callrail 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -15
- data/.rspec +3 -3
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +268 -272
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/callrail.gemspec +39 -39
- data/lib/callrail/version.rb +3 -3
- data/lib/callrail.rb +266 -266
- metadata +13 -14
data/callrail.gemspec
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "callrail/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "callrail"
|
8
|
-
spec.version = Callrail::VERSION
|
9
|
-
spec.authors = ["Michael Hoskison"]
|
10
|
-
spec.email = ["mhoskison@etnainteractive.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Used to access the CallRail api}
|
13
|
-
spec.description = %q{CallRail API}
|
14
|
-
spec.homepage = "https://github.com/mhoskiso/callrail.git"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
"public gem pushes."
|
24
|
-
end
|
25
|
-
|
26
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
f.match(%r{^(test|spec|features)/})
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
spec.add_development_dependency "bundler", "~>
|
34
|
-
spec.add_development_dependency "rake", "~>
|
35
|
-
spec.add_development_dependency "rspec", "~> 3.
|
36
|
-
|
37
|
-
spec.add_dependency "rest-client", "~> 2.0
|
38
|
-
spec.add_dependency "json", "~> 2.
|
39
|
-
end
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "callrail/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "callrail"
|
8
|
+
spec.version = Callrail::VERSION
|
9
|
+
spec.authors = ["Michael Hoskison"]
|
10
|
+
spec.email = ["mhoskison@etnainteractive.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Used to access the CallRail api}
|
13
|
+
spec.description = %q{CallRail API}
|
14
|
+
spec.homepage = "https://github.com/mhoskiso/callrail.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.3.3"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0.6"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.12"
|
36
|
+
|
37
|
+
spec.add_dependency "rest-client", "~> 2.1.0"
|
38
|
+
spec.add_dependency "json", "~> 2.6.3"
|
39
|
+
end
|
data/lib/callrail/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Callrail
|
2
|
-
VERSION = "0.2.
|
3
|
-
end
|
1
|
+
module Callrail
|
2
|
+
VERSION = "0.2.9"
|
3
|
+
end
|
data/lib/callrail.rb
CHANGED
@@ -1,266 +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
|
-
@api_version = opts[:api_version] || "
|
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
|
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
|