trustedsearch 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDEzY2RhNTY1Nzk0OWZhNDM2MzJmNjJiZTg4NzBkZTlkY2ZlZThkNw==
4
+ MzBjOTczNWRmODNjN2UzZDVhM2Q3ZjIwNDZkZmVmNTIwYTMxZjY4MQ==
5
5
  data.tar.gz: !binary |-
6
- NDgwZDU2NjEzODgxNDIwNGNiMTdiM2JkN2I5MTgyY2NmYTE5YTg2ZA==
6
+ N2RhMDNhMDQ4ZGQ1ZDQ5NTI3NWM0NjYzODgwMzNiYzU1MGQzM2NlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODBmMmY2NTRhNWU2NTg3NDJiOWVlM2I3MGI4OGIxMTFjNTdhYzVjYWMyY2Qx
10
- ZGFiYTM0ODZlOTIwOWVjZGIyM2YyZGZkNjI2MGZhZTEyZjgzMGQ2ZDcwMWIz
11
- MTRiYWQzYmM3YmNiN2U0Y2FlMjlkMTFmY2Q1ODE5NjVjZTE1OTY=
9
+ MWQzMWE4ZTU1ZDEyZjEwNDU1NTc4NzFiNDczNDY0ZGIyMDFhMzE0ZDcyMTlj
10
+ ZWIyYTdhMmJmODI5OTg1MWQzNmYzMTUyYWQ0YjdmODYyZjBmYjk5MTZkMzY3
11
+ ZjQ4OGE3NDUwMGFmZGNiMzY5YmVkOWY0OTZjNjBjM2M0YTc2ZjU=
12
12
  data.tar.gz: !binary |-
