Class: HomeAway::API::Client
- Inherits:
-
Object
- Object
- HomeAway::API::Client
- Includes:
- Domain::AddMessage, Domain::Conversation, Domain::Listing, Domain::ListingReview, Domain::ListingReviews, Domain::Me, Domain::MyInbox, Domain::MyListings, Domain::MyReservations, Domain::Quote, Domain::Search, Domain::SubmitReview, Util::OAuth
- Defined in:
- lib/homeaway/api/client.rb,
lib/homeaway/api/domain/client_includes.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Hash
The current client configuration.
-
#mode ⇒ Symbol
readonly
The current authentication state of this client.
-
#refresh_token ⇒ String
readonly
The current refresh token.
-
#token ⇒ String
readonly
The current bearer auth token.
-
#token_expires ⇒ Time
readonly
The time that the current token in use on this client will expire.
Class Method Summary collapse
-
.configure {|@@default_configuration| ... } ⇒ Hash
Pass a block expecting a single hash parameter and set any global configuration settings that will be inherited by all instances created in the future.
-
.default_configuration ⇒ Hash
The global default configuration.
Instance Method Summary collapse
-
#configure {|@configuration| ... } ⇒ Hash
Update the configuration of this particular instance of the client.
- #delete(url, params = {}) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ HomeAway::API::Client
constructor
Instantiates a new HomeAway API client.
-
#logger ⇒ Object
The current logger that has been configured.
- #marshal_dump ⇒ Object
- #marshal_load(array) ⇒ Object
- #options(url, params = {}) ⇒ Object
- #post(url, body, params = {}) ⇒ Object
- #put(url, body, params = {}) ⇒ Object
-
#token_expired? ⇒ Boolean
Has the token that the client is currently using expired?.
Methods included from Domain::Conversation
Methods included from Domain::AddMessage
Methods included from Domain::MyReservations
Methods included from Domain::Me
Methods included from Domain::SubmitReview
Methods included from Domain::MyInbox
Methods included from Domain::MyListings
Methods included from Domain::Quote
Methods included from Domain::Search
Methods included from Domain::ListingReview
Methods included from Domain::ListingReviews
Methods included from Domain::Listing
Methods included from Util::OAuth
#auth_url, #credentials, #oauth_code=, #state
Constructor Details
#initialize(opts = {}) ⇒ HomeAway::API::Client
Instantiates a new HomeAway API client
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/homeaway/api/client.rb', line 58 def initialize(opts={}) @configuration = Hashie::Mash.new(self.class.default_configuration.merge(opts)) if opts.has_key?(:refresh_token) @configuration[:manual_token_supplied] = true @refresh_token = opts.delete(:refresh_token) refresh end validate_configuration logger.debug("client initialized with configuration: #{@configuration}") attempt_auth if @token.nil? end |
Instance Attribute Details
#configuration ⇒ Hash
Returns the current client configuration.
38 39 40 |
# File 'lib/homeaway/api/client.rb', line 38 def configuration @configuration end |
#mode ⇒ Symbol (readonly)
Returns the current authentication state of this client. One of either :unauthorized, :two_legged, or :three_legged.
44 45 46 |
# File 'lib/homeaway/api/client.rb', line 44 def mode @mode end |
#refresh_token ⇒ String (readonly)
Returns The current refresh token.
91 92 93 |
# File 'lib/homeaway/api/client.rb', line 91 def refresh_token @refresh_token end |
#token ⇒ String (readonly)
Returns The current bearer auth token.
41 42 43 |
# File 'lib/homeaway/api/client.rb', line 41 def token @token end |
#token_expires ⇒ Time (readonly)
Returns the time that the current token in use on this client will expire.
47 48 49 |
# File 'lib/homeaway/api/client.rb', line 47 def token_expires @token_expires end |
Class Method Details
.configure {|@@default_configuration| ... } ⇒ Hash
Pass a block expecting a single hash parameter and set any global configuration settings that will be inherited by all instances created in the future
28 29 30 31 |
# File 'lib/homeaway/api/client.rb', line 28 def self.configure yield @@default_configuration if block_given? @@default_configuration end |
Instance Method Details
#configure {|@configuration| ... } ⇒ Hash
Update the configuration of this particular instance of the client. Pass a block expecting a single hash parameter to update the configuration settings.
73 74 75 76 77 |
# File 'lib/homeaway/api/client.rb', line 73 def configure yield @configuration if block_given? validate_configuration @configuration end |
#delete(url, params = {}) ⇒ Object
138 139 140 |
# File 'lib/homeaway/api/client.rb', line 138 def delete(url, params={}) method :delete, url, {}, params end |
#get(url, params = {}) ⇒ Object
123 124 125 |
# File 'lib/homeaway/api/client.rb', line 123 def get(url, params={}) method :get, url, {}, params end |
#logger ⇒ Object
Returns The current logger that has been configured.
80 81 82 |
# File 'lib/homeaway/api/client.rb', line 80 def logger @configuration.logger end |
#marshal_dump ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/homeaway/api/client.rb', line 96 def marshal_dump # we lose our logger instance naively here, marshal dump doesn't like # one of its fields dump_config = configuration.dup.to_hash dump_config.delete('logger') [@token, token_expires, dump_config] end |
#marshal_load(array) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/homeaway/api/client.rb', line 105 def marshal_load(array) @token = array[0] @token_expires = array[1] @configuration = Hashie::Mash.new(array[2]) @configuration.logger = HomeAway::API::Util::Defaults.instance.logger end |
#options(url, params = {}) ⇒ Object
143 144 145 |
# File 'lib/homeaway/api/client.rb', line 143 def (url, params={}) method :options, url, {}, params end |
#post(url, body, params = {}) ⇒ Object
133 134 135 |
# File 'lib/homeaway/api/client.rb', line 133 def post(url, body, params={}) method :post, url, body, params end |
#put(url, body, params = {}) ⇒ Object
128 129 130 |
# File 'lib/homeaway/api/client.rb', line 128 def put(url, body, params={}) method :put, url, body, params end |
#token_expired? ⇒ Boolean
Returns Has the token that the client is currently using expired?.
113 114 115 116 117 118 119 120 |
# File 'lib/homeaway/api/client.rb', line 113 def token_expired? return false if @configuration[:manual_token_supplied] begin Time.now >= token_expires rescue true end end |