Class: Maestrano::Connec::Client
- Inherits:
-
Object
- Object
- Maestrano::Connec::Client
- Includes:
- HTTParty, Preset
- Defined in:
- lib/maestrano/connec/client.rb
Instance Attribute Summary collapse
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
Instance Method Summary collapse
- #batch(body, options = {}) ⇒ Object
-
#default_options ⇒ Object
Return the default options which includes maestrano authentication.
-
#get(relative_path, options = {}) ⇒ Object
E.g: client.get(‘/organizations’) E.g: client.get(‘/organizations/123’).
-
#initialize(group_id) ⇒ Client
constructor
A new instance of Client.
-
#post(relative_path, body, options = {}) ⇒ Object
E.g: client.post(‘/organizations’, { organizations: { name: ‘DoeCorp Inc.’ } }).
-
#put(relative_path, body, options = {}) ⇒ Object
E.g for collection: => client.put(‘/organizations/123’, { organizations: { name: ‘DoeCorp Inc.’ } }) E.g for singular resource: => client.put(‘/company’, { company: { name: ‘DoeCorp Inc.’ } }).
-
#scoped_path(relative_path) ⇒ Object
Return the right path scoped using the customer group id.
Methods included from Preset
Constructor Details
#initialize(group_id) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/maestrano/connec/client.rb', line 14 def initialize(group_id) @group_id = group_id self.class.base_uri("#{Maestrano[self.class.preset].param('connec.host')}#{Maestrano[self.class.preset].param('connec.base_path')}") end |
Instance Attribute Details
#group_id ⇒ Object (readonly)
Returns the value of attribute group_id.
12 13 14 |
# File 'lib/maestrano/connec/client.rb', line 12 def group_id @group_id end |
Instance Method Details
#batch(body, options = {}) ⇒ Object
61 62 63 |
# File 'lib/maestrano/connec/client.rb', line 61 def batch(body, = {}) self.class.post("#{Maestrano[self.class.preset].param('connec.host')}/batch", .merge(body: body.to_json).merge()) end |
#default_options ⇒ Object
Return the default options which includes maestrano authentication
21 22 23 24 25 26 27 28 29 |
# File 'lib/maestrano/connec/client.rb', line 21 def { basic_auth: { username: Maestrano[self.class.preset].param('api.id'), password: Maestrano[self.class.preset].param('api.key') }, timeout: Maestrano[self.class.preset].param('connec.timeout') } end |
#get(relative_path, options = {}) ⇒ Object
E.g: client.get(‘/organizations’) E.g: client.get(‘/organizations/123’)
40 41 42 |
# File 'lib/maestrano/connec/client.rb', line 40 def get(relative_path, = {}) self.class.get(self.scoped_path(relative_path),.merge()) end |
#post(relative_path, body, options = {}) ⇒ Object
E.g: client.post(‘/organizations’, { organizations: { name: ‘DoeCorp Inc.’ } })
45 46 47 48 49 |
# File 'lib/maestrano/connec/client.rb', line 45 def post(relative_path, body, = {}) self.class.post(self.scoped_path(relative_path), .merge(body: body.to_json).merge() ) end |
#put(relative_path, body, options = {}) ⇒ Object
E.g for collection:
> client.put(‘/organizations/123’, { organizations: { name: ‘DoeCorp Inc.’ } })
E.g for singular resource:
> client.put(‘/company’, { company: { name: ‘DoeCorp Inc.’ } })
55 56 57 58 59 |
# File 'lib/maestrano/connec/client.rb', line 55 def put(relative_path, body, = {}) self.class.put(self.scoped_path(relative_path), .merge(body: body.to_json).merge() ) end |
#scoped_path(relative_path) ⇒ Object
Return the right path scoped using the customer group id
33 34 35 36 |
# File 'lib/maestrano/connec/client.rb', line 33 def scoped_path(relative_path) clean_path = relative_path.gsub(/^\/+/, "").gsub(/\/+$/, "") "/#{@group_id}/#{clean_path}" end |