Date
1 - 7 of 7
Trying to figure out an elegant way to handle basicauth
Brian Gupta <brian.gupta@...>
In the main body of my code I parse args and set class variables for username and password, as well as set the basic url via an instance that I pass to rest_client. I got basicauth working by brute force disassembling and reassembling the url. I was hoping there was a more elegant way to do this. Any thoughts?
my_url = "https://host.domain.com/" def get_collection(my_url,path) my_uri = URI.parse(my_url)
my_url2 = my_uri.scheme + "://" + @@my_user + ":" + @@my_pass + "@" + my_uri.host + "/" + path.to_s response = RestClient.get my_url2, { :accept => :json, :content_type => :json }
results = JSON.parse(response.to_str) end Thanks, Brian --
|
|
Archiloque <code@...>
Hi,
toggle quoted messageShow quoted text
not directly with RestClient.get but Request.execute(:method => :get, :url => url, :login => login, :password => password, :headers => { :accept => :json, :content_type => :json }) should do the trick A.
Le 7 oct. 2011 à 08:19, Brian Gupta a écrit : In the main body of my code I parse args and set class variables for username and password, as well as set the basic url via an instance that I pass to rest_client. I got basicauth working by brute force disassembling and reassembling the url. I was hoping there was a more elegant way to do this. Any thoughts?
|
|
Brian Gupta <brian.gupta@...>
Cool and thank you. Is there a more fleshed out example of this somewhere?
toggle quoted messageShow quoted text
Thanks, Brian
On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
![]()
|
|
Archiloque <code@...>
I don't think, do you have any question about the API ? A.
Cool and thank you. Is there a more fleshed out example of this somewhere?
|
|
Brian Gupta <brian.gupta@...>
(In way of background, I am learning ruby for this project). I guess the issue is I don't understand what "Request.execute" is, or how to actually call it? I tried plugging it in as replacement for RestClient.get but didn't work (error follows below the example). IE:
toggle quoted messageShow quoted text
def get_collection(path) response = Request.execute(:method => :get, :url => @my_url, :login => @my_user, :password => @my_pass, :headers => { :accept => :json, :content_type => :json })
results = JSON.parse(response.to_str) end in `get_collection': uninitialized constant Request (NameError) That still leaves the path (including query string) as unhandled, but I figure one step at a time. Thanks, Brian
On Sat, Oct 8, 2011 at 12:40 PM, Archiloque <code@...> wrote:
|
|
Archiloque <code@...>
sorry:
toggle quoted messageShow quoted text
try RestClient::Request.new(......).execute I'm on ruby's IRC if you have other questions A.
Le 8 oct. 2011 à 19:02, Brian Gupta a écrit : (In way of background, I am learning ruby for this project). I guess the issue is I don't understand what "Request.execute" is, or how to actually call it? I tried plugging it in as replacement for RestClient.get but didn't work (error follows below the example). IE:
|
|
Brian Gupta <brian.gupta@...>
In case anyone wants to know how this turned out, thanks to Archiloque's help, I got it working with:
toggle quoted messageShow quoted text
def get_collection(path) #RestClient.log = 'stdout' response = RestClient::Request.new(:method => :get, :url => @my_url + "/" + path.to_s, :user => @my_user, :password => @my_pass, :headers => { :accept => :json, :content_type => :json }).execute
results = JSON.parse(response.to_str) end -Brian
On Sat, Oct 8, 2011 at 1:06 PM, Archiloque <code@...> wrote:
![]()
|
|