callrail 0.2.7 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/callrail.rb CHANGED
@@ -1,265 +1,266 @@
1
- require 'bundler/setup'
2
- require "callrail/version"
3
- require 'json'
4
- require 'ostruct'
5
- require 'rest-client'
6
-
7
- module Callrail
8
- class Api
9
-
10
- MAX_PAGE_SIZE = '250'
11
-
12
- def initialize(opts = {})
13
- @url = 'https://api.callrail.com/v2/a'
14
- @auth = "Token token=" + opts[:key]
15
- @account_id = opts[:account_id].to_s if opts[:account_id]
16
- end
17
-
18
- def set_account_id(opts = {})
19
- @account_id = opts[:account_id].to_s
20
- end
21
-
22
- def parse_json(response)
23
- body = JSON.parse(response.to_str) if response.code == 200 || response.code == 201
24
- OpenStruct.new(code: response.code, body: body)
25
- end
26
-
27
- def set_params(opts = {})
28
- params = {}
29
- #Result params
30
- params[:date_range] = opts[:date_range] if opts[:date_range]
31
- # Values: recent, today, yesterday, last_7_days, last_30_days, this_month, last_month, all_time
32
- params[:start_date] = opts[:start_date] if opts[:start_date]
33
- # ex: “2015-09-05” for all calls after and including September 9, 2015 - “2015-09-05T10:00” for all calls after 10 AM September 5, 2015
34
- params[:end_date] = opts[:end_date] if opts[:end_date]
35
- # ex: “2015-10-05” for all calls before and including October 9, 2015 - “2015-09-05T10:00” for all calls before 10 AM September 5, 2015
36
- params[:sort] = opts[:sort] if opts[:sort]
37
- # ex: /users.json?sort=email Will return a list of user objects for the target account, sorted by email address in alphabetical order.
38
- params[:search] = opts[:search] if opts[:search]
39
- # ex: users.json?search=belcher Will return a list of user objects in the target account that match the name given.
40
- params[:fields] = opts[:fields] if opts[:fields]
41
- # ex: calls/444941612.json?fields=company_id,company_name Will return the additional user requested fields for the target call.
42
- params[:page] = opts[:page] || 1
43
- params[:per_page] = opts[:per_page] || MAX_PAGE_SIZE
44
- params[:path] = opts[:path] if opts[:path]
45
- #Filters
46
- if opts[:filtering]
47
- opts[:filtering].each do |filter|
48
- params[filter[:field].to_sym] = filter[:value]
49
- end
50
- end
51
- #Shared Params
52
- params[:name] = opts[:name] if opts[:name]
53
- #Account Params
54
- # Sorting: id, name
55
- #Company Params
56
- # Sorting: id, name
57
- # Filtering: status
58
- # Searching: name
59
- params[:callscore_enabled] = opts[:callscore_enabled] if opts[:callscore_enabled]
60
- params[:keyword_spotting_enabled] = opts[:keyword_spotting_enabled] if opts[:keyword_spotting_enabled]
61
- params[:callscribe_enabled] = opts[:callscribe_enabled] if opts[:callscribe_enabled]
62
- params[:time_zone] = opts[:time_zone] if opts[:time_zone]
63
- # USA Values: America/New_York (Eastern Time Zone), America/Indiana/Indianapolis (Indiana Time Zone), America/Chicago (Central Time Zone),
64
- # America/Denver (Mountain Time Zone), America/Phoenix (Arizona Time Zone), America/Los_Angeles (Pacific Time Zone)
65
- # Full List: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
66
- params[:swap_exclude_jquery] = opts[:swap_exclude_jquery] if opts[:swap_exclude_jquery]
67
- params[:swap_ppc_override] = opts[:swap_ppc_override] if opts[:swap_ppc_override]
68
- params[:swap_landing_override] = opts[:swap_landing_override] if opts[:swap_landing_override]
69
- params[:swap_cookie_duration] = opts[:swap_cookie_duration] if opts[:swap_cookie_duration]
70
- #User Params
71
- # Sorting: id, email, created_at
72
- # Searching: first_name, last_name, email
73
- params[:first_name] = opts[:first_name] if opts[:first_name]
74
- params[:last_name] = opts[:last_name] if opts[:last_name]
75
- params[:email] = opts[:email] if opts[:email]
76
- params[:role] = opts[:role] if opts[:role]
77
- params[:password] = opts[:password] if opts[:password]
78
- params[:companies] = opts[:companies] if opts[:companies]
79
- params[:company_ids] = opts[:company_ids] if opts[:company_ids] #Callrail disabled
80
- #Tracker Params
81
- # Filtering: type, status
82
- params[:type] = opts[:type] if opts[:type]
83
- params[:company_id] = opts[:company_id] if opts[:company_id]
84
- params[:call_flow] = opts[:call_flow] if opts[:call_flow]
85
- params[:pool_size] = opts[:pool_size] if opts[:pool_size]
86
- params[:pool_numbers] = opts[:pool_numbers] if opts[:pool_numbers]
87
- params[:source] = opts[:source] if opts[:source]
88
- params[:swap_targets] = opts[:swap_targets] if opts[:swap_targets]
89
- params[:whisper_message] = opts[:whisper_message] if opts[:whisper_message]
90
- params[:sms_enabled] = opts[:sms_enabled] if opts[:sms_enabled]
91
- params[:tracking_number] = opts[:tracking_number] if opts[:tracking_number]
92
- #Integration Params
93
- params[:config] = opts[:config] if opts[:config]
94
- params[:state] = opts[:state] if opts[:state]
95
- #Call Params
96
- # Sorting: customer_name, customer_phone_number, duration, start_time, source
97
- # Filtering: date_range, answer_status, device, direction, lead_status
98
- # Searching: caller_name, note, source, dialed_number, caller_number, outgoing_number
99
- # Summary Grouping: source, keywords, campaign, referrer, landing_page, or company
100
- # Summary Fields: total_calls, missed_calls, answered_calls, first_time_callers, average_duration, formatted_average_duration, leads. Defaults to total_calls
101
- params[:tags] = opts[:tags] if opts[:tags]
102
- params[:note] = opts[:note] if opts[:note]
103
- params[:value] = opts[:value] if opts[:value]
104
- params[:lead_status] = opts[:lead_status] if opts[:lead_status]
105
- params[:group_by] = opts[:group_by] if opts[:group_by]
106
- params[:device] = opts[:device] if opts[:device]
107
- params[:min_duration] = opts[:min_duration] if opts[:min_duration]
108
- params[:max_duration] = opts[:max_duration] if opts[:max_duration]
109
- params[:tracker_ids] = opts[:tracker_ids] if opts[:tracker_ids]
110
- params[:direction] = opts[:direction] if opts[:direction]
111
- params[:answer_status] = opts[:answer_status] if opts[:answer_status]
112
- params[:first_time_callers] = opts[:first_time_callers] if opts[:first_time_callers]
113
- params[:agent] = opts[:agent] if opts[:agent]
114
- #Text Message Params
115
- # Filtering: date_range
116
- # Searching: customer_phone_number, customer_name
117
- #pagination
118
-
119
- return params
120
- end
121
-
122
- def get_responses(opts = {})
123
- responses = []
124
- params = set_params(opts)
125
- response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body
126
- total_pages = response["total_pages"] || 1
127
- total_records = response["total_records"] || 1
128
-
129
- while total_pages > 0
130
- response = (opts[:data]) ? response[opts[:data]] : response
131
- responses.push(response)
132
- params[:page] += 1 unless opts[:page]
133
- total_pages -= 1
134
- response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body unless total_pages < 1
135
- end
136
- return responses.flatten! || responses
137
- end
138
-
139
- # Account
140
- def get_accounts(opts = {})
141
- opts[:path] = (opts[:account_id]) ? "/" + opts[:account_id].to_s + ".json" : ".json"
142
- opts[:data] = "accounts" unless opts[:account_id]
143
- return get_responses(opts)
144
- end
145
-
146
- # Company
147
- def get_companies(opts = {})
148
- opts[:path] = (opts[:company_id]) ? "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json" : "/" + @account_id + "/companies.json"
149
- opts[:data] = "companies" unless opts[:company_id]
150
- return get_responses(opts)
151
- end
152
-
153
- def create_company(opts = {}) # http://apidocs.callrail.com/#time-zones
154
- params = set_params(opts)
155
- path = "/" + @account_id + "/companies.json"
156
- response = parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
157
- return response
158
- end
159
-
160
- def update_company(opts = {})
161
- params = set_params(opts)
162
- path = "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json"
163
- return parse_json(RestClient.put(@url+path, params, :Authorization => @auth)).body
164
- end
165
-
166
- def disable_company( opts = {})
167
- path = "/" + @account_id + "/companies/" + opts[:company_id].to_s
168
- return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
169
- end
170
-
171
- # User
172
- def get_users( opts={} )
173
- opts[:path] = (opts[:user_id]) ? "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json" : "/" + @account_id + "/users.json"
174
- opts[:data] = "users" unless opts[:user_id]
175
- return get_responses(opts)
176
- end
177
-
178
- def create_user( opts = {})
179
- params = set_params(opts)
180
- path = "/" + @account_id + "/users.json"
181
- return parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
182
- end
183
-
184
- def update_user(opts = {})
185
- params = set_params(opts)
186
- path = "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json"
187
- return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
188
- end
189
-
190
- # Calls
191
- def get_calls( opts={} )
192
- opts[:path] = (opts[:call_id]) ? "/" + @account_id + "/calls/" + opts[:call_id].to_s + ".json" : "/" + @account_id + "/calls.json"
193
- opts[:data] = "calls" unless opts[:call_id]
194
- return get_responses(opts)
195
- end
196
-
197
- def get_calls_summary( opts={} )
198
- opts[:path] = (opts[:time_series] == true) ? "/" + @account_id + "/calls/timeseries.json" : "/" + @account_id + "/calls/summary.json"
199
- return get_responses(opts)
200
- end
201
-
202
- def update_call(opts = {})
203
- params = set_params(opts)
204
- path = "/" + @account_id + "/calls/" + opts[:call_id].to_s + ".json"
205
- return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
206
- end
207
-
208
- def get_call_recording( opts={} )
209
- opts[:path] = "/" + @account_id + "/calls/" + opts[:call_id].to_s + "/recording.json"
210
- opts[:data] = "url"
211
- return get_responses(opts).first
212
- end
213
-
214
-
215
-
216
- # Tracker
217
- def get_trackers(opts={})
218
- opts[:path] = (opts[:tracker_id]) ? "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json" : "/" + @account_id + "/trackers.json"
219
- opts[:data] = "trackers" unless opts[:tracker_id]
220
- return get_responses(opts)
221
- end
222
-
223
- def create_tracker(opts={})
224
- opts[:path] = "/" + @account_id + "/trackers.json"
225
- params = set_params(opts)
226
- return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
227
- end
228
-
229
- def update_tracker(opts={})
230
- path = "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json"
231
- params = set_params(opts)
232
- return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
233
- end
234
-
235
- def disable_tracker(opts={})
236
- path = "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json"
237
- return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
238
- end
239
-
240
- # Integrations
241
- def get_integrations(opts ={})
242
- opts[:path] = (opts[:integration_id]) ? "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json" : "/" + @account_id + "/integrations.json"
243
- opts[:data] = "integrations" unless opts[:integration_id]
244
- return get_responses(opts)
245
- end
246
-
247
- def create_integration(opts ={})
248
- opts[:path] = "/" + @account_id + "/integrations.json"
249
- params = set_params(opts)
250
- return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
251
- end
252
-
253
- def update_integration(opts = {})
254
- params = set_params(opts)
255
- path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
256
- return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
257
- end
258
-
259
- def disable_integration(opts={})
260
- path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
261
- return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
262
- end
263
-
264
- end
265
- end
1
+ require 'bundler/setup'
2
+ require "callrail/version"
3
+ require 'json'
4
+ require 'ostruct'
5
+ require 'rest-client'
6
+
7
+ module Callrail
8
+ class Api
9
+
10
+ MAX_PAGE_SIZE = '250'
11
+
12
+ def initialize(opts = {})
13
+ @api_version = opts[:api_version] || "v3"
14
+ @url = "https://api.callrail.com/#{@api_version}/a"
15
+ @auth = "Token token=" + opts[:key]
16
+ @account_id = opts[:account_id].to_s if opts[:account_id]
17
+ end
18
+
19
+ def set_account_id(opts = {})
20
+ @account_id = opts[:account_id].to_s
21
+ end
22
+
23
+ def parse_json(response)
24
+ body = JSON.parse(response.to_str) if response.code == 200 || response.code == 201
25
+ OpenStruct.new(code: response.code, body: body)
26
+ end
27
+
28
+ def set_params(opts = {})
29
+ params = {}
30
+ #Result params
31
+ params[:date_range] = opts[:date_range] if opts[:date_range]
32
+ # Values: recent, today, yesterday, last_7_days, last_30_days, this_month, last_month, all_time
33
+ params[:start_date] = opts[:start_date] if opts[:start_date]
34
+ # ex: “2015-09-05” for all calls after and including September 9, 2015 - “2015-09-05T10:00” for all calls after 10 AM September 5, 2015
35
+ params[:end_date] = opts[:end_date] if opts[:end_date]
36
+ # ex: “2015-10-05” for all calls before and including October 9, 2015 - “2015-09-05T10:00” for all calls before 10 AM September 5, 2015
37
+ params[:sort] = opts[:sort] if opts[:sort]
38
+ # ex: /users.json?sort=email Will return a list of user objects for the target account, sorted by email address in alphabetical order.
39
+ params[:search] = opts[:search] if opts[:search]
40
+ # ex: users.json?search=belcher Will return a list of user objects in the target account that match the name given.
41
+ params[:fields] = opts[:fields] if opts[:fields]
42
+ # ex: calls/444941612.json?fields=company_id,company_name Will return the additional user requested fields for the target call.
43
+ params[:page] = opts[:page] || 1
44
+ params[:per_page] = opts[:per_page] || MAX_PAGE_SIZE
45
+ params[:path] = opts[:path] if opts[:path]
46
+ #Filters
47
+ if opts[:filtering]
48
+ opts[:filtering].each do |filter|
49
+ params[filter[:field].to_sym] = filter[:value]
50
+ end
51
+ end
52
+ #Shared Params
53
+ params[:name] = opts[:name] if opts[:name]
54
+ #Account Params
55
+ # Sorting: id, name
56
+ #Company Params
57
+ # Sorting: id, name
58
+ # Filtering: status
59
+ # Searching: name
60
+ params[:callscore_enabled] = opts[:callscore_enabled] if opts[:callscore_enabled]
61
+ params[:keyword_spotting_enabled] = opts[:keyword_spotting_enabled] if opts[:keyword_spotting_enabled]
62
+ params[:callscribe_enabled] = opts[:callscribe_enabled] if opts[:callscribe_enabled]
63
+ params[:time_zone] = opts[:time_zone] if opts[:time_zone]
64
+ # USA Values: America/New_York (Eastern Time Zone), America/Indiana/Indianapolis (Indiana Time Zone), America/Chicago (Central Time Zone),
65
+ # America/Denver (Mountain Time Zone), America/Phoenix (Arizona Time Zone), America/Los_Angeles (Pacific Time Zone)
66
+ # Full List: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
67
+ params[:swap_exclude_jquery] = opts[:swap_exclude_jquery] if opts[:swap_exclude_jquery]
68
+ params[:swap_ppc_override] = opts[:swap_ppc_override] if opts[:swap_ppc_override]
69
+ params[:swap_landing_override] = opts[:swap_landing_override] if opts[:swap_landing_override]
70
+ params[:swap_cookie_duration] = opts[:swap_cookie_duration] if opts[:swap_cookie_duration]
71
+ #User Params
72
+ # Sorting: id, email, created_at
73
+ # Searching: first_name, last_name, email
74
+ params[:first_name] = opts[:first_name] if opts[:first_name]
75
+ params[:last_name] = opts[:last_name] if opts[:last_name]
76
+ params[:email] = opts[:email] if opts[:email]
77
+ params[:role] = opts[:role] if opts[:role]
78
+ params[:password] = opts[:password] if opts[:password]
79
+ params[:companies] = opts[:companies] if opts[:companies]
80
+ params[:company_ids] = opts[:company_ids] if opts[:company_ids] #Callrail disabled
81
+ #Tracker Params
82
+ # Filtering: type, status
83
+ params[:type] = opts[:type] if opts[:type]
84
+ params[:company_id] = opts[:company_id] if opts[:company_id]
85
+ params[:call_flow] = opts[:call_flow] if opts[:call_flow]
86
+ params[:pool_size] = opts[:pool_size] if opts[:pool_size]
87
+ params[:pool_numbers] = opts[:pool_numbers] if opts[:pool_numbers]
88
+ params[:source] = opts[:source] if opts[:source]
89
+ params[:swap_targets] = opts[:swap_targets] if opts[:swap_targets]
90
+ params[:whisper_message] = opts[:whisper_message] if opts[:whisper_message]
91
+ params[:sms_enabled] = opts[:sms_enabled] if opts[:sms_enabled]
92
+ params[:tracking_number] = opts[:tracking_number] if opts[:tracking_number]
93
+ #Integration Params
94
+ params[:config] = opts[:config] if opts[:config]
95
+ params[:state] = opts[:state] if opts[:state]
96
+ #Call Params
97
+ # Sorting: customer_name, customer_phone_number, duration, start_time, source
98
+ # Filtering: date_range, answer_status, device, direction, lead_status
99
+ # Searching: caller_name, note, source, dialed_number, caller_number, outgoing_number
100
+ # Summary Grouping: source, keywords, campaign, referrer, landing_page, or company
101
+ # Summary Fields: total_calls, missed_calls, answered_calls, first_time_callers, average_duration, formatted_average_duration, leads. Defaults to total_calls
102
+ params[:tags] = opts[:tags] if opts[:tags]
103
+ params[:note] = opts[:note] if opts[:note]
104
+ params[:value] = opts[:value] if opts[:value]
105
+ params[:lead_status] = opts[:lead_status] if opts[:lead_status]
106
+ params[:group_by] = opts[:group_by] if opts[:group_by]
107
+ params[:device] = opts[:device] if opts[:device]
108
+ params[:min_duration] = opts[:min_duration] if opts[:min_duration]
109
+ params[:max_duration] = opts[:max_duration] if opts[:max_duration]
110
+ params[:tracker_ids] = opts[:tracker_ids] if opts[:tracker_ids]
111
+ params[:direction] = opts[:direction] if opts[:direction]
112
+ params[:answer_status] = opts[:answer_status] if opts[:answer_status]
113
+ params[:first_time_callers] = opts[:first_time_callers] if opts[:first_time_callers]
114
+ params[:agent] = opts[:agent] if opts[:agent]
115
+ #Text Message Params
116
+ # Filtering: date_range
117
+ # Searching: customer_phone_number, customer_name
118
+ #pagination
119
+
120
+ return params
121
+ end
122
+
123
+ def get_responses(opts = {})
124
+ responses = []
125
+ params = set_params(opts)
126
+ response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body
127
+ total_pages = response["total_pages"] || 1
128
+ total_records = response["total_records"] || 1
129
+
130
+ while total_pages > 0
131
+ response = (opts[:data]) ? response[opts[:data]] : response
132
+ responses.push(response)
133
+ params[:page] += 1 unless opts[:page]
134
+ total_pages -= 1
135
+ response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body unless total_pages < 1
136
+ end
137
+ return responses.flatten! || responses
138
+ end
139
+
140
+ # Account
141
+ def get_accounts(opts = {})
142
+ opts[:path] = (opts[:account_id]) ? "/" + opts[:account_id].to_s + ".json" : ".json"
143
+ opts[:data] = "accounts" unless opts[:account_id]
144
+ return get_responses(opts)
145
+ end
146
+
147
+ # Company
148
+ def get_companies(opts = {})
149
+ opts[:path] = (opts[:company_id]) ? "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json" : "/" + @account_id + "/companies.json"
150
+ opts[:data] = "companies" unless opts[:company_id]
151
+ return get_responses(opts)
152
+ end
153
+
154
+ def create_company(opts = {}) # http://apidocs.callrail.com/#time-zones
155
+ params = set_params(opts)
156
+ path = "/" + @account_id + "/companies.json"
157
+ response = parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
158
+ return response
159
+ end
160
+
161
+ def update_company(opts = {})
162
+ params = set_params(opts)
163
+ path = "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json"
164
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth)).body
165
+ end
166
+
167
+ def disable_company( opts = {})
168
+ path = "/" + @account_id + "/companies/" + opts[:company_id].to_s
169
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
170
+ end
171
+
172
+ # User
173
+ def get_users( opts={} )
174
+ opts[:path] = (opts[:user_id]) ? "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json" : "/" + @account_id + "/users.json"
175
+ opts[:data] = "users" unless opts[:user_id]
176
+ return get_responses(opts)
177
+ end
178
+
179
+ def create_user( opts = {})
180
+ params = set_params(opts)
181
+ path = "/" + @account_id + "/users.json"
182
+ return parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
183
+ end
184
+
185
+ def update_user(opts = {})
186
+ params = set_params(opts)
187
+ path = "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json"
188
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
189
+ end
190
+
191
+ # Calls
192
+ def get_calls( opts={} )
193
+ opts[:path] = (opts[:call_id]) ? "/" + @account_id + "/calls/" + opts[:call_id].to_s + ".json" : "/" + @account_id + "/calls.json"
194
+ opts[:data] = "calls" unless opts[:call_id]
195
+ return get_responses(opts)
196
+ end
197
+
198
+ def get_calls_summary( opts={} )
199
+ opts[:path] = (opts[:time_series] == true) ? "/" + @account_id + "/calls/timeseries.json" : "/" + @account_id + "/calls/summary.json"
200
+ return get_responses(opts)
201
+ end
202
+
203
+ def update_call(opts = {})
204
+ params = set_params(opts)
205
+ path = "/" + @account_id + "/calls/" + opts[:call_id].to_s + ".json"
206
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
207
+ end
208
+
209
+ def get_call_recording( opts={} )
210
+ opts[:path] = "/" + @account_id + "/calls/" + opts[:call_id].to_s + "/recording.json"
211
+ opts[:data] = "url"
212
+ return get_responses(opts).first
213
+ end
214
+
215
+
216
+
217
+ # Tracker
218
+ def get_trackers(opts={})
219
+ opts[:path] = (opts[:tracker_id]) ? "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json" : "/" + @account_id + "/trackers.json"
220
+ opts[:data] = "trackers" unless opts[:tracker_id]
221
+ return get_responses(opts)
222
+ end
223
+
224
+ def create_tracker(opts={})
225
+ opts[:path] = "/" + @account_id + "/trackers.json"
226
+ params = set_params(opts)
227
+ return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
228
+ end
229
+
230
+ def update_tracker(opts={})
231
+ path = "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json"
232
+ params = set_params(opts)
233
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
234
+ end
235
+
236
+ def disable_tracker(opts={})
237
+ path = "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json"
238
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
239
+ end
240
+
241
+ # Integrations
242
+ def get_integrations(opts ={})
243
+ opts[:path] = (opts[:integration_id]) ? "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json" : "/" + @account_id + "/integrations.json"
244
+ opts[:data] = "integrations" unless opts[:integration_id]
245
+ return get_responses(opts)
246
+ end
247
+
248
+ def create_integration(opts ={})
249
+ opts[:path] = "/" + @account_id + "/integrations.json"
250
+ params = set_params(opts)
251
+ return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
252
+ end
253
+
254
+ def update_integration(opts = {})
255
+ params = set_params(opts)
256
+ path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
257
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
258
+ end
259
+
260
+ def disable_integration(opts={})
261
+ path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
262
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
263
+ end
264
+
265
+ end
266
+ end