Class: TopsConnect::Client
- Inherits:
-
Object
- Object
- TopsConnect::Client
- Includes:
- HTTParty, Communities, Owners, Properties
- Defined in:
- lib/tops_connect/client.rb
Instance Attribute Summary collapse
-
#community_api_key ⇒ Object
readonly
Returns the value of attribute community_api_key.
-
#community_id ⇒ Object
readonly
Returns the value of attribute community_id.
Instance Method Summary collapse
- #get(endpoint, headers: {}, query: {}) ⇒ Object
-
#initialize(community_id, community_api_key) ⇒ Client
constructor
A new instance of Client.
- #post(endpoint, body: {}, headers: {}, query: {}) ⇒ Object
- #put(endpoint, body: {}, headers: {}, query: {}) ⇒ Object
- #switch_community(community_id, community_api_key) ⇒ Object
Methods included from Properties
Methods included from Owners
#balance, #charges, #owner, #owners, #update_owner!
Methods included from Communities
#charge_codes, #communities, #community
Constructor Details
#initialize(community_id, community_api_key) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tops_connect/client.rb', line 20 def initialize(community_id, community_api_key) = Base64.strict_encode64 [ TopsConnect.configuration.client_id, TopsConnect.configuration.software_key ].join(':') self.class.headers('authorization' => "Basic #{}") @subscription_key = TopsConnect.configuration.subscription_key switch_community(community_id, community_api_key) end |
Instance Attribute Details
#community_api_key ⇒ Object (readonly)
Returns the value of attribute community_api_key.
13 14 15 |
# File 'lib/tops_connect/client.rb', line 13 def community_api_key @community_api_key end |
#community_id ⇒ Object (readonly)
Returns the value of attribute community_id.
13 14 15 |
# File 'lib/tops_connect/client.rb', line 13 def community_id @community_id end |
Instance Method Details
#get(endpoint, headers: {}, query: {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tops_connect/client.rb', line 38 def get(endpoint, headers: {}, query: {}) response = self.class.get( "/#{TopsConnect.configuration.zone}/api#{endpoint}", query: query.merge('subscription-key' => @subscription_key), headers: headers.merge('community-api-key' => @community_api_key) ) raise_exception(response) unless response.code == 200 response.parsed_response end |
#post(endpoint, body: {}, headers: {}, query: {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tops_connect/client.rb', line 63 def post(endpoint, body: {}, headers: {}, query: {}) response = self.class.post( "/#{TopsConnect.configuration.zone}/api#{endpoint}", query: query.merge('subscription-key' => @subscription_key), headers: headers.merge('community-api-key' => @community_api_key), body: body.to_json ) raise_exception(response) unless response.code == 200 response.parsed_response end |
#put(endpoint, body: {}, headers: {}, query: {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tops_connect/client.rb', line 50 def put(endpoint, body: {}, headers: {}, query: {}) response = self.class.put( "/#{TopsConnect.configuration.zone}/api#{endpoint}", query: query.merge('subscription-key' => @subscription_key), headers: headers.merge('community-api-key' => @community_api_key), body: body.to_json ) raise_exception(response) unless response.code == 200 response.parsed_response end |
#switch_community(community_id, community_api_key) ⇒ Object
33 34 35 36 |
# File 'lib/tops_connect/client.rb', line 33 def switch_community(community_id, community_api_key) @community_id = community_id @community_api_key = community_api_key end |