13
- NTk2OWI5MTBlODkxMzkwODQyN2EwMDE2ODdiMWEzMWNmYTNiYWFjNDQ1ZWNj
14
- ODQ5MWJhNGZhNGRlMzdkNmZkODM5ZmNlMGQwMWUwMTU1MjMzZWNmMzE3Mjg1
15
- NjQ3ZjU1MzcwZjk3ZGQ3OWIwNDIzNWNmZDZmYTUxNzU0MDk1MDg=
13
+ ZWRjMDAyMWExMDYzMTA5OGQ5OGVkMzdlZTZjOTNlNGVlM2NhZWUzYzM2NWY2
14
+ ZjEzYTdkNGY5YThmN2Q0MGNiNzQxZDdhZjQzNmRjYjQ1N2ExMTNiNDQyYTFh
15
+ MGQ4ZDE3NDliZmNkOWNjZTc5MWM0OTczZmYxNzA5YTM4ZTc4YmM=
data/README.md CHANGED
@@ -35,7 +35,7 @@ The gem is designed to support all existing and future [TRUSTEDSearch API's](htt
35
35
  To start using the gem, you need to be given your sandbox and production public & private keys.
36
36
 
37
37
 
38
- ### API Examples
38
+ ## API V1 Examples
39
39
 
40
40
  Include the required libs & set your public and private keys
41
41
 
@@ -57,6 +57,12 @@ See the [API documentation](http://developers.trustedsearch.org/#/get-business-u
57
57
  api = TrustedSearch::V1.new
58
58
  puts api.getBusinessUpdate().data.to_s
59
59
  ```
60
+ ##### Rake
61
+
62
+ ```ruby
63
+ rake v1:updates[YourPublicKey,YourPrivateKey]
64
+ ```
65
+
60
66
 
61
67
  #### Get Business Updates for single location
62
68
  See the [API documentation](http://developers.trustedsearch.org/#/get-business-updates) for a list of parameters for each API resource.
@@ -66,6 +72,14 @@ api = TrustedSearch::V1.new
66
72
  puts api.getBusinessUpdate(534f95e8-1de1-558f-885c-3962f22c9a28).data.to_s
67
73
  ```
68
74
 
75
+ ##### Rake
76
+ Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28
77
+
78
+ ```ruby
79
+ rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]
80
+ ```
81
+
82
+
69
83
  #### Get Business Updates since epoch 1380611103
70
84
  See the [API documentation](http://developers.trustedsearch.org/#/get-business-updates) for a list of parameters for each API resource.
71
85
 
@@ -74,6 +88,12 @@ api = TrustedSearch::V1.new
74
88
  puts api.getBusinessUpdateSince(1380611103).data.to_s
75
89
  ```
76
90
 
91
+ ##### Rake
92
+ Get update since 1380611103
93
+ ```ruby
94
+ rake v1:updates_since[YourPublicKey,YourPrivateKey,1380611103]
95
+ ```
96
+
77
97
  #### Submit New Business Listings
78
98
 
79
99
  See the [API documentation](http://developers.trustedsearch.org/#/submitting-a-business) for a list of parameters for each API resource.
@@ -139,6 +159,14 @@ response = api.postBusiness(business_data)
139
159
  uuid = response.data[0]["uuid"]
140
160
  ```
141
161
 
162
+ ##### Rake
163
+
164
+ Submit a new location using JSON data in file relative path "examples/body.json"
165
+
166
+ ```ruby
167
+ rake v1:submit[YourPublicKey,YourPrivateKey,"examples/body.json"]
168
+ ```
169
+
142
170
  ### Testing
143
171
 
144
172
  #### Testing / Simulating a change in a business listing
@@ -149,7 +177,280 @@ uuid = '534f95e8-1de1-558f-885c-3962f22c9a28'
149
177
  api = TrustedSearch::V1.new
150
178
  response = api.putTestFulfillment(uuid)
151
179
 
180
+ ```
181
+ ##### Rake
182
+
183
+ SANDBOX ONLY: Test the fulfilment process for development & testing purposes
184
+
185
+ ```ruby
186
+ rake v1:test_fulfillment[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]
187
+ ```
188
+
189
+ ## V2 Api Examples
190
+
191
+ ### Hooks
192
+
193
+ #### Index: Retrieve an array of hooks that can be subscribed to.
194
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-index)
195
+
196
+ ```ruby
197
+ hook = TrustedSearch::V2::Hook.new
198
+ puts hook.index().data.to_json
199
+ ```
200
+
201
+ ##### Rake
202
+
203
+ ```ruby
204
+ rake v2:hooks:index[PUBLIC_KEY,PRIVATE_KEY]
205
+ ```
206
+
207
+ ##### Response
208
+ ```ruby
209
+ {
210
+ :status=>"success",
211
+ :code=>200,
212
+ :message=>"",
213
+ :data=>
214
+ [
215
+ {
216
+ :id => 1,
217
+ :name => "location.updates",
218
+ :description => "Data for the location has been update within TRUSTEDSearch ecosystem.",
219
+ :product_id => nil,
220
+ :created_at => "0000-00-00 00:00:00",
221
+ :updated_at => "0000-00-00 00:00:00"
222
+ },
223
+ {
224
+ :id => 2,
225
+ :name => "location.audit",
226
+ :description => "Results of an audit.",
227
+ :product_id => 63,
228
+ :created_at => "0000-00-00 00:00:00",
229
+ :updated_at => "0000-00-00 00:00:00"
230
+ },
231
+ {
232
+ :id => 3,
233
+ :name => "location.report",
234
+ :description => "Results of a recurring reporting for a given location and its listings.",
235
+ :product_id => 64,
236
+ :created_at => "0000-00-00 00:00:00",
237
+ :updated_at => "0000-00-00 00:00:00"
238
+ }
239
+ ]
240
+ }
241
+ ```
242
+
243
+ #### Show: Show a single hook record.
244
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-show)
245
+
246
+ ```ruby
247
+ hook = TrustedSearch::V2::Hook.new
248
+ puts hook.show("1").data.to_json
249
+
250
+ ```
251
+
252
+ ##### Rake
253
+
254
+ ```ruby
255
+ rake v2:hooks:show[PUBLIC_KEY,PRIVATE_KEY,1]
256
+ ```
257
+
258
+ ##### Reponse
259
+
260
+ ```ruby
261
+ {
262
+ :status => "success",
263
+ :code => 200,
264
+ :message => "",
265
+ :data=>
266
+ {
267
+ :id => 1,
268
+ :name => "location.updates",
269
+ :description => "Data for the location has been update within TRUSTEDSearch ecosystem.",
270
+ :product_id => nil,
271
+ :created_at => "0000-00-00 00:00:00",
272
+ :updated_at => "0000-00-00 00:00:00"
273
+ }
274
+ }
275
+ ```
276
+
277
+ ### Subscriptions
278
+
279
+ #### Index: Retrieve an array of all hook subscriptions you are subscribed to.
280
+
281
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-index)
282
+
283
+ ```ruby
284
+ subscription = TrustedSearch::V2::HookSubscription.new
285
+ pp subscription.index().data
286
+
287
+ ```
288
+
289
+ ##### Rake
290
+
291
+ ```ruby
292
+ rake v2:hooksubscriptions:index[PUBLIC_KEY,PRIVATE_KEY]
293
+ ```
294
+
295
+ ##### Response
296
+
297
+ ```ruby
298
+ {
299
+ :status=>"success",
300
+ :code=>200,
301
+ :message=>"",
302
+ :data=> [
303
+ {
304
+ :id => "624c83f1-3c0d-4b27-86e1-c80d88dbf8e2",
305
+ :hook_id => 1,
306
+ :user_id => 94,
307
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-updates",
308
+ :created_at => "2014-03-20 18:32:45",
309
+ :updated_at => "2014-03-20 18:32:45"
310
+ },
311
+ {
312
+ :id => "bdd46e50-669a-49cf-93ce-db682f6e9008",
313
+ :hook_id => 2,
314
+ :user_id => 94,
315
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-audits",
316
+ :created_at => "2014-03-20 18:33:21",
317
+ :updated_at => "2014-03-20 18:33:21"
318
+ }
319
+ ]
320
+ }
321
+ ```
322
+
152
323
 
324
+ #### Create: Create a new hook subscription
325
+
326
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-create)
327
+
328
+ ```ruby
329
+
330
+ subscription = TrustedSearch::V2::HookSubscription.new
331
+ data = {
332
+ :hook => "location.updates",
333
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-updates"
334
+ }
335
+ pp subscription.create(data).data
336
+ ```
337
+
338
+ ##### Rake
339
+
340
+ ```ruby
341
+ rake v2:hooksubscriptions:create[PUBLIC_KEY,PRIVATE_KEY,location.update,http://api.myendpoint.com/trustedsearch/location-updates]
342
+ ```
343
+
344
+ ##### Response
345
+ ```ruby
346
+ {
347
+ :status => "success",
348
+ :code => 200,
349
+ :message => "",
350
+ :data=> {
351
+ :hook_id => 1,
352
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-updates",
353
+ :user_id => 94,
354
+ :id => "bdd46e50-669a-49cf-93ce-db682f6e9008",
355
+ :updated_at => "2014-03-20 18:33:21",
356
+ :created_at => "2014-03-20 18:33:21"
357
+ }
358
+ }
359
+ ```
360
+
361
+ #### Show: Show a hook subscription record
362
+
363
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-show)
364
+
365
+ ```ruby
366
+ subscription = TrustedSearch::V2::HookSubscription.new
367
+ pp subscription.show("bdd46e50-669a-49cf-93ce-db682f6e9008").data
368
+ ```
369
+
370
+ ##### Rake
371
+
372
+ ```ruby
373
+ rake env=local v2:hooksubscriptions:show[PUBLIC_KEY,PRIVATE_KEY,bdd46e50-669a-49cf-93ce-db682f6e9008]
374
+ ```
375
+
376
+ ##### Response
377
+
378
+ ```ruby
379
+ {
380
+ :status => "success",
381
+ :code => 200,
382
+ :message => "",
383
+ :data => {
384
+ :id => "bdd46e50-669a-49cf-93ce-db682f6e9008",
385
+ :hook_id => 1,
386
+ :user_id => 94,
387
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-updates",
388
+ :created_at => "2014-03-20 18:33:21",
389
+ :updated_at => "2014-03-20 18:33:21"
390
+ }
391
+ }
392
+ ```
393
+
394
+ #### Update: Update an existing hook subscription record.
395
+
396
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-update)
397
+
398
+ ```ruby
399
+ subscription = TrustedSearch::V2::HookSubscription.new
400
+ data = {
401
+ :hook => "loocation.audit",
402
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-audit"
403
+ }
404
+ pp subscription.update("bdd46e50-669a-49cf-93ce-db682f6e9008", data).data
405
+ ```
406
+
407
+ ##### Rake
408
+
409
+ ```ruby
410
+ rake v2:hooksubscriptions:update[PUBLIC_KEY,PRIVATE_KEY,bdd46e50-669a-49cf-93ce-db682f6e9008,location.audit,http://api.myendpoint.com/trustedsearch/location-audit]
411
+ ```
412
+
413
+ ##### Response
414
+ ```ruby
415
+ {
416
+ :status => "success",
417
+ :code => 200,
418
+ :message => "",
419
+ :data => {
420
+ :id => "bdd46e50-669a-49cf-93ce-db682f6e9008",
421
+ :hook_id => 2, ###<----- Notice this changed to a 2
422
+ :user_id => 94,
423
+ :target_url => "http://api.myendpoint.com/trustedsearch/location-audit", ####<----Notice this updated.
424
+ :created_at => "2014-03-20 18:33:21",
425
+ :updated_at => "2014-03-20 18:35:11"
426
+ }
427
+ }
428
+
429
+ ```
430
+
431
+ #### Destroy: Destroy an existing hook-subscription record.
432
+
433
+ [API documentation](http://developers.trustedsearch.org/#/v2-subscriptions-destroy)
434
+
435
+ ```ruby
436
+ subscription = TrustedSearch::V2::HookSubscription.new
437
+ pp subscription.destroy(args.id).data
438
+ ```
439
+ ##### Rake
440
+
441
+ ```ruby
442
+ rake v2:hooksubscriptions:destroy[PUBLIC_KEY,PRIVATE_KEY,bdd46e50-669a-49cf-93ce-db682f6e9008]
443
+ ```
444
+
445
+ ##### Response
446
+
447
+ ```ruby
448
+ {
449
+ :status => "success",
450
+ :code => 200,
451
+ :message => "Successfully removed subscription : bdd46e50-669a-49cf-93ce-db682f6e9008",
452
+ :data => []
453
+ }
153
454
  ```
154
455
 
155
456
  ### Error Handling
@@ -191,25 +492,3 @@ Code: 409
191
492
 
192
493
  ```
193
494
 
194
-
195
- ### Rake Examples
196
-
197
- Get all udpates in your account
198
-
199
- rake v1:updates[YourPublicKey,YourPrivateKey]
200
-
201
- Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28
202
-
203
- rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]
204
-
205
- Get update since 1380611103
206
-
207
- rake v1:updates_since[YourPublicKey,YourPrivateKey,1380611103]
208
-
209
- Submit a new location using JSON data in file relative path "examples/body.json"
210
-
211
- rake v1:submit[YourPublicKey,YourPrivateKey,"examples/body.json"]
212
-
213
- SANDBOX ONLY: Test the fulfilment process for development & testing purposes
214
-
215
- rake v1:test_fulfillment[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]
data/lib/tasks/v2.rake ADDED
@@ -0,0 +1,146 @@
1
+ require 'pp'
2
+ namespace :v2 do
3
+
4
+ task :default do
5
+
6
+ end
7
+
8
+ namespace :hooks do
9
+ desc "Get a list of all the hooks."
10
+ task :index, [:public_key, :private_key] do |t, args|
11
+ TrustedSearch.public_key = args.public_key
12
+ TrustedSearch.private_key = args.private_key
13
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
14
+
15
+ hook = TrustedSearch::V2::Hook.new
16
+ begin
17
+ pp hook.index().data
18
+ rescue Exception => e
19
+ puts "Message: " + e.message.to_s
20
+ #puts "Body:"
21
+ puts e.backtrace
22
+ #puts "Code: " + e.code.to_s
23
+ end
24
+
25
+ end
26
+
27
+ desc "Get a single hook."
28
+ task :show, [:public_key, :private_key, :id] do |t, args|
29
+ TrustedSearch.public_key = args.public_key
30
+ TrustedSearch.private_key = args.private_key
31
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
32
+
33
+ hook = TrustedSearch::V2::Hook.new
34
+ begin
35
+ pp hook.show(args.id).data
36
+ rescue Exception => e
37
+ puts "Message: " + e.message.to_s
38
+ #puts "Body:"
39
+ #puts e.backtrace
40
+ #puts "Code: " + e.code.to_s
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ namespace :hooksubscriptions do
47
+ desc "Get a list of all the subscriptions you are subscribed to."
48
+ task :index, [:public_key, :private_key] do |t, args|
49
+ TrustedSearch.public_key = args.public_key
50
+ TrustedSearch.private_key = args.private_key
51
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
52
+
53
+ subscription = TrustedSearch::V2::HookSubscription.new
54
+ begin
55
+ pp subscription.index().data
56
+ rescue Exception => e
57
+ puts "Message: " + e.message.to_s
58
+ #puts "Body:"
59
+ #puts e.backtrace
60
+ #puts "Code: " + e.code.to_s
61
+ end
62
+
63
+ end
64
+
65
+ desc "Show a single subscription."
66
+ task :show, [:public_key, :private_key, :id] do |t, args|
67
+ TrustedSearch.public_key = args.public_key
68
+ TrustedSearch.private_key = args.private_key
69
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
70
+
71
+ subscription = TrustedSearch::V2::HookSubscription.new
72
+ begin
73
+ pp subscription.show(args.id).data
74
+ rescue Exception => e
75
+ puts "Message: " + e.message.to_s
76
+ #puts "Body:"
77
+ #puts e.backtrace
78
+ #puts "Code: " + e.code.to_s
79
+ end
80
+
81
+ end
82
+
83
+ desc "Create a single subscription."
84
+ task :create, [:public_key, :private_key, :hook, :target_url] do |t, args|
85
+ TrustedSearch.public_key = args.public_key
86
+ TrustedSearch.private_key = args.private_key
87
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
88
+
89
+ subscription = TrustedSearch::V2::HookSubscription.new
90
+ begin
91
+ data = {
92
+ :hook => args.hook,
93
+ :target_url => args.target_url
94
+ }
95
+ pp subscription.create(data).data
96
+ rescue Exception => e
97
+ puts "Message: " + e.message.to_s
98
+ #puts "Body:"
99
+ #puts e.backtrace
100
+ #puts "Code: " + e.code.to_s
101
+ end
102
+
103
+ end
104
+
105
+ desc "Update a single subscription."
106
+ task :update, [:public_key, :private_key, :id, :hook, :target_url] do |t, args|
107
+ TrustedSearch.public_key = args.public_key
108
+ TrustedSearch.private_key = args.private_key
109
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
110
+
111
+ subscription = TrustedSearch::V2::HookSubscription.new
112
+ begin
113
+ data = {
114
+ :hook => args.hook,
115
+ :target_url => args.target_url
116
+ }
117
+ pp subscription.update(args.id, data).data
118
+ rescue Exception => e
119
+ puts "Message: " + e.message.to_s
120
+ #puts "Body:"
121
+ #puts e.backtrace
122
+ #puts "Code: " + e.code.to_s
123
+ end
124
+
125
+ end
126
+
127
+ desc "Destroy a single subscription."
128
+ task :destroy, [:public_key, :private_key, :id] do |t, args|
129
+ TrustedSearch.public_key = args.public_key
130
+ TrustedSearch.private_key = args.private_key
131
+ TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
132
+
133
+ subscription = TrustedSearch::V2::HookSubscription.new
134
+ begin
135
+ pp subscription.destroy(args.id).data
136
+ rescue Exception => e
137
+ puts "Message: " + e.message.to_s
138
+ #puts "Body:"
139
+ #puts e.backtrace
140
+ #puts "Code: " + e.code.to_s
141
+ end
142
+
143
+ end
144
+ end
145
+
146
+ end
@@ -13,6 +13,12 @@ module TrustedSearch
13
13
  "/v1/"
14
14
  end
15
15
 
16
+ #Update All request to Version 1.
17
+ def request(method='get', resource_url, params, body)
18
+ TrustedSearch::api_version = 1
19
+ super
20
+ end
21
+
16
22
  # Makes an API request to /directory-listings
17
23
  # If uuid is nil, all are returned.
18
24
  def getBusinessUpdate(uuid = nil)
@@ -39,7 +39,7 @@ module TrustedSearch
39
39
 
40
40
  timestamp = get_time()
41
41
 
42
- url_to_sign = base_path + api_resource
42
+ url_to_sign = base_path() + api_resource
43
43
 
44
44
  params.merge!(
45
45
  {
@@ -49,7 +49,7 @@ module TrustedSearch
49
49
  }
50
50
  )
51
51
 
52
- resource_url = end_point + url_to_sign
52
+ resource_url = end_point() + url_to_sign
53
53
  request('get', resource_url, params, body)
54
54
  end
55
55
 
@@ -98,6 +98,27 @@ module TrustedSearch
98
98
  request('put', resource_url, params, body)
99
99
  end
100
100
 
101
+ def delete(api_resource, params = {}, body = {})
102
+ @resource ||= api_resource
103
+ has_keys()
104
+
105
+ raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
106
+
107
+ timestamp = get_time()
108
+
109
+ url_to_sign = base_path + api_resource
110
+
111
+ params.merge!({
112
+ apikey: TrustedSearch.public_key,
113
+ signature: sign_request(TrustedSearch.private_key, url_to_sign, body, timestamp ),
114
+ timestamp: timestamp
115
+ })
116
+
117
+ resource_url = end_point + url_to_sign
118
+
119
+ request('delete', resource_url, params, body)
120
+ end
121
+
101
122
  def sign_request( private_key, url, body, timestamp )
102
123
 
103
124
  body_md5 = (body == "") ? "" : Base64.strict_encode64( Digest::MD5.digest(body.to_json) )
@@ -124,7 +145,7 @@ module TrustedSearch
124
145
 
125
146
  timeout = TrustedSearch.api_timeout
126
147
  begin
127
-
148
+ puts resource_url
128
149
  case method
129
150
  when 'get'
130
151
  response = self.class.get(resource_url, query: params, timeout: timeout)
@@ -132,6 +153,8 @@ module TrustedSearch
132
153
  response = self.class.post(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
133
154
  when 'put'
134
155
  response = self.class.put(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
156
+ when 'delete'
157
+ response = self.class.delete(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
135
158
  end
136
159
 
137
160
  rescue Timeout::Error
@@ -140,13 +163,11 @@ module TrustedSearch
140
163
  process(response)
141
164
  end
142
165
 
143
-
144
166
  def process(response)
145
- # puts response.code
167
+ # puts response.to_s
146
168
  # body = JSON.parse(response.body)
147
169
  # puts body.to_json
148
170
  # puts response.message
149
-
150
171
  case response.code
151
172
 
152
173
  when 200, 201, 204
@@ -3,11 +3,37 @@ module TrustedSearch
3
3
  attr_reader :meta, :data, :request, :code
4
4
 
5
5
  def initialize(response)
6
- @request = response.request
6
+ @request = response.request
7
7
  @code = response.code
8
8
  #handle case where body has no response and thus JSON.parse requires octet aka a byte.
9
9
  @data = (response.body.length >=2) ? JSON.parse(response.body.strip) : nil
10
10
 
11
+ #Lets symbolize Version responses.
12
+ if(TrustedSearch::api_version == 2)
13
+ @data = self.symbolize_keys(@data)
14
+ end
15
+ end
16
+
17
+ def symbolize_keys(x)
18
+ if x.is_a? Hash
19
+ x.inject({}) do |result, (key, value)|
20
+ new_key = case key
21
+ when String then key.to_sym
22
+ else key
23
+ end
24
+ new_value = case value
25
+ when Hash then symbolize_keys(value)
26
+ when Array then symbolize_keys(value)
27
+ else value
28
+ end
29
+ result[new_key] = new_value
30
+ result
31
+ end
32
+ elsif x.is_a? Array
33
+ x.map {|el| symbolize_keys(el)}
34
+ else
35
+ x
36
+ end
11
37
  end
12
38
 
13
39
  end
@@ -0,0 +1,45 @@
1
+ module TrustedSearch
2
+ module V2
3
+ class HookSubscription < ApiVersion2
4
+ attr_accessor :resource
5
+
6
+ def initialize
7
+ @resource = 'hook-subscriptions'
8
+ end
9
+
10
+ #Retrieve an array of all hook subscriptions
11
+ def index()
12
+ method_url = @resource
13
+ return self.get(method_url)
14
+ end
15
+
16
+ #Show the details of a single hook
17
+ def show(id = nil)
18
+ method_url = @resource + "/" + id
19
+ params = {}
20
+ return self.get(method_url, params)
21
+ end
22
+
23
+ #Create a new subscription
24
+ def create(data = nil)
25
+ method_url = @resource
26
+ params = {}
27
+ return self.post(method_url, params, data)
28
+ end
29
+
30
+ #Update a subscription
31
+ def update(id = nil, data)
32
+ method_url = @resource + "/" + id
33
+ params = {}
34
+ return self.put(method_url, params, data)
35
+ end
36
+
37
+ #Delete/Destroy a subscription
38
+ def destroy(id = nil)
39
+ method_url = @resource + "/" + id
40
+ return self.delete(method_url)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ module TrustedSearch
2
+ module V2
3
+ class Hook < ApiVersion2
4
+ attr_accessor :resource
5
+
6
+ def initialize
7
+ @resource = 'hooks'
8
+ end
9
+
10
+ #Retrieve an array of all available hooks
11
+ def index()
12
+ method_url = @resource
13
+ return self.get(method_url)
14
+ end
15
+
16
+ #Get the details of a single hook
17
+ def show(id = nil)
18
+ method_url = @resource + "/" + id
19
+ params = {}
20
+ return self.get(method_url, params)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module TrustedSearch
2
+ module V2
3
+ class ApiVersion2 < Api
4
+ def base_path
5
+ if self == APIResource
6
+ raise NotImplementedError.new("APIResource is an abstract class. You should perform actions on its subclasses (i.e. Publisher)")
7
+ end
8
+ "/v2/"
9
+ end
10
+ #Update All request to Version 2.
11
+ def request(method='get', resource_url, params, body)
12
+ TrustedSearch::api_version = 2
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/trustedsearch.rb CHANGED
@@ -13,6 +13,9 @@ require_relative "trustedsearch/version"
13
13
  require_relative "trustedsearch/api_response"
14
14
  require_relative "trustedsearch/api_resource"
15
15
  require_relative "trustedsearch/api"
16
+ require_relative "trustedsearch/v2/v2"
17
+ require_relative "trustedsearch/v2/hooks"
18
+ require_relative "trustedsearch/v2/hook_subscriptions"
16
19
 
17
20
  require_relative "trustedsearch/errors/error"
18
21
  require_relative "trustedsearch/errors/authentication_error"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trustedsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - trustedSEARCH Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -142,8 +142,12 @@ executables: []
142
142
  extensions: []
143
143
  extra_rdoc_files: []
144
144
  files:
145
+ - LICENSE
146
+ - README.md
145
147
  - lib/tasks/test.rb
146
148
  - lib/tasks/v1.rake
149
+ - lib/tasks/v2.rake
150
+ - lib/trustedsearch.rb
147
151
  - lib/trustedsearch/api.rb
148
152
  - lib/trustedsearch/api_resource.rb
149
153
  - lib/trustedsearch/api_response.rb
@@ -151,10 +155,10 @@ files:
151
155
  - lib/trustedsearch/errors/connection_error.rb
152
156
  - lib/trustedsearch/errors/error.rb
153
157
  - lib/trustedsearch/errors/invalid_request_error.rb
158
+ - lib/trustedsearch/v2/hook_subscriptions.rb
159
+ - lib/trustedsearch/v2/hooks.rb
160
+ - lib/trustedsearch/v2/v2.rb
154
161
  - lib/trustedsearch/version.rb
155
- - lib/trustedsearch.rb
156
- - LICENSE
157
- - README.md
158
162
  homepage: https://github.com/trustedsearch/ruby-trustedsearch
159
163
  licenses:
160
164
  - MIT
@@ -175,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
179
  version: '0'
176
180
  requirements: []
177
181
  rubyforge_project:
178
- rubygems_version: 2.1.11
182
+ rubygems_version: 2.2.2
179
183
  signing_key:
180
184
  specification_version: 4
181
185
  summary: trustedSEARCH API Ruby SDK