Class: HaveAPI::Client::Client
- Inherits:
-
Object
- Object
- HaveAPI::Client::Client
- Defined in:
- lib/haveapi/client/client.rb
Overview
HaveAPI client interface.
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#auth ⇒ HaveAPI::Client::Authentication::Base?
Get uthentication provider.
-
#authenticate(*args) ⇒ Object
See Communicator#authenticate.
- #compatible? ⇒ Boolean
-
#initialize(url, v = nil, identity: 'haveapi-client', communicator: nil) ⇒ Client
constructor
Create an instance of client.
-
#method_missing(symbol, *args) ⇒ Object
Initialize the client if it is not yet initialized and call the resource if it exists.
-
#setup(v = :_nil) ⇒ Object
Get the description from the API now.
-
#versions ⇒ Object
Returns a list of API versions.
Constructor Details
#initialize(url, v = nil, identity: 'haveapi-client', communicator: nil) ⇒ Client
Create an instance of client. The client by default uses the default version of the API. API is asked for description only when needed or by calling #setup. identity is sent in each request to the API in User-Agent header.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/haveapi/client/client.rb', line 11 def initialize(url, v = nil, identity: 'haveapi-client', communicator: nil) @setup = false @version = v if communicator @api = communicator else @api = HaveAPI::Client::Communicator.new(url, v) @api.identity = identity end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
Initialize the client if it is not yet initialized and call the resource if it exists.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/haveapi/client/client.rb', line 59 def method_missing(symbol, *args) return super(symbol, *args) if @setup setup_api if @resources.include?(symbol) method(symbol).call(*args) else super(symbol, *args) end end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
5 6 7 |
# File 'lib/haveapi/client/client.rb', line 5 def resources @resources end |
Instance Method Details
#auth ⇒ HaveAPI::Client::Authentication::Base?
Get uthentication provider
48 49 50 |
# File 'lib/haveapi/client/client.rb', line 48 def auth @api.auth end |
#authenticate(*args) ⇒ Object
See Communicator#authenticate.
41 42 43 |
# File 'lib/haveapi/client/client.rb', line 41 def authenticate(*args) @api.authenticate(*args) end |
#compatible? ⇒ Boolean
53 54 55 |
# File 'lib/haveapi/client/client.rb', line 53 def compatible? @api.compatible? end |
#setup(v = :_nil) ⇒ Object
Get the description from the API now.
25 26 27 28 |
# File 'lib/haveapi/client/client.rb', line 25 def setup(v = :_nil) @version = v unless v == :_nil setup_api end |
#versions ⇒ Object
Returns a list of API versions. The return value is a hash, e.g.:
{
versions: [1, 2, 3],
default: 3
}
36 37 38 |
# File 'lib/haveapi/client/client.rb', line 36 def versions @api.available_versions end |