class Camper::Client
Wrapper for the Camper
REST API.
Public Class Methods
new(options = {})
click to toggle source
Creates a new Client
instance. @raise [Error:MissingCredentials]
# File lib/camper/client.rb, line 29 def initialize(options = {}) @config = Configuration.new(options) end
Public Instance Methods
configure() { |config| ... }
click to toggle source
Allows setting configuration values for this client by yielding the config object to the block @return [Camper::Client] the client instance being configured
# File lib/camper/client.rb, line 48 def configure yield @config if block_given? self end
inspect()
click to toggle source
Text representation of the client, masking private token.
@return [String]
Calls superclass method
# File lib/camper/client.rb, line 57 def inspect inspected = super inspected.sub! @config.access_token, only_show_last_four_chars(@config.access_token) if @config.access_token inspected end
Private Instance Methods
new_request(method, path, options)
click to toggle source
# File lib/camper/client.rb, line 65 def new_request(method, path, options) Request.new(self, method, path, options) end
only_show_last_four_chars(token)
click to toggle source
# File lib/camper/client.rb, line 89 def only_show_last_four_chars(token) "#{'*' * (token.size - 4)}#{token[-4..-1]}" end
retry_request?(response, result)
click to toggle source
# File lib/camper/client.rb, line 69 def retry_request?(response, result) case result when Request::Result::ACCESS_TOKEN_EXPIRED update_access_token! true when Request::Result::TOO_MANY_REQUESTS sleep_before_retrying(response) true else false end end
sleep_before_retrying(response)
click to toggle source
# File lib/camper/client.rb, line 82 def sleep_before_retrying(response) time = response.headers['Retry-After'].to_i logger.debug("Sleeping for #{time} seconds before retrying request") sleep(time) end