callrail 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32be84e443677aff60e60bb350c56f70ef2de42d
4
- data.tar.gz: bd8e1ee25df3c9fb056966f267acf3dc1e354f9b
3
+ metadata.gz: 755f0a7d0503a15aa630debbb1bc4e93a9d1ed70
4
+ data.tar.gz: e4ade5757b8caa6ac48e8e8bfb4de30f2dd4af1a
5
5
  SHA512:
6
- metadata.gz: e98b518e973b0e1cb095c2c5ca4e0623fa1ccaa7087352efe97831bb550432b58e8137f539cef4552fc7ecb86cfa7f45323087329859b9e9ac79240eef493b3a
7
- data.tar.gz: 94e67d4af52dd4e1dc15ca96f8a519ab6562afbb16c474c772c34ea893d0ca13503b92716223e1560f2520eef659f6eece0fbfd29039f9b20cf3d732cec3a09f
6
+ metadata.gz: 300a031b407ba7bd46762784d0d0d5c8d445585ed3ae8f89f408c949aeb595d7d40c59368470a22d509626512655d46d5edf6c95a83fa6efce794d3a343711e8
7
+ data.tar.gz: 5e5a03de59af3a266cada07bae9c566302e036b220bd9f067936133a8a5e45fe5a3342d8878d836ee7c8df684a2d0c842bfdc192f158fa919184e5f300df26a9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- callrail (0.2.0)
4
+ callrail (0.2.1)
5
5
  json (~> 2.1.0)
6
6
  rest-client (~> 2.0.2)
7
7
 
data/README.md CHANGED
@@ -90,6 +90,12 @@ testcon.disable_company(opts)
90
90
  ###### Get Users
91
91
  ``` testcon.get_users ```
92
92
 
93
+ ###### Get Users For a specific company
94
+ ```
95
+ user_opts = {:company_id => <company_id>}
96
+ puts testcon.get_users(user_opts)
97
+ ```
98
+
93
99
  ###### Get Specific User
