Class: MyVR::Client
- Inherits:
-
Object
- Object
- MyVR::Client
- Includes:
- API::Amenities, API::Fees, API::Photos, API::Properties, API::Rates, API::Rooms
- Defined in:
- lib/myvr/client.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#last_response ⇒ Object
Returns the value of attribute last_response.
Instance Method Summary collapse
- #base_url(path, params = {}) ⇒ Object
- #get_object(path, params = {}) ⇒ Object
- #get_objects(path, params = {}) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #request(http_method, path, params = {}) ⇒ Object
- #user_agent ⇒ Object
Methods included from API::Rooms
Methods included from API::Rates
Methods included from API::Properties
#properties, #properties!, #property
Methods included from API::Photos
Methods included from API::Fees
Methods included from API::Amenities
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 |
# File 'lib/myvr/client.rb', line 14 def initialize( = {}) @last_response = nil .each do |key, value| instance_variable_set("@#{ key }", value) end yield(self) if block_given? end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
12 13 14 |
# File 'lib/myvr/client.rb', line 12 def access_key @access_key end |
#last_response ⇒ Object
Returns the value of attribute last_response.
12 13 14 |
# File 'lib/myvr/client.rb', line 12 def last_response @last_response end |
Instance Method Details
#base_url(path, params = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/myvr/client.rb', line 48 def base_url(path, params={}) if ENV["MYVR_TEST"] Addressable::URI.new( host: 'api.local.myvr.com', port: 8000, scheme: 'http', path: path, query_values: params ) else Addressable::URI.new( host: 'api.myvr.com', port: 80, scheme: 'https', path: path, query_values: params ) end end |
#get_object(path, params = {}) ⇒ Object
31 32 33 |
# File 'lib/myvr/client.rb', line 31 def get_object(path, params={}) request(:get, path, params.dup) end |
#get_objects(path, params = {}) ⇒ Object
26 27 28 29 |
# File 'lib/myvr/client.rb', line 26 def get_objects(path, params={}) response = request(:get, path, params.dup) response['results'] end |
#request(http_method, path, params = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/myvr/client.rb', line 35 def request(http_method, path, params={}) url = base_url(path, params.dup) c = Curl::Easy.new(url) c.http_auth_types = :basic c.username = access_key c.send(http_method) if ENV["MYVR_TEST"] p JSON.parse(c.body_str) else JSON.parse(c.body_str) end end |