Class: ServiceApi
- Inherits:
-
Object
- Object
- ServiceApi
- Includes:
- Validation
- Defined in:
- lib/tacklebox/apis/service_api.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
Instance Method Summary collapse
- #create_service(service_data) ⇒ Object
- #delete_service(service_id) ⇒ Object
- #get_service(service_id) ⇒ Object
-
#initialize(config) ⇒ ServiceApi
constructor
A new instance of ServiceApi.
- #list_services ⇒ Object
Methods included from Validation
#is_valid_data, #is_valid_event_data, #is_valid_id, #is_valid_name, #is_valid_subscription_data
Constructor Details
#initialize(config) ⇒ ServiceApi
Returns a new instance of ServiceApi.
10 11 12 13 |
# File 'lib/tacklebox/apis/service_api.rb', line 10 def initialize(config) self.base_url = config[:base_url] self.http_client = HttpClient.new(config[:api_key]) end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/tacklebox/apis/service_api.rb', line 8 def base_url @base_url end |
#http_client ⇒ Object
Returns the value of attribute http_client.
8 9 10 |
# File 'lib/tacklebox/apis/service_api.rb', line 8 def http_client @http_client end |
Instance Method Details
#create_service(service_data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tacklebox/apis/service_api.rb', line 21 def create_service(service_data) if !self.is_valid_data(service_data) return new_error( ERROR_TYPES['missing_parameter'], "The create_service method must be invoked with a non-empty string name argument." ) end path = "services" request = HttpRequest.new("POST", @base_url, path, service_data) self.http_client.send(request) end |
#delete_service(service_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tacklebox/apis/service_api.rb', line 34 def delete_service(service_id) if !self.is_valid_id(service_id) return new_error( ERROR_TYPES['missing_parameter'], "The get_service method must be invoked with a non-empty string service_id argument." ) end path = "services/#{service_id}" request = HttpRequest.new("DELETE", @base_url, path) self.http_client.send(request) end |
#get_service(service_id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tacklebox/apis/service_api.rb', line 47 def get_service(service_id) if !self.is_valid_id(service_id) return new_error( ERROR_TYPES['missing_parameter'], "The get_service method must be invoked with a non-empty string service_id argument." ) end path = "services/#{service_id}" request = HttpRequest.new("GET", @base_url, path) self.http_client.send(request) end |
#list_services ⇒ Object
15 16 17 18 19 |
# File 'lib/tacklebox/apis/service_api.rb', line 15 def list_services path = "services" request = HttpRequest.new("GET", @base_url, path) self.http_client.send(request) end |