Class: Stretchr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/stretchr/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
	self.transporter = options[:transporter] || Stretchr::JSONTransporter.new
	self.api_version = options[:api_version] || Stretchr.config["api_version"]
	self.project = options[:project]
	self.key = options[:key]
	self.hostname = options[:hostname] || Stretchr.config["hostname"]
	self. = options[: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

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def 
  @account
end

#api_versionObject

Returns the value of attribute api_version.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def api_version
  @api_version
end

#hostnameObject

Returns the value of attribute hostname.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def hostname
  @hostname
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def key
  @key
end

#projectObject

Returns the value of attribute project.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def project
  @project
end

#transporterObject

Returns the value of attribute transporter.



3
4
5
# File 'lib/stretchr/client.rb', line 3

def transporter
  @transporter
end