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,

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?

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
-- 




Brian Gupta <brian.gupta@...>
 

Cool and thank you. Is there a more fleshed out example of this somewhere?

Thanks,
Brian


On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
Hi,

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?

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@...>
 


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?

Thanks,
Brian

On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
Hi,

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?

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
-- 






--




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:

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

error:

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:

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?

Thanks,
Brian

On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
Hi,

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?

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@...>
 

sorry:

 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:

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

error:

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:

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?

Thanks,
Brian

On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
Hi,

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?

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
-- 






--






--




Brian Gupta <brian.gupta@...>
 

In case anyone wants to know how this turned out, thanks to Archiloque's help, I got it working with:

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:
sorry:

 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:

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

error:

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:

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?

Thanks,
Brian

On Sat, Oct 8, 2011 at 5:02 AM, Archiloque <code@...> wrote:
Hi,

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?

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
-- 






--






--






--