94
100
  ```
95
101
  opts[:user_id] = <user_id>
data/lib/callrail.rb CHANGED
@@ -100,48 +100,39 @@ module Callrail
100
100
  # Filtering: date_range
101
101
  # Searching: customer_phone_number, customer_name
102
102
  #pagination
103
- params[:total_records] = get_total_records(params) if opts[:path]
104
- params[:total_pages] = get_total_pages(params) if opts[:path]
105
103
 
106
104
  return params
107
105
  end
108
106
 
109
- def get_total_records(params)
110
- total_records = parse_json(RestClient.get(@url+params[:path], params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total_records'] || 1
111
- return total_records
112
- end
113
-
114
- def get_total_pages(params)
115
- total_pages = parse_json(RestClient.get(@url+params[:path], params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total_pages'] || 1
116
- return total_pages
117
- end
118
-
119
107
  def get_responses(opts = {})
120
108
  responses = []
121
109
  params = set_params(opts)
122
- while params[:total_pages] > 0
123
- response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body
124
- response = (opts[:data]) ? response[opts[:data]] : response
110
+ response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body
111
+ total_pages = response["total_pages"] || 1
112
+ total_records = response["total_records"] || 1
113
+
114
+ while total_pages > 0
115
+ response = (opts[:data]) ? response[opts[:data]] : response
125
116
  responses.push(response)
126
117
  params[:page] += 1 unless opts[:page]
127
- params[:total_pages] -= 1
118
+ total_pages -= 1
119
+ response = parse_json(RestClient.get(@url+params[:path], params: params,:Authorization => @auth)).body
128
120
  end
129
- return responses
121
+ return responses.flatten! || responses
130
122
  end
123
+
131
124
  # Account Calls
132
125
  def get_accounts(opts = {})
133
126
  opts[:path] = (opts[:account_id]) ? "/" + opts[:account_id].to_s + ".json" : ".json"
134
127
  opts[:data] = "accounts" unless opts[:account_id]
135
- results = get_responses(opts)
136
- return results
128
+ return get_responses(opts)
137
129
  end
138
130
 
139
131
  # Company Calls
140
132
  def get_companies(opts = {})
141
133
  opts[:path] = (opts[:company_id]) ? "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json" : "/" + @account_id + "/companies.json"
142
134
  opts[:data] = "companies" unless opts[:company_id]
143
- results = get_responses(opts)
144
- return results
135
+ return get_responses(opts)
145
136
  end
146
137
 
147
138
  def create_company(opts = {}) # http://apidocs.callrail.com/#time-zones
@@ -154,84 +145,79 @@ module Callrail
154
145
  def update_company(opts = {})
155
146
  params = set_params(opts)
156
147
  path = "/" + @account_id + "/companies/" + opts[:company_id].to_s + ".json"
157
- response = parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
148
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth)).body
158
149
  end
159
150
 
160
151
  def disable_company( opts = {})
161
152
  path = "/" + @account_id + "/companies/" + opts[:company_id].to_s
162
- response = parse_json(RestClient.delete(@url+path, :Authorization => @auth))
153
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
163
154
  end
164
155
 
165
156
  # User Calls
166
157
  def get_users( opts={} )
167
158
  opts[:path] = (opts[:user_id]) ? "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json" : "/" + @account_id + "/users.json"
168
159
  opts[:data] = "users" unless opts[:user_id]
169
- results = get_responses(opts)
170
- return results
160
+ return get_responses(opts)
171
161
  end
172
162
 
173
163
  def create_user( opts = {})
174
164
  params = set_params(opts)
175
165
  path = "/" + @account_id + "/users.json"
176
- response = parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
177
- return response
166
+ return parse_json(RestClient.post(@url+path, params ,:Authorization => @auth))
178
167
  end
179
168
 
180
169
  def update_user(opts = {})
181
170
  params = set_params(opts)
182
171
  path = "/" + @account_id + "/users/" + opts[:user_id].to_s + ".json"
183
- response = parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
172
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
184
173
  end
185
174
 
186
175
  # Tracker Calls
187
176
  def get_trackers(opts={})
188
177
  opts[:path] = (opts[:tracker_id]) ? "/" + @account_id + "/trackers/" + opts[:tracker_id].to_s + ".json" : "/" + @account_id + "/trackers.json"
189
178
  opts[:data] = "trackers" unless opts[:tracker_id]
190
- results = get_responses(opts)
179
+ return get_responses(opts)
191
180
  end
192
181
 
193
182
  def create_tracker(opts={})
194
183
  opts[:path] = "/" + @account_id + "/trackers.json"
195
184
  params = set_params(opts)
196
- response = parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
197
- return response
185
+ return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
198
186
  end
199
187
 
200
188
  def update_tracker(opts={})
201
189
  opts[:path] = "/" + @account_id + "/trackers/" + opts[:tracker_id] + ".json"
202
190
  params = set_params(opts)
203
- response = parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
191
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
204
192
  end
205
193
 
206
194
  def disable_tracker(opts={})
207
195
  path = "/" + @account_id + "/trackers/" + opts[:tracker_id] + ".json"
208
- response = parse_json(RestClient.delete(@url+path, :Authorization => @auth))
196
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
209
197
  end
210
198
 
211
199
  # Integrations
212
200
  def get_integrations(opts ={})
213
201
  opts[:path] = (opts[:integration_id]) ? "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json" : "/" + @account_id + "/integrations.json"
214
202
  opts[:data] = "integrations" unless opts[:integration_id]
215
- results = get_responses(opts)
216
- return results
203
+ return get_responses(opts)
217
204
  end
218
205
 
219
206
  def create_integration(opts ={})
220
207
  opts[:path] = "/" + @account_id + "/integrations.json"
221
208
  params = set_params(opts)
222
- response = parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
223
- return response
209
+ return parse_json(RestClient.post(@url+opts[:path], params ,:Authorization => @auth))
224
210
  end
225
211
 
226
212
  def update_integration(opts = {})
227
213
  params = set_params(opts)
228
214
  path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
229
- response = parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
215
+ return parse_json(RestClient.put(@url+path, params, :Authorization => @auth))
230
216
  end
231
217
 
232
218
  def disable_integration(opts={})
233
219
  path = "/" + @account_id + "/integrations/" + opts[:integration_id].to_s + ".json"
234
- response = parse_json(RestClient.delete(@url+path, :Authorization => @auth))
220
+ return parse_json(RestClient.delete(@url+path, :Authorization => @auth))
235
221
  end
236
222
 
237
223
  end
@@ -1,3 +1,3 @@
1
1
  module Callrail
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hoskison