Class: HotelsPro::Request
- Inherits:
-
Object
- Object
- HotelsPro::Request
- Defined in:
- lib/hotels_pro/request.rb
Instance Attribute Summary collapse
-
#api_method ⇒ Object
Returns the value of attribute api_method.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(api_method, params = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #query ⇒ Object
- #real_response ⇒ Object
- #stubbed_response ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(api_method, params = {}) ⇒ Request
Returns a new instance of Request.
5 6 7 8 |
# File 'lib/hotels_pro/request.rb', line 5 def initialize(api_method, params={}) @api_method = api_method.camelize(:lower) @params = params end |
Instance Attribute Details
#api_method ⇒ Object
Returns the value of attribute api_method.
3 4 5 |
# File 'lib/hotels_pro/request.rb', line 3 def api_method @api_method end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/hotels_pro/request.rb', line 3 def params @params end |
Instance Method Details
#perform ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/hotels_pro/request.rb', line 22 def perform HotelsPro.log("Request URL: #{uri}") raw_response = stubbed_response || real_response HotelsPro.log("Response: #{raw_response}") Response.new(raw_response) end |
#query ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hotels_pro/request.rb', line 10 def query params = @params.dup params["method"] = api_method params["apiKey"] = HotelsPro.configuration.api_key Query.new(params).to_s end |
#real_response ⇒ Object
39 40 41 |
# File 'lib/hotels_pro/request.rb', line 39 def real_response Typhoeus::Request.get(uri).body end |
#stubbed_response ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hotels_pro/request.rb', line 31 def stubbed_response response = HotelsPro::Stubs.match(self) if !response && HotelsPro.configuration.only_stubs raise HotelsPro::UnstubbedRequest.new("Unstubbed request to URL: #{uri}") end response end |
#uri ⇒ Object
18 19 20 |
# File 'lib/hotels_pro/request.rb', line 18 def uri "#{HotelsPro.configuration.api_url}#{query}" end |