Class: BooticClient::Client
- Inherits:
-
Object
- Object
- BooticClient::Client
- Defined in:
- lib/bootic_client/client.rb
Constant Summary collapse
- USER_AGENT =
"[BooticClient v#{VERSION}] Ruby-#{RUBY_VERSION} - #{RUBY_PLATFORM}".freeze
Instance Attribute Summary collapse
-
#api_root ⇒ Object
readonly
Returns the value of attribute api_root.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #get(href, query = {}) ⇒ Object
- #get_and_wrap(href, wrapper_class, query = {}) ⇒ Object
-
#initialize(api_root, options = {}, &block) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_root, options = {}, &block) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bootic_client/client.rb', line 15 def initialize(api_root, = {}, &block) @api_root = api_root @options = { access_token: nil, logging: false }.merge(.dup) @options[:cache_store] = @options[:cache_store] || Faraday::HttpCache::MemoryStore.new conn &block if block_given? end |
Instance Attribute Details
#api_root ⇒ Object (readonly)
Returns the value of attribute api_root.
13 14 15 |
# File 'lib/bootic_client/client.rb', line 13 def api_root @api_root end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/bootic_client/client.rb', line 13 def @options end |
Instance Method Details
#get(href, query = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bootic_client/client.rb', line 31 def get(href, query = {}) validate_request! resp = conn.get do |req| req.url href req.params.update(query) req.headers['Authorization'] = "Bearer #{[:access_token]}" req.headers['User-Agent'] = USER_AGENT end raise_if_invalid! resp resp end |
#get_and_wrap(href, wrapper_class, query = {}) ⇒ Object
27 28 29 |
# File 'lib/bootic_client/client.rb', line 27 def get_and_wrap(href, wrapper_class, query = {}) wrapper_class.new get(href, query).body, self end |