singleplatform 0.2.2 → 0.3.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 +4 -4
- data/.gitignore +2 -1
- data/.todo +10 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -2
- data/Gemfile.lock +2 -0
- data/README.md +8 -4
- data/Rakefile +9 -0
- data/lib/singleplatform/client.rb +5 -5
- data/lib/singleplatform/error.rb +6 -0
- data/lib/singleplatform/request.rb +4 -9
- data/lib/singleplatform/response.rb +5 -5
- data/lib/singleplatform/version.rb +1 -1
- data/spec/singleplatform/client/locations_spec.rb +1 -0
- data/spec/singleplatform/client_spec.rb +0 -8
- data/spec/singleplatform/response_spec.rb +61 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55bb39070469e1543ee041e5af49da520af9cf13
|
4
|
+
data.tar.gz: 6d1cbf1682277c41d6d24e422327cbcf2dc4a90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c8c90b954cf495ba99841c1d690d828a4e71dd8eab71d59db0793791dddf557e750ea76ec10cde748160b8bb863ceccd67aa543eef96ac1c7698547d8e54c16
|
7
|
+
data.tar.gz: a7eb93dba76d7ced5cf66b8fd121aff5229287243a1cab9b41e134cb714d292e69530e97a101836504f365f994f29efe89515af8c6c8d9ec857050e74c596a92
|
data/.gitignore
CHANGED
data/.todo
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
- handle response status codes where not 200 (status code)
|
2
|
+
- implement /locations/{id}/all endpoint
|
3
|
+
- New response type with iterator (next), which passes path+params to locations_updated_since
|
4
|
+
- be defensive, checking for empty/nil
|
5
|
+
- add test coverage for Response handling
|
6
|
+
- RSpec (nested expecations)
|
7
|
+
- Gemcutter
|
8
|
+
- CodeClimate
|
9
|
+
- TravisCI
|
10
|
+
- License file (MIT)
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -10,6 +10,7 @@ GEM
|
|
10
10
|
httparty (0.14.0)
|
11
11
|
multi_xml (>= 0.5.2)
|
12
12
|
multi_xml (0.5.5)
|
13
|
+
rake (11.2.2)
|
13
14
|
rspec (2.99.0)
|
14
15
|
rspec-core (~> 2.99.0)
|
15
16
|
rspec-expectations (~> 2.99.0)
|
@@ -31,6 +32,7 @@ DEPENDENCIES
|
|
31
32
|
bundler
|
32
33
|
hashie
|
33
34
|
httparty
|
35
|
+
rake
|
34
36
|
rspec
|
35
37
|
webmock
|
36
38
|
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# SinglePlatform API Ruby Client
|
2
2
|
This is a wrapper for accessing SinglePlatform's API. Please see [SinglePlatform's official API documentation](http://docs.singleplatform.com/spv3/) for information on obtaining API credentials.
|
3
3
|
|
4
|
+
[](https://codeclimate.com/github/okayjeff/singleplatform)
|
5
|
+
|
4
6
|
## Installation
|
5
7
|
```
|
6
8
|
gem install singleplatform
|
@@ -46,6 +48,8 @@ This will return a ```Singleplatform::Response``` object. Access the response bo
|
|
46
48
|
|
47
49
|
```ruby
|
48
50
|
response = client.location('nobu') # => #<Singleplatform::Response ... >
|
51
|
+
response.code # => 200
|
52
|
+
response.body # => #<Hashie::Mash ... >
|
49
53
|
response.body.name # => "Nobu"
|
50
54
|
response.body.attributes # => #<Hashie::Mash ... >
|
51
55
|
response.body.attributes.drive_thru # => false
|
@@ -84,9 +88,9 @@ See SinglePlatform's API documentation for the Menu schema with a full list of a
|
|
84
88
|
Many SinglePlatform locations have photos, both at the business and menu-item level. Returns a ```Singleplatform::Response``` object whose body is an Array of menus.
|
85
89
|
|
86
90
|
```ruby
|
87
|
-
response = client.photos_for('
|
88
|
-
response.body.first.type
|
89
|
-
response.body.first.url
|
91
|
+
response = client.photos_for('nobu') # => #<Singleplatform::Response ... >
|
92
|
+
response.body.first.type # => "Product"
|
93
|
+
response.body.first.url # => "http://xyz.cloudfront.net/.../39bf7671bc7d006f4cef72d94eee24aeec7615d2.jpg"
|
90
94
|
```
|
91
95
|
|
92
96
|
#### Fetching all photos updated since a given date
|
@@ -95,5 +99,5 @@ Similarly to ```locations_updated_since```, calling ```photos_updated_since``` r
|
|
95
99
|
|
96
100
|
````ruby
|
97
101
|
response = client.photos_updated_since('2016-09-01') # => #<Singleplatform::Response ... >
|
98
|
-
response
|
102
|
+
response.next
|
99
103
|
````
|
data/Rakefile
CHANGED
@@ -27,6 +27,8 @@ module Singleplatform
|
|
27
27
|
raise Error::MissingCredentialsError if credentials_missing?
|
28
28
|
end
|
29
29
|
|
30
|
+
private
|
31
|
+
|
30
32
|
# Form the complete URL for a given endpoint
|
31
33
|
#
|
32
34
|
# @note Signature must be the last parameter
|
@@ -70,11 +72,9 @@ module Singleplatform
|
|
70
72
|
#
|
71
73
|
# @return [Boolean]
|
72
74
|
def valid_date?(date)
|
73
|
-
|
74
|
-
|
75
|
-
Date.valid_date?(
|
76
|
-
rescue TypeError
|
77
|
-
return false
|
75
|
+
return false if date.index(/[^-0-9]/)
|
76
|
+
y, m, d = date.to_s.split('-')
|
77
|
+
Date.valid_date?(y.to_i, m.to_i, d.to_i)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
data/lib/singleplatform/error.rb
CHANGED
@@ -18,6 +18,12 @@ module Singleplatform
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
class RequestError < Base
|
22
|
+
def initialize(msg = "Unable to transmit HTTP request to SinglePlatform.")
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
21
27
|
class MissingParametersError < Base
|
22
28
|
def initialize(msg = "Your request is missing required parameters.")
|
23
29
|
super
|
@@ -12,13 +12,8 @@ module Singleplatform
|
|
12
12
|
response = HTTParty.get(url)
|
13
13
|
rescue
|
14
14
|
sleep 3
|
15
|
-
if tries -= 1 > 0
|
16
|
-
|
17
|
-
end
|
18
|
-
raise(
|
19
|
-
Error::RequestError,
|
20
|
-
"Unable to transmit request to SinglePlatform. Try again later or contact technical support."
|
21
|
-
)
|
15
|
+
retry if (tries -= 1) > 0
|
16
|
+
raise Error::RequestError
|
22
17
|
else
|
23
18
|
raise(
|
24
19
|
Error::ApiError,
|
@@ -27,8 +22,8 @@ module Singleplatform
|
|
27
22
|
Response.new(
|
28
23
|
code: response.code,
|
29
24
|
body: self.parse_response_body(response.body),
|
30
|
-
# Pass the calling method to the Response object so
|
31
|
-
# method to call when API results are iterable
|
25
|
+
# Pass the calling method to the Response object so Response#next
|
26
|
+
# knows which method to call when API results are iterable.
|
32
27
|
origin: caller_locations(1,1)[0].label
|
33
28
|
)
|
34
29
|
end
|
@@ -12,10 +12,10 @@ module Singleplatform
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# An iterator for retrieving the next page of results from
|
15
|
-
#
|
15
|
+
# API response.
|
16
16
|
#
|
17
17
|
# @note Will only work with Client#locations_updated_since and
|
18
|
-
#
|
18
|
+
# #photos_updated_since at this time.
|
19
19
|
#
|
20
20
|
# @return [Hashie::Mash]
|
21
21
|
def next
|
@@ -26,9 +26,9 @@ module Singleplatform
|
|
26
26
|
client_secret: ENV['CLIENT_SECRET']
|
27
27
|
)
|
28
28
|
new_page = client.public_send(
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
origin.to_sym,
|
30
|
+
params.delete('date'), params
|
31
|
+
)
|
32
32
|
refresh(new_page)
|
33
33
|
end
|
34
34
|
|
@@ -72,6 +72,7 @@ describe 'Singleplatform::Client::Locations' do
|
|
72
72
|
expect { @client.locations_updated_since('2016-9') }.to raise_error(Singleplatform::Error::InvalidDateError)
|
73
73
|
expect { @client.locations_updated_since('2016-9-') }.to raise_error(Singleplatform::Error::InvalidDateError)
|
74
74
|
expect { @client.locations_updated_since('2016-9-31') }.to raise_error(Singleplatform::Error::InvalidDateError)
|
75
|
+
expect { @client.locations_updated_since('2016-9-3w1') }.to raise_error(Singleplatform::Error::InvalidDateError)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
@@ -26,12 +26,4 @@ describe Singleplatform::Client do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
describe ".generate_url" do
|
31
|
-
context "given a valid path and params" do
|
32
|
-
it "correctly generates a URL" do
|
33
|
-
expect(@client.generate_url(@path, @params)).to eql(@url)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
29
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'singleplatform'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Singleplatform::Response do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@creds = {
|
9
|
+
client_id: 'purplespacesuitfrogboots1',
|
10
|
+
client_secret: 'yellowsubmarinesresonatewithmeandmybestbros'
|
11
|
+
}
|
12
|
+
ENV['CLIENT_ID'] = @creds[:client_id]
|
13
|
+
ENV['CLIENT_SECRET'] = @creds[:client_secret]
|
14
|
+
@client = Singleplatform::Client.new(@creds)
|
15
|
+
@updated_since = File.open(Dir.pwd + '/spec/support/fixtures/updated_since.json').read
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".next" do
|
19
|
+
context "when next_page is nil" do
|
20
|
+
it "returns nil" do
|
21
|
+
response = Singleplatform::Response.new(
|
22
|
+
code: 200,
|
23
|
+
body: nil,
|
24
|
+
origin: :locations_updated_since,
|
25
|
+
next_page: nil
|
26
|
+
)
|
27
|
+
expect(response.next.nil?).to be
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when next_page is empty" do
|
32
|
+
it "returns nil" do
|
33
|
+
response = Singleplatform::Response.new(
|
34
|
+
code: 200,
|
35
|
+
body: nil,
|
36
|
+
origin: :locations_updated_since,
|
37
|
+
next_page: ''
|
38
|
+
)
|
39
|
+
expect(response.next.nil?).to be
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when origin = updated_since" do
|
44
|
+
it "returns updated_since results" do
|
45
|
+
response = Singleplatform::Response.new(
|
46
|
+
code: 200,
|
47
|
+
body: @updated_since,
|
48
|
+
origin: :locations_updated_since,
|
49
|
+
next_page: "http://publishing-api.singleplatform.com/locations/updated_since/?date=2016-09-01T00:00:02&limit=2&last_record_id=22494"
|
50
|
+
)
|
51
|
+
stub_request(:get, /publishing-api.singleplatform.com/).
|
52
|
+
with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
53
|
+
to_return(status: 200, body: @updated_since)
|
54
|
+
next_page = response.next
|
55
|
+
expect(next_page).to be_a(Singleplatform::Response)
|
56
|
+
expect(next_page.body.results.size).to eql(3)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleplatform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Gharakhanian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,8 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- ".todo"
|
50
|
+
- ".travis.yml"
|
49
51
|
- Gemfile
|
50
52
|
- Gemfile.lock
|
51
53
|
- LICENSE.txt
|
@@ -65,6 +67,7 @@ files:
|
|
65
67
|
- spec/singleplatform/client/menus_spec.rb
|
66
68
|
- spec/singleplatform/client/photos_spec.rb
|
67
69
|
- spec/singleplatform/client_spec.rb
|
70
|
+
- spec/singleplatform/response_spec.rb
|
68
71
|
- spec/singleplatform_spec.rb
|
69
72
|
- spec/spec_helper.rb
|
70
73
|
- spec/support/fixtures/location.json
|
@@ -91,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
94
|
version: '0'
|
92
95
|
requirements: []
|
93
96
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.5
|
95
98
|
signing_key:
|
96
99
|
specification_version: 4
|
97
100
|
summary: A Ruby client library for accessing the SinglePlatform API.
|