trustedsearch 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE +20 -0
- data/README.md +156 -0
- data/lib/tasks/v1.rake +36 -0
- data/lib/trustedsearch/api.rb +35 -0
- data/lib/trustedsearch/api_resource.rb +127 -0
- data/lib/trustedsearch/api_response.rb +11 -0
- data/lib/trustedsearch/errors/authentication_error.rb +4 -0
- data/lib/trustedsearch/errors/connection_error.rb +4 -0
- data/lib/trustedsearch/errors/error.rb +15 -0
- data/lib/trustedsearch/errors/invalid_request_error.rb +4 -0
- data/lib/trustedsearch/version.rb +3 -0
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yzk3ZDA3OWU1MWY2MjczZjRjN2E5MmZlODNhMDgyZWI0YWM1ZjFhNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmEwYjdmY2NkZjIwMTg2YWRiMzQ2NTc4MWViMmJmYTdiNzExODUyMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmY5YTAzZmQzZGEyYzUxNjRmMGZjZTczMDg4MWE5NmEzNjJhMzllZjgxYTJh
|
10
|
+
NDc0YWUxYWNlYmU4NDYwMDA1YTU2MWYxYzA0NWYyN2IxZGY0ZDNiMTc1MDIz
|
11
|
+
OTM4MjQ5ZDA4ZDVhZjllOTIyYmM2NjMwMWZlOThmN2Q5ZTk1ZWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTg3NThlZGE5MzJlN2ZkOGRiYTI0Y2U1Yjk5ZWFmYjRkMDdjNmY1ZGVhNmEw
|
14
|
+
ZjBjYzg0Y2I1Zjk1YWNkNDE5OTA0MDc3ZGE1NzRmZmYyNTRjZjQ2YWU1Zjdi
|
15
|
+
NTVlM2YxOTQ3MzI1MGZkNzg4ZDNlOGEyMzE2NDZhNzc4NTgyYWU=
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 trustedsearch
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
ruby-trustedsearch
|
2
|
+
==================
|
3
|
+
trustedSEARCH Ruby Gem
|
4
|
+
|
5
|
+
|
6
|
+
Full Documentation: [http://developers.trustedsearch.org](http://developers.trustedsearch.org/)
|
7
|
+
|
8
|
+
## <a id="requirement"></a>Requirements
|
9
|
+
|
10
|
+
[Ruby](http://www.ruby-lang.org/en/downloads/) 1.9 or above.
|
11
|
+
|
12
|
+
|
13
|
+
## <a id="installation"></a>Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'trustedsearch'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install trustedsearch
|
26
|
+
|
27
|
+
Once you have your credentials you can manually run rake tasks to access the the api, or you can integrate direction.
|
28
|
+
|
29
|
+
## <a id="usage"></a>Usage
|
30
|
+
|
31
|
+
The gem is designed to support all existing and future [TRUSTEDSearch API's](http://developers.trustedsearch.org) resources.
|
32
|
+
|
33
|
+
To start using the gem, you need to be given your sandbox and production public & private keys.
|
34
|
+
|
35
|
+
|
36
|
+
### API Examples
|
37
|
+
|
38
|
+
Include the required libs & set your public and private keys
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
|
42
|
+
require "trustedsearch"
|
43
|
+
|
44
|
+
TrustedSearch.public_key = "PUBLIC_KEY"
|
45
|
+
TrustedSearch.private_key = "PRIVATE_KEY"
|
46
|
+
TrustedSearch.environment = "production" #default is 'sandbox'
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
#### Get All Business for all users locations
|
52
|
+
See the [API documentation](http://developers.trustedsearch.org/#/get-business-updates) for a list of parameters for each API resource.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
api = TrustedSearch::V1.new
|
56
|
+
puts api.getBusinessUpdate().data.to_s
|
57
|
+
```
|
58
|
+
|
59
|
+
#### Get Business Updates for single location
|
60
|
+
See the [API documentation](http://developers.trustedsearch.org/#/get-business-updates) for a list of parameters for each API resource.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
api = TrustedSearch::V1.new
|
64
|
+
puts api.getBusinessUpdate(534f95e8-1de1-558f-885c-3962f22c9a28).data.to_s
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Get Business Updates for single location since epoch 1380611103
|
68
|
+
See the [API documentation](http://developers.trustedsearch.org/#/get-business-updates) for a list of parameters for each API resource.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
api = TrustedSearch::V1.new
|
72
|
+
puts api.getBusinessUpdate( 534f95e8-1de1-558f-885c-3962f22c9a28, 1380611103).data.to_s
|
73
|
+
```
|
74
|
+
|
75
|
+
#### Submit New Business Listings
|
76
|
+
|
77
|
+
See the [API documentation](http://developers.trustedsearch.org/#/submitting-a-business) for a list of parameters for each API resource.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
business_data = [
|
81
|
+
{
|
82
|
+
:externalId => 'ABC123',
|
83
|
+
:order => {
|
84
|
+
:onBehalfOf => 'Sample Partner',
|
85
|
+
:packages => [
|
86
|
+
9,10
|
87
|
+
]
|
88
|
+
},
|
89
|
+
:contact => {
|
90
|
+
:firstName => "Albert",
|
91
|
+
:lastName => "Einstein",
|
92
|
+
:email => "albert@trustedsearch.org",
|
93
|
+
:phone => "5555555555"
|
94
|
+
},
|
95
|
+
:business => {
|
96
|
+
:name => "Albert's Relativity Lane",
|
97
|
+
:street => "123 Cherry Tree Lane",
|
98
|
+
:city => "Santa Barbara",
|
99
|
+
:state => "CA",
|
100
|
+
:postalCode => "93041",
|
101
|
+
:phoneTollFree =>"(800) 555-5555",
|
102
|
+
:website => "http://www.relativitylane.com",
|
103
|
+
:email => "info@relativitylane.com",
|
104
|
+
}
|
105
|
+
},
|
106
|
+
{
|
107
|
+
:externalId => 'ABC456',
|
108
|
+
:order => {
|
109
|
+
:onBehalfOf => 'Sample Partner',
|
110
|
+
:packages => [
|
111
|
+
9,10
|
112
|
+
]
|
113
|
+
},
|
114
|
+
:contact => {
|
115
|
+
:firstName => "Albert",
|
116
|
+
:lastName => "Einstein",
|
117
|
+
:email => "albert@trustedsearch.org",
|
118
|
+
:phone => "4444444444"
|
119
|
+
},
|
120
|
+
:business => {
|
121
|
+
:name => "Albert's Relativity Lane",
|
122
|
+
:street => "456 Cherry Tree Lane",
|
123
|
+
:city => "Santa Barbara",
|
124
|
+
:state => "CA",
|
125
|
+
:postalCode => "93041",
|
126
|
+
:phoneTollFree =>"(800) 555-5555",
|
127
|
+
:website => "http://www.relativitylane.com/mc2",
|
128
|
+
:email => "info@relativitylane.com",
|
129
|
+
}
|
130
|
+
}
|
131
|
+
]
|
132
|
+
|
133
|
+
api = TrustedSearch::V1.new
|
134
|
+
response = api.postBusiness(business_data)
|
135
|
+
|
136
|
+
# # Ex: v1/directory-listings/:uuid
|
137
|
+
uuid = response.data[0]["uuid"]
|
138
|
+
```
|
139
|
+
|
140
|
+
### Rake Examples
|
141
|
+
|
142
|
+
Get all udpates in your account
|
143
|
+
|
144
|
+
rake v1:updates[YourPublicKey,YourPrivateKey]
|
145
|
+
|
146
|
+
Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28
|
147
|
+
|
148
|
+
rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]
|
149
|
+
|
150
|
+
Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28 since 1380611103
|
151
|
+
|
152
|
+
rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28,1380611103]
|
153
|
+
|
154
|
+
Submit a new location using JSON data in file relative path "examples/body.json"
|
155
|
+
|
156
|
+
rake v1:submit[YourPublicKey,YourPrivateKey,"examples/body.json"]
|
data/lib/tasks/v1.rake
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
namespace :v1 do
|
2
|
+
task :default do
|
3
|
+
|
4
|
+
end
|
5
|
+
|
6
|
+
desc "Get the directory listings updates. [uuid] if not specified, returns all."
|
7
|
+
task :updates, [:public_key, :private_key, :uuid, :since] do |t, args|
|
8
|
+
TrustedSearch.public_key = args.public_key
|
9
|
+
TrustedSearch.private_key = args.private_key
|
10
|
+
TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
|
11
|
+
uuid = ( args.uuid.nil? ? nil : args.uuid)
|
12
|
+
since = ( args.since.nil? ? nil : args.since)
|
13
|
+
api = TrustedSearch::V1.new
|
14
|
+
puts api.getBusinessUpdate(uuid, since).data.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Submit a listings to be enhanced and created."
|
18
|
+
|
19
|
+
task :submit, [:public_key, :private_key, :file] do |t, args|
|
20
|
+
TrustedSearch.public_key = args.public_key
|
21
|
+
TrustedSearch.private_key = args.private_key
|
22
|
+
TrustedSearch.environment = ( ENV['env'] ? ENV['env'] : 'sandbox')
|
23
|
+
body_file = ( args.file ? args.file : nil)
|
24
|
+
if(body_file.nil?)
|
25
|
+
puts "You must specify a valid body file."
|
26
|
+
next
|
27
|
+
end
|
28
|
+
|
29
|
+
api = TrustedSearch::V1.new
|
30
|
+
file = File.open(body_file, "rb")
|
31
|
+
contents = file.read
|
32
|
+
response = api.postBusiness(JSON.parse(contents))
|
33
|
+
file.close
|
34
|
+
puts response.data
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module TrustedSearch
|
2
|
+
class Api < APIResource
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
module TrustedSearch
|
7
|
+
class V1 < Api
|
8
|
+
|
9
|
+
def base_path
|
10
|
+
if self == APIResource
|
11
|
+
raise NotImplementedError.new("APIResource is an abstract class. You should perform actions on its subclasses (i.e. Publisher)")
|
12
|
+
end
|
13
|
+
"/v1/"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Makes an API request to /directory-listings
|
17
|
+
# If uuid is nil, all are returned.
|
18
|
+
# If since is provided as an integer, only changes made since that time are returned.
|
19
|
+
def getBusinessUpdate(uuid = nil , since = nil)
|
20
|
+
method_url = 'directory-listings' + ( (uuid) ? "/#{uuid}" : '')
|
21
|
+
params = {}
|
22
|
+
if(since)
|
23
|
+
params[:since] = since
|
24
|
+
end
|
25
|
+
|
26
|
+
return self.get(method_url, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
#Submit a single business more multiple business for
|
30
|
+
def postBusiness( data = [] )
|
31
|
+
method_url = 'local-business'
|
32
|
+
return self.post(method_url, {} , data )
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module TrustedSearch
|
2
|
+
class APIResource
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def class_name
|
6
|
+
self.class.name.split('::')[-1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_path
|
10
|
+
if self == APIResource
|
11
|
+
raise NotImplementedError.new("APIResource is an abstract class. You should perform actions on its subclasses (i.e. Publisher)")
|
12
|
+
end
|
13
|
+
""
|
14
|
+
end
|
15
|
+
|
16
|
+
def has_keys
|
17
|
+
unless public_key ||= TrustedSearch.public_key
|
18
|
+
raise AuthenticationError.new(
|
19
|
+
"No public_key key provided. Set your public_key using 'TrustedSearch.public_key = <API-KEY>'. " +
|
20
|
+
"You can retrieve your public_key from a TRUSTEDSearch rep. " +
|
21
|
+
"See http://developers.trustedsearch.org/#/getting-started for details."
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
unless private_key ||= TrustedSearch.private_key
|
26
|
+
raise AuthenticationError.new(
|
27
|
+
"No private_key provided. Set your private_key using 'TrustedSearch.private_key = <API-KEY>'. " +
|
28
|
+
"You can retrieve your private_key from a TRUSTEDSearch rep. " +
|
29
|
+
"See http://developers.trustedsearch.org/#/getting-started for details."
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(api_resource, params = {}, body = {})
|
35
|
+
@resource ||= api_resource
|
36
|
+
has_keys()
|
37
|
+
|
38
|
+
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
39
|
+
|
40
|
+
timestamp = get_time()
|
41
|
+
|
42
|
+
url_to_sign = base_path + api_resource
|
43
|
+
|
44
|
+
params.merge!({
|
45
|
+
apikey: TrustedSearch.public_key,
|
46
|
+
signature: sign_request(TrustedSearch.private_key, url_to_sign, body, timestamp ),
|
47
|
+
timestamp: timestamp
|
48
|
+
})
|
49
|
+
|
50
|
+
resource_url = end_point + url_to_sign
|
51
|
+
request('get', resource_url, params, body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_time
|
55
|
+
return Time.now.utc.to_i
|
56
|
+
end
|
57
|
+
def post(api_resource, params = {}, body = [])
|
58
|
+
@resource ||= api_resource
|
59
|
+
has_keys()
|
60
|
+
|
61
|
+
raise ArgumentError, "Params must be a Hash; got #{params.class} instead" unless params.is_a? Hash
|
62
|
+
|
63
|
+
timestamp = get_time()
|
64
|
+
|
65
|
+
url_to_sign = base_path + api_resource
|
66
|
+
|
67
|
+
params.merge!({
|
68
|
+
apikey: TrustedSearch.public_key,
|
69
|
+
signature: sign_request(TrustedSearch.private_key, url_to_sign, body, timestamp ),
|
70
|
+
timestamp: timestamp
|
71
|
+
})
|
72
|
+
|
73
|
+
resource_url = end_point + url_to_sign
|
74
|
+
request('post', resource_url, params, body)
|
75
|
+
end
|
76
|
+
|
77
|
+
def sign_request( private_key, url, body, timestamp )
|
78
|
+
|
79
|
+
body_md5 = ( body.empty? ) ? '' : Base64.strict_encode64( Digest::MD5.digest(body.to_json) )
|
80
|
+
signature = url + body_md5 + timestamp.to_s
|
81
|
+
signature = Base64.strict_encode64( Digest::HMAC.digest(signature, private_key , Digest::SHA1) )
|
82
|
+
return signature
|
83
|
+
end
|
84
|
+
|
85
|
+
#get the end_point based upon the environment. Default to sandbox.
|
86
|
+
def end_point
|
87
|
+
if(TrustedSearch.environment == 'production')
|
88
|
+
return TrustedSearch.environments[:production][:domain]
|
89
|
+
else
|
90
|
+
return TrustedSearch.environments[:sandbox][:domain]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def request(method='get', resource_url, params, body )
|
96
|
+
|
97
|
+
timeout = TrustedSearch.api_timeout
|
98
|
+
begin
|
99
|
+
|
100
|
+
case method
|
101
|
+
when 'get'
|
102
|
+
response = self.class.get(resource_url, query: params, timeout: timeout)
|
103
|
+
when 'post'
|
104
|
+
response = self.class.post(resource_url, {:query => params, :body => body.to_json, :timeout => timeout } )
|
105
|
+
end
|
106
|
+
|
107
|
+
rescue Timeout::Error
|
108
|
+
raise ConnectionError.new("Timeout error (#{timeout}s)")
|
109
|
+
end
|
110
|
+
process(response)
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def process(response)
|
115
|
+
case response.code
|
116
|
+
when 200, 201, 204
|
117
|
+
APIResponse.new(response)
|
118
|
+
when 400, 404
|
119
|
+
raise InvalidRequestError.new(response.message, response.code)
|
120
|
+
when 401
|
121
|
+
raise AuthenticationError.new(response.message, response.code)
|
122
|
+
else
|
123
|
+
raise Error.new(response.message, response.code)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TrustedSearch
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :message, :code
|
4
|
+
|
5
|
+
def initialize(message = nil, code = nil)
|
6
|
+
@message = message
|
7
|
+
@code = code
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
code_string = code.nil? ? "" : " (Code #{code})"
|
12
|
+
"#{message}#{code_string}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- trustedSEARCH Team
|
@@ -142,7 +142,18 @@ executables: []
|
|
142
142
|
extensions: []
|
143
143
|
extra_rdoc_files: []
|
144
144
|
files:
|
145
|
+
- lib/tasks/v1.rake
|
146
|
+
- lib/trustedsearch/api.rb
|
147
|
+
- lib/trustedsearch/api_resource.rb
|
148
|
+
- lib/trustedsearch/api_response.rb
|
149
|
+
- lib/trustedsearch/errors/authentication_error.rb
|
150
|
+
- lib/trustedsearch/errors/connection_error.rb
|
151
|
+
- lib/trustedsearch/errors/error.rb
|
152
|
+
- lib/trustedsearch/errors/invalid_request_error.rb
|
153
|
+
- lib/trustedsearch/version.rb
|
145
154
|
- lib/trustedsearch.rb
|
155
|
+
- LICENSE
|
156
|
+
- README.md
|
146
157
|
homepage: https://github.com/trustedsearch/ruby-trustedsearch
|
147
158
|
licenses:
|
148
159
|
- MIT
|