Class: Wesabe::Request
- Inherits:
-
Object
- Object
- Wesabe::Request
- Defined in:
- lib/wesabe/request.rb
Defined Under Namespace
Classes: Exception, Redirect, RequestFailed, ResourceNotFound, ServerBrokeConnection, Unauthorized
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'User-Agent' => "Wesabe-RubyGem/#{Wesabe::VERSION} (Ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})" }
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.base_url ⇒ Object
Gets the base url for the Wesabe API.
-
.base_url=(base_url) ⇒ Object
Sets the base url for the Wesabe API.
- .ca_file ⇒ Object
-
.execute(options = Hash.new) ⇒ Net::HTTPResponse
Executes a request and returns the response.
Instance Method Summary collapse
-
#execute ⇒ String
Executes the request and returns the response.
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def method @method end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def password @password end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def payload @payload end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def proxy @proxy end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def url @url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
2 3 4 |
# File 'lib/wesabe/request.rb', line 2 def username @username end |
Class Method Details
.base_url ⇒ Object
Gets the base url for the Wesabe API.
135 136 137 |
# File 'lib/wesabe/request.rb', line 135 def self.base_url @base_url ||= "https://www.wesabe.com" end |
.base_url=(base_url) ⇒ Object
Sets the base url for the Wesabe API.
140 141 142 |
# File 'lib/wesabe/request.rb', line 140 def self.base_url=(base_url) @base_url = base_url end |
.ca_file ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/wesabe/request.rb', line 126 def self.ca_file [File.("~/.wesabe"), File.join(File.dirname(__FILE__), '..')].each do |dir| file = File.join(dir, "cacert.pem") return file if File.exist?(file) end raise "Unable to find a CA pem file to use for www.wesabe.com" end |
.execute(options = Hash.new) ⇒ Net::HTTPResponse
Executes a request and returns the response.
122 123 124 |
# File 'lib/wesabe/request.rb', line 122 def self.execute(=Hash.new) new().execute end |
Instance Method Details
#execute ⇒ String
Executes the request and returns the response.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wesabe/request.rb', line 80 def execute # set up the uri @username = uri.user if uri.user @password = uri.password if uri.password # set up the request req = Net::HTTP.const_get(method.to_s.capitalize).new(uri.request_uri, DEFAULT_HEADERS) req.basic_auth(username, password) net.start do |http| process_response http.request(req, payload || "") end end |