trustedsearch 1.0.3 → 1.0.4
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 +8 -8
- data/README.md +17 -2
- data/lib/tasks/test.rb +8 -0
- data/lib/tasks/v1.rake +22 -1
- data/lib/trustedsearch/api.rb +12 -4
- data/lib/trustedsearch/api_resource.rb +35 -7
- data/lib/trustedsearch/api_response.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODk5MDY5Nzk1MjFlYTM3NTI4ZmIxOWEyODE2MzdhZjBhYjkzYmMwMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWUyM2FjMjkzOGIzNTQwNjUyODAwZjRkNDAwZWIyNGZlZDY2OGU4Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmQ2OTRjODE4NmM0YjZiMmE1ZTZlMjYzMDU2NTFjNTJjNThhZTA1YTdiY2U5
|
10
|
+
ZTQxMGU5Yzk3OTZjMzZlNzUzYWVhZWI2MWVlZTU1NjMyZWExOTUzN2ZkMDNi
|
11
|
+
ZjFjNWE5ZWEyYjlhZjZmZDIxMDcxZjI5Mzk4MTk2ZjI4MmZjNzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjlkZWQ4ZmY1YzcyYjE0YTY1ZWZlM2E1MTYyZDU0MzQ2OTU1MmIzMGVjNzAw
|
14
|
+
Zjc2MmVjZjVhOGE4NWY0OWU0YzMyNjBjNzcyYWZjZjliZGI2NmZmNWM0MTU5
|
15
|
+
NTFkYjY4ZDE3ZTNiMTIwNmM3ZDkzZWZiYWFlNDQ4NWUwMWY4N2Q=
|
data/README.md
CHANGED
@@ -137,8 +137,23 @@ response = api.postBusiness(business_data)
|
|
137
137
|
uuid = response.data[0]["uuid"]
|
138
138
|
```
|
139
139
|
|
140
|
+
### Testing
|
141
|
+
|
142
|
+
#### Testing / Simulating a change in a business listing
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
|
146
|
+
uuid = '534f95e8-1de1-558f-885c-3962f22c9a28'
|
147
|
+
api = TrustedSearch::V1.new
|
148
|
+
response = api.putTestFulfillment(uuid)
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
140
155
|
### Rake Examples
|
141
|
-
|
156
|
+
|
142
157
|
Get all udpates in your account
|
143
158
|
|
144
159
|
rake v1:updates[YourPublicKey,YourPrivateKey]
|
@@ -149,7 +164,7 @@ Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28
|
|
149
164
|
|
150
165
|
Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28 since 1380611103
|
151
166
|
|
152
|
-
rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28,1380611103]
|
167
|
+
rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28,1380611103]
|
153
168
|
|
154
169
|
Submit a new location using JSON data in file relative path "examples/body.json"
|
155
170
|
|
data/lib/tasks/test.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require "trustedsearch"
|
2
|
+
|
3
|
+
TrustedSearch.public_key = "0e2e66593bd4e7423ab83b2ded17acfa"
|
4
|
+
TrustedSearch.private_key = "pakaThe3rupHuprEnupraCha"
|
5
|
+
TrustedSearch.environment = "sandbox" #default is 'sandbox'
|
6
|
+
|
7
|
+
api = TrustedSearch::V1.new
|
8
|
+
puts api.getBusinessUpdate().data.to_s
|
data/lib/tasks/v1.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :v1 do
|
2
2
|
task :default do
|
3
|
-
|
3
|
+
|
4
4
|
end
|
5
5
|
|
6
6
|
desc "Get the directory listings updates. [uuid] if not specified, returns all."
|
@@ -9,6 +9,9 @@ namespace :v1 do
|
|
9
9
|
TrustedSearch.private_key = args.private_key
|
10
10
|
TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
|
11
11
|
uuid = ( args.uuid.nil? ? nil : args.uuid)
|
12
|
+
if(uuid == "")
|
13
|
+
uuid = nil
|
14
|
+
end
|
12
15
|
since = ( args.since.nil? ? nil : args.since)
|
13
16
|
api = TrustedSearch::V1.new
|
14
17
|
puts api.getBusinessUpdate(uuid, since).data.to_s
|
@@ -33,4 +36,22 @@ namespace :v1 do
|
|
33
36
|
file.close
|
34
37
|
puts response.data
|
35
38
|
end
|
39
|
+
|
40
|
+
task :test_fulfillment, [:public_key, :private_key, :uuid] do |t, args|
|
41
|
+
TrustedSearch.public_key = args.public_key
|
42
|
+
TrustedSearch.private_key = args.private_key
|
43
|
+
TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
|
44
|
+
|
45
|
+
location_id = args.uuid
|
46
|
+
location_id = ( args.uuid ? args.uuid : nil)
|
47
|
+
|
48
|
+
if(location_id.nil?)
|
49
|
+
puts "You must specify a uuid of the business you wish to test."
|
50
|
+
next
|
51
|
+
end
|
52
|
+
|
53
|
+
api = TrustedSearch::V1.new
|
54
|
+
response = api.putTestFulfillment(location_id)
|
55
|
+
puts response.data
|
56
|
+
end
|
36
57
|
end
|
data/lib/trustedsearch/api.rb
CHANGED
@@ -14,10 +14,12 @@ module TrustedSearch
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Makes an API request to /directory-listings
|
17
|
-
# If uuid is nil, all are returned.
|
17
|
+
# If uuid is nil, all are returned.
|
18
18
|
# If since is provided as an integer, only changes made since that time are returned.
|
19
19
|
def getBusinessUpdate(uuid = nil , since = nil)
|
20
|
-
|
20
|
+
|
21
|
+
method_url = 'directory-listings' + ( ( uuid ) ? "/#{uuid}" : '')
|
22
|
+
puts method_url
|
21
23
|
params = {}
|
22
24
|
if(since)
|
23
25
|
params[:since] = since
|
@@ -26,10 +28,16 @@ module TrustedSearch
|
|
26
28
|
return self.get(method_url, params)
|
27
29
|
end
|
28
30
|
|
29
|
-
#Submit a single business more multiple business for
|
31
|
+
#Submit a single business more multiple business for
|
30
32
|
def postBusiness( data = [] )
|
31
|
-
method_url = 'local-business'
|
33
|
+
method_url = 'local-business'
|
32
34
|
return self.post(method_url, {} , data )
|
33
35
|
end
|
36
|
+
|
37
|
+
|
38
|
+
def putTestFulfillment( uuid = nil)
|
39
|
+
method_url = 'test-fulfillment/' + uuid.to_s
|
40
|
+
return self.put(method_url)
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
@@ -31,14 +31,14 @@ module TrustedSearch
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def get(api_resource, params = {}, body =
|
34
|
+
def get(api_resource, params = {}, body = '')
|
35
35
|
@resource ||= api_resource
|
36
36
|
has_keys()
|
37
37
|
|
38
38
|
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
39
39
|
|
40
40
|
timestamp = get_time()
|
41
|
-
|
41
|
+
|
42
42
|
url_to_sign = base_path + api_resource
|
43
43
|
|
44
44
|
params.merge!({
|
@@ -54,14 +54,15 @@ module TrustedSearch
|
|
54
54
|
def get_time
|
55
55
|
return Time.now.utc.to_i
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
|
+
def post(api_resource, params = {}, body = {})
|
58
59
|
@resource ||= api_resource
|
59
60
|
has_keys()
|
60
61
|
|
61
62
|
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
62
63
|
|
63
64
|
timestamp = get_time()
|
64
|
-
|
65
|
+
|
65
66
|
url_to_sign = base_path + api_resource
|
66
67
|
|
67
68
|
params.merge!({
|
@@ -74,9 +75,30 @@ module TrustedSearch
|
|
74
75
|
request('post', resource_url, params, body)
|
75
76
|
end
|
76
77
|
|
78
|
+
def put(api_resource, params = {}, body = {})
|
79
|
+
@resource ||= api_resource
|
80
|
+
has_keys()
|
81
|
+
|
82
|
+
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
83
|
+
|
84
|
+
timestamp = get_time()
|
85
|
+
|
86
|
+
url_to_sign = base_path + api_resource
|
87
|
+
|
88
|
+
params.merge!({
|
89
|
+
apikey: TrustedSearch.public_key,
|
90
|
+
signature: sign_request(TrustedSearch.private_key, url_to_sign, body, timestamp ),
|
91
|
+
timestamp: timestamp
|
92
|
+
})
|
93
|
+
|
94
|
+
resource_url = end_point + url_to_sign
|
95
|
+
|
96
|
+
request('put', resource_url, params, body)
|
97
|
+
end
|
98
|
+
|
77
99
|
def sign_request( private_key, url, body, timestamp )
|
78
100
|
|
79
|
-
body_md5 = (
|
101
|
+
body_md5 = (body == "") ? "" : Base64.strict_encode64( Digest::MD5.digest(body.to_json) )
|
80
102
|
signature = url + body_md5 + timestamp.to_s
|
81
103
|
signature = Base64.strict_encode64( Digest::HMAC.digest(signature, private_key , Digest::SHA1) )
|
82
104
|
return signature
|
@@ -92,7 +114,9 @@ module TrustedSearch
|
|
92
114
|
end
|
93
115
|
|
94
116
|
|
95
|
-
def request(method='get', resource_url, params, body
|
117
|
+
def request(method='get', resource_url, params, body)
|
118
|
+
#puts resource_url
|
119
|
+
#puts params.to_json
|
96
120
|
|
97
121
|
timeout = TrustedSearch.api_timeout
|
98
122
|
begin
|
@@ -102,8 +126,10 @@ module TrustedSearch
|
|
102
126
|
response = self.class.get(resource_url, query: params, timeout: timeout)
|
103
127
|
when 'post'
|
104
128
|
response = self.class.post(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
|
129
|
+
when 'put'
|
130
|
+
response = self.class.put(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
|
105
131
|
end
|
106
|
-
|
132
|
+
|
107
133
|
rescue Timeout::Error
|
108
134
|
raise ConnectionError.new("Timeout error (#{timeout}s)")
|
109
135
|
end
|
@@ -112,6 +138,8 @@ module TrustedSearch
|
|
112
138
|
|
113
139
|
|
114
140
|
def process(response)
|
141
|
+
#puts response.to_json
|
142
|
+
|
115
143
|
case response.code
|
116
144
|
when 200, 201, 204
|
117
145
|
APIResponse.new(response)
|
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.
|
4
|
+
version: 1.0.4
|
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-10-
|
11
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -142,6 +142,7 @@ executables: []
|
|
142
142
|
extensions: []
|
143
143
|
extra_rdoc_files: []
|
144
144
|
files:
|
145
|
+
- lib/tasks/test.rb
|
145
146
|
- lib/tasks/v1.rake
|
146
147
|
- lib/trustedsearch/api.rb
|
147
148
|
- lib/trustedsearch/api_resource.rb
|