Class: DeskApi::Client
- Inherits:
-
Object
- Object
- DeskApi::Client
- Includes:
- Configuration
- Defined in:
- lib/desk_api/client.rb
Overview
The Client builds and performs the http request using Faraday and the configured adapter. It includes and has full access to the configuration module.
Instance Attribute Summary
Attributes included from Configuration
#connection_options, #consumer_key, #consumer_secret, #endpoint, #middleware, #password, #subdomain, #token, #token_secret, #username
Instance Method Summary collapse
-
#by_url(path) ⇒ DeskApi::Resource
Returns a new resource for the given path.
-
#initialize(options = {}) ⇒ DeskApi::Client
constructor
Initializes a new client object.
-
#method {|Faraday::Response| ... } ⇒ Faraday::Response
Perform an http request.
Methods included from Configuration
#configure, #credentials?, included, keys, register_middleware, #reset!
Constructor Details
#initialize(options = {}) ⇒ DeskApi::Client
Initializes a new client object
48 49 50 51 52 53 |
# File 'lib/desk_api/client.rb', line 48 def initialize( = {}) DeskApi::Configuration.keys.each do |key| value = [key] || DeskApi.instance_variable_get(:"@#{key}") instance_variable_set(:"@#{key}", value) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, params = {}) {|DeskApi::Resource| ... } ⇒ DeskApi::Resource (private)
Returns a new resource based on the method you're trying to load:
87 88 89 90 91 92 93 |
# File 'lib/desk_api/client.rb', line 87 def method_missing(method, params = {}) definition = DeskApi::Resource.build_self_link("/api/v2/#{method}") DeskApi::Resource.new(self, definition).tap do |res| res.query_params = params yield res if block_given? end end |
Instance Method Details
#by_url(path) ⇒ DeskApi::Resource
Returns a new resource for the given path
73 74 75 |
# File 'lib/desk_api/client.rb', line 73 def by_url(path) DeskApi::Resource.new(self, DeskApi::Resource.build_self_link(path)) end |
#method {|Faraday::Response| ... } ⇒ Faraday::Response
Perform an http request
61 62 63 64 65 66 67 |
# File 'lib/desk_api/client.rb', line 61 %w(get head delete post patch).each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(path, params = {}, &block) request(:#{method}, path, params, &block) end RUBY end |