Class: EventApi
- Inherits:
-
Object
- Object
- EventApi
- Includes:
- Validation
- Defined in:
- lib/tacklebox/apis/event_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_event(service_id, user_id, event_data) ⇒ Object
- #get_event(service_id, user_id, event_id) ⇒ Object
-
#initialize(config) ⇒ EventApi
constructor
A new instance of EventApi.
- #list_events(service_id, user_id) ⇒ 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) ⇒ EventApi
Returns a new instance of EventApi.
10 11 12 13 |
# File 'lib/tacklebox/apis/event_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/event_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/event_api.rb', line 8 def http_client @http_client end |
Instance Method Details
#create_event(service_id, user_id, event_data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tacklebox/apis/event_api.rb', line 35 def create_event(service_id, user_id, event_data) if !self.is_valid_id(service_id) return new_error( ERROR_TYPES['missing_parameter'], "The create_event method must be invoked with a non-empty string service_id argument." ) end if !self.is_valid_id(user_id) return new_error( ERROR_TYPES['missing_parameter'], "The create_event method must be invoked with a non-empty string user_id argument." ) end if !self.is_valid_event_data(event_data) return new_error( ERROR_TYPES['missing_parameter'], "The create_event method must be invoked with an event_data argument containing non-empty event_type and payload properties." ) end path = "services/#{service_id}/users/#{user_id}/events" request = HttpRequest.new("POST", @base_url, path, event_data) @http_client.send(request) end |
#get_event(service_id, user_id, event_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tacklebox/apis/event_api.rb', line 62 def get_event(service_id, user_id, event_id) if !self.is_valid_id(service_id) return new_error( ERROR_TYPES['missing_parameter'], "The get_event method must be invoked with a non-empty string service_id argument." ) end if !self.is_valid_id(user_id) return new_error( ERROR_TYPES['missing_parameter'], "The get_event method must be invoked with a non-empty string user_id argument." ) end if !self.is_valid_id(event_id) return new_error( ERROR_TYPES['missing_parameter'], "The get_event method must be invoked with a non-empty string event_id argument." ) end path = "services/#{service_id}/users/#{user_id}/events/#{event_id}" request = HttpRequest.new("GET", @base_url, path) @http_client.send(request) end |
#list_events(service_id, user_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tacklebox/apis/event_api.rb', line 15 def list_events(service_id, user_id) if !self.is_valid_id(service_id) return new_error( ERROR_TYPES['missing_parameter'], "The list_events method must be invoked with a non-empty string service_id argument." ) end if !self.is_valid_id(user_id) return new_error( ERROR_TYPES['missing_parameter'], "The list_events method must be invoked with a non-empty string user_id argument." ) end path = "services/#{service_id}/users/#{user_id}/events" request = HttpRequest.new("GET", @base_url, path) @http_client.send(request) end |