vivialconnect 0.0.4 → 0.0.5
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 +4 -4
- data/lib/vivialconnect.rb +1 -0
- data/lib/vivialconnect/client.rb +24 -42
- data/lib/vivialconnect/connector.rb +305 -0
- data/lib/vivialconnect/extra_connector_code.rb +0 -0
- data/lib/vivialconnect/log.rb +2 -2
- data/lib/vivialconnect/message.rb +2 -3
- data/lib/vivialconnect/number.rb +2 -3
- data/lib/vivialconnect/resource.rb +13 -13
- data/lib/vivialconnect/user.rb +2 -2
- data/lib/vivialconnect/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a6443884ab02922173831c0af10d3e119edaabf
|
4
|
+
data.tar.gz: d5c283b21cc7cccb274520fe25d66dfc1624d219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13453505754c33484921b976b94823f38f3a8bfdbe978cc3c1335928bce1791128de109442586a9fbdd13e7fe0e2010ae115afc65a22b519186f0b513280d394
|
7
|
+
data.tar.gz: 3d0f1ad6905305239b5a622cb6974b4fdaa1e9f679663ab47ea886638b183fba952227ebd39796701869942ecfbd953e4d5ac1c9111d6805854ddb2ee65dca41
|
data/lib/vivialconnect.rb
CHANGED
data/lib/vivialconnect/client.rb
CHANGED
@@ -100,13 +100,13 @@ module VivialConnect
|
|
100
100
|
@@host = host
|
101
101
|
end
|
102
102
|
|
103
|
-
def account_id
|
103
|
+
def account_id
|
104
104
|
@@account_id
|
105
|
-
end
|
105
|
+
end
|
106
106
|
|
107
107
|
def account_id=(id)
|
108
108
|
@@account_id = id
|
109
|
-
end
|
109
|
+
end
|
110
110
|
|
111
111
|
def reset_api_base_path(new_host, new_api_version)
|
112
112
|
set_host(new_host)
|
@@ -114,8 +114,7 @@ module VivialConnect
|
|
114
114
|
@base_api_path = host + api_version
|
115
115
|
connection
|
116
116
|
true
|
117
|
-
end
|
118
|
-
|
117
|
+
end
|
119
118
|
|
120
119
|
def api_version
|
121
120
|
@@api_version
|
@@ -133,42 +132,34 @@ module VivialConnect
|
|
133
132
|
@@configured == true
|
134
133
|
end
|
135
134
|
|
136
|
-
|
137
135
|
def set_request_timestamp
|
138
136
|
@request_timestamp = Time.now.utc.strftime('%Y%m%dT%H%M%SZ')
|
139
137
|
end
|
140
138
|
|
141
|
-
|
142
139
|
def request_timestamp
|
143
140
|
@request_timestamp
|
144
|
-
end
|
145
|
-
|
141
|
+
end
|
146
142
|
|
147
143
|
def set_date_for_date_header
|
148
144
|
@date_for_date_header = Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
149
|
-
end
|
150
|
-
|
145
|
+
end
|
151
146
|
|
152
147
|
def date_for_date_header
|
153
148
|
@date_for_date_header
|
154
|
-
end
|
155
|
-
|
149
|
+
end
|
156
150
|
|
157
151
|
def api_key
|
158
152
|
@@api_key
|
159
153
|
end
|
160
154
|
|
161
|
-
|
162
155
|
def api_secret
|
163
156
|
@@api_secret
|
164
157
|
end
|
165
158
|
|
166
|
-
|
167
159
|
def set_hmac_sha256(canonical_request)
|
168
160
|
@hmac_sha256 = OpenSSL::HMAC.hexdigest('SHA256', api_secret, canonical_request)
|
169
161
|
end
|
170
162
|
|
171
|
-
|
172
163
|
def hmac_sha256
|
173
164
|
@hmac_sha256
|
174
165
|
end
|
@@ -177,8 +168,7 @@ module VivialConnect
|
|
177
168
|
canonical_request = http_verb + "\n" + request_timestamp + "\n" + Addressable::URI.encode(url.path) +
|
178
169
|
"\n" + get_canonicalized_query_string(url) + "\n" + canonicalized_headers + "\n" +
|
179
170
|
canonicalized_header_names + "\n" + Digest::SHA256.hexdigest(data.to_s)
|
180
|
-
end
|
181
|
-
|
171
|
+
end
|
182
172
|
|
183
173
|
def sign_request(http_verb, url, data={})
|
184
174
|
set_request_timestamp
|
@@ -187,8 +177,7 @@ module VivialConnect
|
|
187
177
|
canonicalized_header_names = "accept;date;host"
|
188
178
|
canonical_request = build_canonical_request(http_verb, url, request_timestamp, canonicalized_headers, canonicalized_header_names, data)
|
189
179
|
set_hmac_sha256(canonical_request)
|
190
|
-
end
|
191
|
-
|
180
|
+
end
|
192
181
|
|
193
182
|
def get_canonicalized_query_string(url)
|
194
183
|
return "" unless url.query_values
|
@@ -199,7 +188,6 @@ module VivialConnect
|
|
199
188
|
encoded_sorted_params = Addressable::URI.form_encode(sorted_params).gsub('+', '%20')
|
200
189
|
end
|
201
190
|
|
202
|
-
|
203
191
|
def connection
|
204
192
|
@conn = Faraday.new(:url => base_api_path)
|
205
193
|
end
|
@@ -211,12 +199,11 @@ module VivialConnect
|
|
211
199
|
url = get_request_path(url)
|
212
200
|
sign_request(request_method, url, data)
|
213
201
|
headers = create_request_headers
|
214
|
-
request_method = request_method.downcase.to_sym
|
202
|
+
request_method = request_method.downcase.to_sym
|
215
203
|
response = connection.run_request(request_method, url, data.to_s, headers)
|
216
|
-
process_api_response(response, url)
|
204
|
+
process_api_response(response, url, request_method)
|
217
205
|
end
|
218
206
|
|
219
|
-
|
220
207
|
def create_request_headers
|
221
208
|
headers = {}
|
222
209
|
headers['Content-Type'] = 'application/json'
|
@@ -227,25 +214,21 @@ module VivialConnect
|
|
227
214
|
headers['Date'] = date_for_date_header
|
228
215
|
headers['Accept'] = 'application/json'
|
229
216
|
headers
|
230
|
-
end
|
231
|
-
|
217
|
+
end
|
232
218
|
|
233
219
|
def no_account_number_endpoints
|
234
220
|
['accounts.json', '/accounts/count.json', 'registration/register.json']
|
235
221
|
end
|
236
222
|
|
237
|
-
|
238
223
|
def account_regex_match?(url)
|
239
224
|
m = /accounts\/[0-9]+.json/.match(url)
|
240
225
|
return !m.nil?
|
241
226
|
end
|
242
227
|
|
243
|
-
|
244
228
|
def account_query_match?(url)
|
245
229
|
url.include?("accounts.json?")
|
246
230
|
end
|
247
231
|
|
248
|
-
|
249
232
|
def get_request_path(url)
|
250
233
|
if no_account_number_endpoints.include?(url) || account_regex_match?(url) || account_query_match?(url)
|
251
234
|
base_path = base_api_path
|
@@ -254,43 +237,43 @@ module VivialConnect
|
|
254
237
|
base_path = base_api_path + "accounts/#{account_id}"
|
255
238
|
Addressable::URI.parse(base_path + url)
|
256
239
|
end
|
257
|
-
end
|
240
|
+
end
|
258
241
|
|
259
|
-
def process_api_response(response, url)
|
242
|
+
def process_api_response(response, url, request_method)
|
260
243
|
# make API response into appropriate object and return it
|
261
244
|
api_response = {}
|
262
245
|
raise VivialConnectClientError, JSON.parse(response.body)['message'] ? JSON.parse(response.body)['message'] : response.body if response.status >= 400
|
263
246
|
response_class = choose_response_class(url.path)
|
264
|
-
if response.body == "" || response.body.include?("{}")
|
247
|
+
if request_method == :delete || response.body == "" || response.body.include?("{}")
|
265
248
|
return true if response.status.between?(200, 299)
|
266
249
|
false
|
250
|
+
api_response = JSON.parse(response.body)
|
267
251
|
else
|
268
252
|
api_response = JSON.parse(response.body)
|
269
|
-
if api_response[api_response.keys.first].is_a?(Array)
|
270
|
-
#return an array of resource objects
|
253
|
+
if api_response[api_response.keys.first].is_a?(Array)
|
254
|
+
#return an array of resource objects for typical .all requests
|
271
255
|
response_array = api_response[api_response.keys.first]
|
272
256
|
api_response = process_array(response_array, response_class)
|
273
257
|
elsif api_response[api_response.keys[1]].is_a?(Array)
|
274
258
|
#handle Log resource, return last key and an array full of log objects
|
275
259
|
last_key = api_response['last_key']
|
276
260
|
response_array = api_response['log_items']
|
277
|
-
processed_array = process_array(response_array, response_class)
|
261
|
+
processed_array = process_array(response_array, response_class)
|
278
262
|
[last_key, processed_array]
|
279
263
|
elsif api_response[api_response.keys.first].is_a?(Fixnum)
|
280
264
|
# json is only one level deep for .count response, so no need to delete the json root
|
281
265
|
# return the number
|
282
266
|
api_response['count']
|
283
|
-
else
|
267
|
+
else
|
284
268
|
if response_class == VivialConnect::Log
|
285
269
|
# json is only one level deep for Log response, so no need to delete the json root
|
286
270
|
response_class.new(api_response)
|
287
|
-
else
|
271
|
+
else
|
288
272
|
# remove json root, these resources return nested info
|
289
273
|
api_response = api_response[api_response.keys.first]
|
290
274
|
response_class.new(api_response)
|
291
275
|
end
|
292
|
-
end
|
293
|
-
|
276
|
+
end
|
294
277
|
end
|
295
278
|
end
|
296
279
|
|
@@ -306,7 +289,7 @@ module VivialConnect
|
|
306
289
|
return Account
|
307
290
|
elsif url.include?('attachments')
|
308
291
|
return Attachment
|
309
|
-
else
|
292
|
+
else
|
310
293
|
api_resource = url[5]
|
311
294
|
#exceptions needed for resources requiring camelcase
|
312
295
|
klass = api_resource.capitalize
|
@@ -316,7 +299,6 @@ module VivialConnect
|
|
316
299
|
end
|
317
300
|
end
|
318
301
|
|
319
|
-
|
320
302
|
end
|
321
|
-
end
|
303
|
+
end
|
322
304
|
|
@@ -0,0 +1,305 @@
|
|
1
|
+
module VivialConnect
|
2
|
+
##
|
3
|
+
#=== .all
|
4
|
+
#
|
5
|
+
#Returns an array containing ruby objects corresponding to all Connector resources on your account
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# Example usage:
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# VivialConnect::Connector.all
|
12
|
+
# => [#<VivialConnect::Connector account_id=10XXX, active=true, callbacks=[{"date_created"=>"2017-08-21T20:41:46+00:00", "date_modified"=>"2017-08-21T20:41:46+00:00", "event_type"=>"incoming", "message_type"=>"text", "method"=>"POST", "url"=>"path/for/callback"}, {"date_created"=>"2017-08-21T21:05:49+00:00", "date_modified"=>"2017-08-21T21:05:49+00:00", "event_type"=>"incoming_fallback", "message_type"=>"text", "method"=>"POST", "url"=>"path/for/backup/callback"}], date_created="2017-08-21T19:41:01+00:00", date_modified="2017-08-21T19:41:01+00:00", id=54, more_numbers=false, name="List Sender", phone_numbers=[{"phone_number"=>"+1646493XXXX", "phone_number_id"=>1XXX}, {"phone_number"=>"+1646494XXXX", "phone_number_id"=>1XXX}]> ...]
|
13
|
+
#
|
14
|
+
#
|
15
|
+
#=== .count
|
16
|
+
#
|
17
|
+
#Returns the amount of Connector resources you have set up on your account
|
18
|
+
#
|
19
|
+
# Example usage:
|
20
|
+
#
|
21
|
+
#
|
22
|
+
# VivialConnect::Connectors.count
|
23
|
+
# => 3
|
24
|
+
#
|
25
|
+
#
|
26
|
+
#
|
27
|
+
#=== .create(options={})
|
28
|
+
#
|
29
|
+
#Creates a record of the Connector and returns it as a Ruby object.
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# Required parameter:
|
33
|
+
#
|
34
|
+
# name | String | "Connector 1"
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# Example Usage
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# VivialConnect::Connector.create(name: "Connector 1")
|
41
|
+
# => #<VivialConnect::Connector account_id=10XXX, active=true, callbacks=[], date_created="2017-08-22T16:48:32+00:00", date_modified="2017-08-22T16:48:32+00:00", id=XXXX, more_numbers=false, name="Connector 1", phone_numbers=[]>
|
42
|
+
##
|
43
|
+
#=== .find(id)
|
44
|
+
#
|
45
|
+
#Returns the Connector resource referenced by the `id` value as a ruby object.
|
46
|
+
#
|
47
|
+
# Required parameter:
|
48
|
+
#
|
49
|
+
# id | Fixnum | the id of the message you would like to retrieve
|
50
|
+
#
|
51
|
+
#
|
52
|
+
# Example usage:
|
53
|
+
#
|
54
|
+
#
|
55
|
+
# VivialConnect::Connector.find(5555)
|
56
|
+
# => #<VivialConnect::Connector account_id=10XXX, active=true, callbacks=[], date_created="2017-08-22T16:48:32+00:00", date_modified="2017-08-22T16:48:32+00:00", id=XXXX, more_numbers=false, name="Connector 1", phone_numbers=[]>
|
57
|
+
#
|
58
|
+
#
|
59
|
+
#=== .update(id, options={})
|
60
|
+
#
|
61
|
+
#Updates the Connector resource with the provided id and returns it
|
62
|
+
#
|
63
|
+
# Required parameters:
|
64
|
+
#
|
65
|
+
# id | Fixnum | 10000
|
66
|
+
#
|
67
|
+
# Example usage:
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# VivialConnect::Connector.update(5555, name: "New Connector Name")
|
71
|
+
# => #<VivialConnect::Connector account_id=10XXX, active=true, callbacks=[], date_created="2017-08-22T16:48:32+00:00", date_modified="2017-08-22T16:48:32+00:00", id=XXXX, more_numbers=false, name="New Connector Name", phone_numbers=[]>
|
72
|
+
#
|
73
|
+
##
|
74
|
+
#=== .delete(id)
|
75
|
+
#
|
76
|
+
#Deletes the Connector resource with the provided id from your account and returns true. WARNING: this cannot be undone.
|
77
|
+
#
|
78
|
+
# Required parameters:
|
79
|
+
#
|
80
|
+
# id | Fixnum | 10000
|
81
|
+
#
|
82
|
+
#
|
83
|
+
# Example usage:
|
84
|
+
#
|
85
|
+
# VivialConnect::Connector.delete(5555)
|
86
|
+
# => true
|
87
|
+
#
|
88
|
+
#
|
89
|
+
#=== \#add_number(number)
|
90
|
+
#
|
91
|
+
#Adds a number resource to the Connector object and saves it. If the Connector object has not been saved prior, it will save for the first time during this process.
|
92
|
+
#If you wish to add more than one number to your Connector at a time, pass the numbers in an Array i.e. [num_1, num_2, num_3]
|
93
|
+
#
|
94
|
+
# Required parameters:
|
95
|
+
#
|
96
|
+
# number | VivialConnect::Number
|
97
|
+
#
|
98
|
+
#
|
99
|
+
# Example usage:
|
100
|
+
#
|
101
|
+
#
|
102
|
+
# connector = VivialConnect::Connector.new
|
103
|
+
# number = VivialConnect::Number.all.first
|
104
|
+
# connector.add_number(number)
|
105
|
+
# => #<VivialConnect::Connector account_id=10###, active=true, callbacks=[], date_created="2017-08-24T20:04:18+00:00", date_modified="2017-08-24T20:04:18+00:00", id=7##, more_numbers=false, name=nil, phone_numbers=[{"phone_number"=>"+1646493####", "phone_number_id"=>1###}]>
|
106
|
+
#
|
107
|
+
#=== \#delete_number(number)
|
108
|
+
#
|
109
|
+
#Dissassociates a number from the Connector. This does not release the number. You can still add it back or to another Connector.
|
110
|
+
#If you wish to delete more than one number from your Connector at a time, pass the numbers in an Array i.e. [num_1, num_2, num_3]
|
111
|
+
#
|
112
|
+
# Required parameters:
|
113
|
+
#
|
114
|
+
# number | VivialConnect::Number
|
115
|
+
#
|
116
|
+
#
|
117
|
+
# Example usage:
|
118
|
+
#
|
119
|
+
#
|
120
|
+
# connector = VivialConnect::Connector.all.first
|
121
|
+
# number = VivialConnect::Number.all.first
|
122
|
+
# connector.delete_number(number)
|
123
|
+
# => #<VivialConnect::Connector account_id=10###, active=true, callbacks=[], date_created="2017-08-24T20:04:18+00:00", date_modified="2017-08-24T20:04:18+00:00", id=7##, more_numbers=false, name=nil, phone_numbers=[{"phone_number"=>"+1646493####", "phone_number_id"=>1###}]>
|
124
|
+
#
|
125
|
+
#=== \#add_callback(callback)
|
126
|
+
#
|
127
|
+
#Adds a callback resource to the Connector object and saves it. If the Connector object has not been saved prior, it will save for the first time during this process.
|
128
|
+
#If you wish to add more than one callback to your Connector at a time, pass the callbacks in an Array i.e. [cb_1, cb_2, cb_3]
|
129
|
+
#
|
130
|
+
# Required parameters for callback Hash:
|
131
|
+
#
|
132
|
+
# message_type | String | Can either be "text" or "voice"
|
133
|
+
# event_type | String | Can be "incoming", "incoming_fallback", "status"
|
134
|
+
# url | String | The URL that will receive callback request
|
135
|
+
# method | String | Can be "GET", "POST", or "PUT"
|
136
|
+
#
|
137
|
+
#
|
138
|
+
# Example usage:
|
139
|
+
#
|
140
|
+
#
|
141
|
+
# connector = VivialConnect::Connector.new
|
142
|
+
# callback = {event_type: "incoming", message_type: "text", url: "path/for/calback", method: "GET"}
|
143
|
+
# connector.add_callback(callback)
|
144
|
+
# => #<VivialConnect::Connector account_id=10144, active=true, callbacks=[{"date_created"=>"2017-08-28T13:41:01+00:00", "date_modified"=>"2017-08-28T13:41:01+00:00", "event_type"=>"incoming", "message_type"=>"text", "method"=>nil, "url"=>"path/for/calback"}], date_created="2017-08-23T16:22:20+00:00", date_modified="2017-08-23T16:22:20+00:00", id=XX, more_numbers=false, name="Hello Connector", phone_numbers=[]>
|
145
|
+
#
|
146
|
+
#=== \#delete_callback(callback)
|
147
|
+
#
|
148
|
+
#Deletes a callback resource on the Connector object.
|
149
|
+
#If you wish to delete more than one callback from your Connector at a time, pass the callbacks in an Array i.e. [cb_1, cb_2, cb_3]
|
150
|
+
#
|
151
|
+
# Required parameters for callback Hash:
|
152
|
+
#
|
153
|
+
# message_type | String | Can either be "text" or "voice"
|
154
|
+
# event_type | String | Can be "incoming", "incoming_fallback", "status"
|
155
|
+
#
|
156
|
+
# Example usage:
|
157
|
+
#
|
158
|
+
#
|
159
|
+
# connector = VivialConnect::Connector.all.first
|
160
|
+
# number = VivialConnect::Connector.all.first
|
161
|
+
# connector.delete_callback({event_type: "incoming", message_type: "text"})
|
162
|
+
# => #<VivialConnect::Connector account_id=10XXX, active=true, callbacks=[], date_created="2017-08-25T14:51:04+00:00", date_modified="2017-08-25T14:51:04+00:00", id=XX, more_numbers=false, name=nil, phone_numbers=[]>
|
163
|
+
#
|
164
|
+
class Connector < Resource
|
165
|
+
|
166
|
+
def add_number(input) # :nodoc:
|
167
|
+
if self.id == nil
|
168
|
+
self.save
|
169
|
+
end
|
170
|
+
if input.class == Array
|
171
|
+
input.each {|num| created = VivialConnect::Connector::Number.create_or_update(self, num); self.phone_numbers << created}
|
172
|
+
else
|
173
|
+
created = VivialConnect::Connector::Number.create_or_update(self, input)
|
174
|
+
self.phone_numbers << created
|
175
|
+
end
|
176
|
+
self.phone_numbers = VivialConnect::Connector.find(self.id).phone_numbers
|
177
|
+
self
|
178
|
+
end
|
179
|
+
|
180
|
+
def delete_number(input) # :nodoc:
|
181
|
+
if input.class == Array
|
182
|
+
input.each {|num| VivialConnect::Connector::Number.delete(self.id,[phone_number_id: num.id, phone_number: num.phone_number ])}
|
183
|
+
else
|
184
|
+
response = VivialConnect::Connector::Number.delete(self.id,[phone_number_id: input.id, phone_number: input.phone_number ])
|
185
|
+
end
|
186
|
+
self.phone_numbers = VivialConnect::Connector.find(self.id).phone_numbers
|
187
|
+
self
|
188
|
+
end
|
189
|
+
|
190
|
+
def add_callback(input) # :nodoc:
|
191
|
+
if self.id == nil
|
192
|
+
self.save
|
193
|
+
end
|
194
|
+
if input.class == Array
|
195
|
+
input.each {|cb| created = VivialConnect::Connector::Callback.create_or_update(self, cb); self.callbacks << created}
|
196
|
+
else
|
197
|
+
created = VivialConnect::Connector::Callback.create_or_update(self, input)
|
198
|
+
self.callbacks << created
|
199
|
+
end
|
200
|
+
|
201
|
+
self.callbacks = VivialConnect::Connector.find(self.id).callbacks
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
def delete_callback(input) # :nodoc:
|
206
|
+
if input.class == Array
|
207
|
+
input.each {|cb| VivialConnect::Connector::Callback.delete(self.id,[message_type: cb[:message_type], event_type: cb[:event_type]])}
|
208
|
+
else
|
209
|
+
response = VivialConnect::Connector::Callback.delete(self.id,[message_type: input[:message_type], event_type: input[:event_type]])
|
210
|
+
end
|
211
|
+
self.callbacks = VivialConnect::Connector.find(self.id).callbacks
|
212
|
+
self
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
module Callback # :nodoc:
|
217
|
+
# add callback for connector
|
218
|
+
def self.create_by_connector_id(id, options = {}) # :nodoc:
|
219
|
+
data = {}
|
220
|
+
data['connector'] = {}
|
221
|
+
data['connector']['callbacks'] = options
|
222
|
+
data = data.to_json
|
223
|
+
uri = "/connectors/#{id}/callbacks.json"
|
224
|
+
VivialConnect::Client.instance.make_request('POST', uri, data)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Updates the list of callbacks for the connector id provided, editing existing ones and adding new ones
|
228
|
+
def self.update_by_connector_id(id, options = {}) # :nodoc:
|
229
|
+
data = {}
|
230
|
+
data['connector'] = {}
|
231
|
+
data['connector']['callbacks'] = options
|
232
|
+
data = data.to_json
|
233
|
+
uri = "/connectors/#{id}/callbacks.json"
|
234
|
+
VivialConnect::Client.instance.make_request('PUT', uri, data)
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.create_or_update(connector, input) # :nodoc:
|
238
|
+
if connector.callbacks.count > 0
|
239
|
+
VivialConnect::Connector::Callback.update_by_connector_id(connector.id, [message_type: input[:message_type], event_type: input[:event_type], url: input[:url], method: input[:request_method]])
|
240
|
+
else
|
241
|
+
VivialConnect::Connector::Callback.create_by_connector_id(connector.id, [message_type: input[:message_type], event_type: input[:event_type], url: input[:url], method: input[:request_method]])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# Deletes the callbacks provided in the body from the Connector with id of {connector_id} path parameter.
|
246
|
+
def self.delete(id, options = {}) # :nodoc:
|
247
|
+
data = {}
|
248
|
+
data['connector'] = {}
|
249
|
+
data['connector']['callbacks'] = options
|
250
|
+
data = data.to_json
|
251
|
+
uri = "/connectors/#{id}/callbacks.json"
|
252
|
+
VivialConnect::Client.instance.make_request('DELETE', uri, data)
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
module Number # :nodoc:
|
258
|
+
|
259
|
+
# add numbers to connector
|
260
|
+
def self.create_by_connector_id(id, options = {}) # :nodoc:
|
261
|
+
data = {}
|
262
|
+
data['connector'] = {}
|
263
|
+
data['connector']['phone_numbers'] = options
|
264
|
+
data = data.to_json
|
265
|
+
uri = "/connectors/#{id}/phone_numbers.json"
|
266
|
+
VivialConnect::Client.instance.make_request('POST', uri, data)
|
267
|
+
end
|
268
|
+
|
269
|
+
# update numbers for connector
|
270
|
+
def self.update_by_connector_id(id, options = {}) # :nodoc:
|
271
|
+
data = {}
|
272
|
+
data['connector'] = {}
|
273
|
+
data['connector']['phone_numbers'] = options
|
274
|
+
data = data.to_json
|
275
|
+
uri = "/connectors/#{id}/phone_numbers.json"
|
276
|
+
VivialConnect::Client.instance.make_request('PUT', uri, data)
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.create_or_update(connector, input) # :nodoc:
|
280
|
+
if connector.phone_numbers.count > 0
|
281
|
+
VivialConnect::Connector::Number.update_by_connector_id(connector.id,[phone_number_id: input.id, phone_number: input.phone_number ])
|
282
|
+
else
|
283
|
+
VivialConnect::Connector::Number.create_by_connector_id(connector.id,[phone_number_id: input.id, phone_number: input.phone_number ])
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
# delete numbers for connector
|
288
|
+
def self.delete(id, options = {}) # :nodoc:
|
289
|
+
data = {}
|
290
|
+
data['connector'] = {}
|
291
|
+
data['connector']['phone_numbers'] = options
|
292
|
+
data = data.to_json
|
293
|
+
uri = "/connectors/#{id}/phone_numbers.json"
|
294
|
+
VivialConnect::Client.instance.make_request('DELETE', uri, data)
|
295
|
+
end
|
296
|
+
|
297
|
+
def self.count_by_connector_id(id) # :nodoc:
|
298
|
+
uri = "/connectors/#{id}/phone_numbers/count.json"
|
299
|
+
VivialConnect::Client.instance.make_request('GET', uri)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
File without changes
|
data/lib/vivialconnect/log.rb
CHANGED
@@ -48,7 +48,7 @@ module VivialConnect
|
|
48
48
|
# => [ 7b226163...', [ #<VivialConnect::Log>, #<VivialConnect::Log>, #<VivialConnect::Log> ]]
|
49
49
|
#
|
50
50
|
#
|
51
|
-
|
51
|
+
|
52
52
|
class Log < Resource
|
53
53
|
|
54
54
|
def self.find_by_time(options = {}) #:nodoc:
|
@@ -63,7 +63,7 @@ module VivialConnect
|
|
63
63
|
numbers_template = Addressable::Template.new("#{uri}{?query*}")
|
64
64
|
uri = numbers_template.expand(query: options).to_s
|
65
65
|
VivialConnect::Client.instance.make_request('GET', uri)
|
66
|
-
end
|
66
|
+
end
|
67
67
|
|
68
68
|
end
|
69
69
|
|
data/lib/vivialconnect/number.rb
CHANGED
@@ -281,7 +281,7 @@ module VivialConnect
|
|
281
281
|
# => #<VivialConnect::Number account_id=1XXXX, active=true, address_requirements="none", capabilities={"mms"=>true, "sms"=>true, "voice"=>true}, city="PITTSBURGH ", date_created="2017-04-25T09:56:04-04:00", date_modified="2017-04-25T09:56:04-04:00", id=66, lata=nil, master_account_id=10096, status_text_url=nil, name="new name for this number", phone_number="+14124330365", phone_number_type="local", rate_center="PTTSBGZON1", region="PA", sms_configuration_id=nil, incoming_text_fallback_method=nil, incoming_text_fallback_url=nil, incoming_text_method=nil, incoming_text_url=nil, voice_forwarding_number=nil>
|
282
282
|
#
|
283
283
|
#
|
284
|
-
|
284
|
+
|
285
285
|
class Number < Resource
|
286
286
|
|
287
287
|
singleton_class.send(:alias_method, :buy, :create)
|
@@ -314,8 +314,7 @@ module VivialConnect
|
|
314
314
|
|
315
315
|
def self.local # :nodoc:
|
316
316
|
VivialConnect::Client.instance.make_request('GET', '/numbers/local.json')
|
317
|
-
end
|
318
|
-
|
317
|
+
end
|
319
318
|
|
320
319
|
end
|
321
320
|
|
@@ -20,14 +20,17 @@ class Resource < OpenStruct # :nodoc:
|
|
20
20
|
##
|
21
21
|
# Returns an array containing all of the API resources
|
22
22
|
|
23
|
-
def self.all
|
23
|
+
def self.all(path=false)
|
24
24
|
final_array = []
|
25
25
|
page = 1
|
26
26
|
limit = 100
|
27
27
|
while true
|
28
|
-
path = path_builder(:all)
|
28
|
+
path = path ||= path_builder(:all)
|
29
29
|
uri = build_template_uri(path: path, start: page, batch_size: limit)
|
30
30
|
current_iteration = VivialConnect::Client.instance.make_request('GET', uri)
|
31
|
+
if current_iteration.class != Array
|
32
|
+
return []
|
33
|
+
end
|
31
34
|
final_array = update_final_array(current_iteration, final_array)
|
32
35
|
break final_array if current_iteration.count < limit
|
33
36
|
page += 1
|
@@ -120,7 +123,7 @@ class Resource < OpenStruct # :nodoc:
|
|
120
123
|
data = data.to_json
|
121
124
|
uri = path_builder(:update, id)
|
122
125
|
VivialConnect::Client.instance.make_request('PUT', uri, data)
|
123
|
-
end
|
126
|
+
end
|
124
127
|
|
125
128
|
##
|
126
129
|
# Deletes the record defined by the provided id.
|
@@ -132,7 +135,7 @@ class Resource < OpenStruct # :nodoc:
|
|
132
135
|
data['id'] = id
|
133
136
|
data = data.to_json
|
134
137
|
VivialConnect::Client.instance.make_request('DELETE', uri, data)
|
135
|
-
end
|
138
|
+
end
|
136
139
|
|
137
140
|
|
138
141
|
def self.redact(id)
|
@@ -165,7 +168,7 @@ class Resource < OpenStruct # :nodoc:
|
|
165
168
|
end
|
166
169
|
end
|
167
170
|
return url
|
168
|
-
end
|
171
|
+
end
|
169
172
|
|
170
173
|
def self.pluralize(string) # :nodoc:
|
171
174
|
# avoids importing a library but will need to be improved upon depending on future api resource names
|
@@ -182,7 +185,7 @@ class Resource < OpenStruct # :nodoc:
|
|
182
185
|
data['phone_number'] = options
|
183
186
|
return data
|
184
187
|
end
|
185
|
-
end
|
188
|
+
end
|
186
189
|
|
187
190
|
def self.class_to_path # :nodoc:
|
188
191
|
base = self.to_s.split('::')[-1].downcase
|
@@ -204,7 +207,7 @@ class Resource < OpenStruct # :nodoc:
|
|
204
207
|
end
|
205
208
|
end
|
206
209
|
final.join("").downcase
|
207
|
-
end
|
210
|
+
end
|
208
211
|
|
209
212
|
def self.build_template_uri(path: p, start: nil, batch_size: nil) # :nodoc:
|
210
213
|
all_template = Addressable::Template.new("#{path}{?query*}")
|
@@ -220,7 +223,7 @@ class Resource < OpenStruct # :nodoc:
|
|
220
223
|
# This instance method saves the current object if it does not have an id
|
221
224
|
# and updates the existing object if it does have an id. It is equivalent to calling .create or .update
|
222
225
|
# on the instance level.
|
223
|
-
|
226
|
+
|
224
227
|
def save
|
225
228
|
if self.id.nil?
|
226
229
|
data = self.class.build_hash_root_and_add_user_hash(self.to_h)
|
@@ -239,7 +242,7 @@ class Resource < OpenStruct # :nodoc:
|
|
239
242
|
new_object_hash =response_object.marshal_dump
|
240
243
|
self.add_methods(new_object_hash)
|
241
244
|
self
|
242
|
-
end
|
245
|
+
end
|
243
246
|
end
|
244
247
|
|
245
248
|
##
|
@@ -253,9 +256,6 @@ class Resource < OpenStruct # :nodoc:
|
|
253
256
|
data['id'] = self.id
|
254
257
|
data = data.to_json
|
255
258
|
VivialConnect::Client.instance.make_request('DELETE', uri, data)
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
|
-
|
259
|
+
end
|
260
260
|
|
261
261
|
end
|
data/lib/vivialconnect/user.rb
CHANGED
@@ -152,7 +152,7 @@ module VivialConnect
|
|
152
152
|
data[:user] = {_password: old_pw, password: new_pw}
|
153
153
|
data = data.to_json
|
154
154
|
response = VivialConnect::Client.instance.make_request('PUT', "/users/#{self.id}/profile/password.json", data)
|
155
|
-
end
|
156
|
-
|
155
|
+
end
|
156
|
+
|
157
157
|
end
|
158
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vivialconnect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin LeFurjah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -133,7 +133,9 @@ files:
|
|
133
133
|
- lib/vivialconnect/account.rb
|
134
134
|
- lib/vivialconnect/attachment.rb
|
135
135
|
- lib/vivialconnect/client.rb
|
136
|
+
- lib/vivialconnect/connector.rb
|
136
137
|
- lib/vivialconnect/contact.rb
|
138
|
+
- lib/vivialconnect/extra_connector_code.rb
|
137
139
|
- lib/vivialconnect/log.rb
|
138
140
|
- lib/vivialconnect/message.rb
|
139
141
|
- lib/vivialconnect/number.rb
|