Class: CobotClient::ApiClient
- Inherits:
-
Object
- Object
- CobotClient::ApiClient
- Includes:
- UrlHelper
- Defined in:
- lib/cobot_client/api_client.rb
Instance Method Summary collapse
- #auth_headers ⇒ Object
- #create_booking(subdomain, resource_id, attributes) ⇒ Object
- #delete(subdomain, path) ⇒ Object
- #delete_booking(subdomain, id) ⇒ Object
- #get(subdomain, path, params = {}) ⇒ Object
- #get_resources(subdomain) ⇒ Object
-
#initialize(access_token) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #post(subdomain, path, params) ⇒ Object
- #put(subdomain, path, params) ⇒ Object
- #update_booking(subdomain, id, attributes) ⇒ Object
Methods included from UrlHelper
Constructor Details
#initialize(access_token) ⇒ ApiClient
Returns a new instance of ApiClient.
8 9 10 |
# File 'lib/cobot_client/api_client.rb', line 8 def initialize(access_token) @access_token = access_token end |
Instance Method Details
#auth_headers ⇒ Object
49 50 51 |
# File 'lib/cobot_client/api_client.rb', line 49 def auth_headers {'Authorization' => "Bearer #{@access_token}"} end |
#create_booking(subdomain, resource_id, attributes) ⇒ Object
16 17 18 |
# File 'lib/cobot_client/api_client.rb', line 16 def create_booking(subdomain, resource_id, attributes) post subdomain, "/resources/#{resource_id}/bookings", attributes end |
#delete(subdomain, path) ⇒ Object
33 34 35 |
# File 'lib/cobot_client/api_client.rb', line 33 def delete(subdomain, path) RestClient.delete(cobot_url(subdomain, "/api#{path}"), auth_headers) end |
#delete_booking(subdomain, id) ⇒ Object
24 25 26 |
# File 'lib/cobot_client/api_client.rb', line 24 def delete_booking(subdomain, id) delete subdomain, "/bookings/#{id}" end |
#get(subdomain, path, params = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/cobot_client/api_client.rb', line 42 def get(subdomain, path, params = {}) JSON.parse( RestClient.get(cobot_url(subdomain, "/api#{path}", params: params), auth_headers).body, symbolize_names: true ) end |
#get_resources(subdomain) ⇒ Object
12 13 14 |
# File 'lib/cobot_client/api_client.rb', line 12 def get_resources(subdomain) get subdomain, '/resources' end |
#post(subdomain, path, params) ⇒ Object
37 38 39 40 |
# File 'lib/cobot_client/api_client.rb', line 37 def post(subdomain, path, params) JSON.parse RestClient.post(cobot_url(subdomain, "/api#{path}"), params, auth_headers).body, symbolize_names: true end |
#put(subdomain, path, params) ⇒ Object
28 29 30 31 |
# File 'lib/cobot_client/api_client.rb', line 28 def put(subdomain, path, params) JSON.parse RestClient.put(cobot_url(subdomain, "/api#{path}"), params, auth_headers).body, symbolize_names: true end |
#update_booking(subdomain, id, attributes) ⇒ Object
20 21 22 |
# File 'lib/cobot_client/api_client.rb', line 20 def update_booking(subdomain, id, attributes) put subdomain, "/bookings/#{id}", attributes end |