Class: Stretchr::Client
- Inherits:
-
Object
- Object
- Stretchr::Client
- Defined in:
- lib/stretchr/client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#key ⇒ Object
Returns the value of attribute key.
-
#project ⇒ Object
Returns the value of attribute project.
-
#transporter ⇒ Object
Returns the value of attribute transporter.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Initializes a new stretchr client This is the main entrypoint into working with stretchr.
-
#method_missing(method, *args) ⇒ Object
Catches everything you can throw at client and passes it on to a new request object All interactions will then take place on the request object itself This is the primary function of the Client class, to get you into a unique request as quickly as possible.
Constructor Details
#initialize(options = {}) ⇒ Client
Initializes a new stretchr client This is the main entrypoint into working with stretchr
Parameters
options[:project]
- The project you’re working with options[:key]
- The key for the project you want to use options[:transporter]
- The transporter to use for actually making requests options[:api_version]
- The stretchr API endpoint we want to communicate with
12 13 14 15 16 17 18 19 |
# File 'lib/stretchr/client.rb', line 12 def initialize( = {}) self.transporter = [:transporter] || Stretchr::JSONTransporter.new self.api_version = [:api_version] || Stretchr.config["api_version"] self.project = [:project] self.key = [:key] self.hostname = [:hostname] || Stretchr.config["hostname"] self.account = [:account] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Catches everything you can throw at client and passes it on to a new request object All interactions will then take place on the request object itself This is the primary function of the Client class, to get you into a unique request as quickly as possible
Example
stretchr = Stretchr::Client.new(“project”, key: “key”) stretchr.people(1).cars.path # => people/1/cars
29 30 31 32 33 |
# File 'lib/stretchr/client.rb', line 29 def method_missing(method, *args) r = Stretchr::Request.new({client: self}) r.param("key", key) if key r.send(method, *args) end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def account @account end |
#api_version ⇒ Object
Returns the value of attribute api_version.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def api_version @api_version end |
#hostname ⇒ Object
Returns the value of attribute hostname.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def hostname @hostname end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def key @key end |
#project ⇒ Object
Returns the value of attribute project.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def project @project end |
#transporter ⇒ Object
Returns the value of attribute transporter.
3 4 5 |
# File 'lib/stretchr/client.rb', line 3 def transporter @transporter end |