squarespace 0.0.3
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 +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +21 -0
- data/README.md +70 -0
- data/lib/squarespace.rb +17 -0
- data/lib/squarespace/client.rb +107 -0
- data/lib/squarespace/configuration.rb +13 -0
- data/lib/squarespace/order.rb +7 -0
- data/lib/squarespace/version.rb +3 -0
- data/spec/fixtures/fulfill_order_body.json +19 -0
- data/spec/fixtures/fulfilled_orders_response.json +146 -0
- data/spec/fixtures/order_response.json +100 -0
- data/spec/fixtures/orders_response.json +283 -0
- data/spec/fixtures/pending_orders_response.json +283 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/squarespace/client_spec.rb +106 -0
- data/spec/squarespace/configuration_spec.rb +23 -0
- data/spec/squarespace_spec.rb +7 -0
- data/squarespace.gemspec +32 -0
- metadata +184 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'pry'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
7
|
+
require 'squarespace'
|
8
|
+
|
9
|
+
def stub_faraday_request(return_object, method, url='', headers={}, params={}, body=nil)
|
10
|
+
# Add in default headers that Squarespace excepts on every request
|
11
|
+
headers.merge({
|
12
|
+
"Content-Type" => "application/json",
|
13
|
+
"Authorization" => "Bearer test_key"
|
14
|
+
})
|
15
|
+
|
16
|
+
request = instance_double(Faraday::Request,
|
17
|
+
headers: {},
|
18
|
+
params: {},
|
19
|
+
url: nil,
|
20
|
+
body: nil)
|
21
|
+
|
22
|
+
expect(request).to receive(:body=).with(body) unless body.nil?
|
23
|
+
expect(request).to receive(:params) unless params.empty?
|
24
|
+
expect(request).to receive(:headers) unless headers.empty?
|
25
|
+
expect(request).to receive(:url).with(url)
|
26
|
+
expect_any_instance_of(Faraday::Connection).to receive(method.to_sym)
|
27
|
+
.and_yield(request)
|
28
|
+
.and_return(return_object)
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_faraday_response(status, body)
|
32
|
+
if (200..299).include?(status)
|
33
|
+
success = true
|
34
|
+
else
|
35
|
+
success = false
|
36
|
+
end
|
37
|
+
|
38
|
+
stub_response = object_double('response', body: body, status: status, success?: success)
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_order_object
|
42
|
+
stub_faraday_response(200, load_fixture('spec/fixtures/order_response.json'))
|
43
|
+
end
|
44
|
+
|
45
|
+
def stub_orders_object
|
46
|
+
stub_faraday_response(200, load_fixture('spec/fixtures/orders_response.json'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_pending_orders_object
|
50
|
+
stub_faraday_response(200, load_fixture('spec/fixtures/pending_orders_response.json'))
|
51
|
+
end
|
52
|
+
|
53
|
+
def stub_fulfilled_orders_object
|
54
|
+
stub_faraday_response(200, load_fixture('spec/fixtures/fulfilled_orders_response.json'))
|
55
|
+
end
|
56
|
+
|
57
|
+
def stub_fulfill_order_object
|
58
|
+
stub_faraday_response(204, nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_json_fixture(path)
|
62
|
+
File.read(path)
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_fixture(path)
|
66
|
+
File.read(path)
|
67
|
+
end
|
68
|
+
|
69
|
+
RSpec.configure do |config|
|
70
|
+
# rspec-expectations config goes here. You can use an alternate
|
71
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
72
|
+
# assertions if you prefer.
|
73
|
+
config.expect_with :rspec do |expectations|
|
74
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
75
|
+
# and `failure_message` of custom matchers include text for helper methods
|
76
|
+
# defined using `chain`, e.g.:
|
77
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
78
|
+
# # => "be bigger than 2 and smaller than 4"
|
79
|
+
# ...rather than:
|
80
|
+
# # => "be bigger than 2"
|
81
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
82
|
+
end
|
83
|
+
|
84
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
85
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
86
|
+
config.mock_with :rspec do |mocks|
|
87
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
88
|
+
# a real object. This is generally recommended, and will default to
|
89
|
+
# `true` in RSpec 4.
|
90
|
+
mocks.verify_partial_doubles = true
|
91
|
+
end
|
92
|
+
|
93
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
94
|
+
# have no way to turn it off -- the option exists only for backwards
|
95
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
96
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
97
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
98
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
99
|
+
|
100
|
+
config.order = :random
|
101
|
+
config.warnings = true
|
102
|
+
config.color_mode = true
|
103
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
require 'timecop'
|
5
|
+
|
6
|
+
describe Squarespace::Client do
|
7
|
+
|
8
|
+
let(:client) { Squarespace::Client.new(app_name: app_name, api_key: api_key) }
|
9
|
+
let(:private_client) { client.instance_eval { } }
|
10
|
+
let(:api_url) { 'https://api.squarespace.com' }
|
11
|
+
let(:app_name) { 'test_app' }
|
12
|
+
let(:api_key) { 'test_key' }
|
13
|
+
let(:base_commerce_url) { "#{api_url}/0.1/commerce/orders" }
|
14
|
+
let(:order_id) { '585d498fdee9f31a60284a37' }
|
15
|
+
|
16
|
+
context 'For the Squarespace API' do
|
17
|
+
it 'create a connection to squarespace' do
|
18
|
+
test_url = 'https://some_url.com'
|
19
|
+
expect(Faraday).to receive(:new).with(url: 'https://some_url.com')
|
20
|
+
client.send('connection', test_url)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'make request to the sqaurespace api' do
|
24
|
+
test_route = '/some/test/route'
|
25
|
+
test_method = 'GET'
|
26
|
+
expect_any_instance_of(Faraday::Connection).to receive(:get)
|
27
|
+
|
28
|
+
client.commerce_request(test_method, test_route)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'For the Squarespace Commerce API' do
|
33
|
+
it 'have an API version number' do
|
34
|
+
expect(Squarespace::Client::COMMERCE_API_VERSION).to be_a Float
|
35
|
+
expect(Squarespace::Client::COMMERCE_API_VERSION).to be > 0
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'set the commerce api url' do
|
39
|
+
expect(client.commerce_url).to eq base_commerce_url
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'get an order' do
|
43
|
+
stub_faraday_request(stub_order_object, 'get', order_id)
|
44
|
+
|
45
|
+
order = client.get_order(order_id)
|
46
|
+
expect(order.lineItems.count).to be 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'get a batch of orders' do
|
50
|
+
stub_faraday_request(stub_orders_object, 'get')
|
51
|
+
|
52
|
+
orders = client.get_orders
|
53
|
+
expect(orders.result.count).to be 2
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'get a batch of orders that is status PENDING' do
|
57
|
+
stub_faraday_request(stub_pending_orders_object, 'get',
|
58
|
+
'', {}, {"fulfillmentStatus"=>"PENDING"})
|
59
|
+
|
60
|
+
orders = client.get_pending_orders
|
61
|
+
expect(orders.result.count).to be 2
|
62
|
+
orders.each do |order|
|
63
|
+
expect(order.fulfillmentStatus).to eq 'PENDING'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'get a batch of orders that is status FULFILLED' do
|
68
|
+
stub_faraday_request(stub_pending_orders_object, 'get',
|
69
|
+
'', {}, {"fulfillmentStatus"=>"FULFILLED"})
|
70
|
+
|
71
|
+
orders = client.get_fulfilled_orders
|
72
|
+
expect(orders.result.count).to be 2
|
73
|
+
orders.each do |order|
|
74
|
+
expect(order.fulfillmentStatus).to eq 'FULFILLED'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'fulfill an order' do
|
79
|
+
Timecop.freeze
|
80
|
+
body_fixture = JSON.parse(load_fixture('spec/fixtures/fulfill_order_body.json'), symbolize_names: true)
|
81
|
+
body_fixture[:shipments].each do |s|
|
82
|
+
s[:shipDate] = Time.now.utc.iso8601
|
83
|
+
end
|
84
|
+
|
85
|
+
shipments = [{
|
86
|
+
tracking_number: 'test_tracking_number1',
|
87
|
+
tracking_url: 'https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=test_tracking_number2',
|
88
|
+
carrier_name: 'USPS',
|
89
|
+
service: 'ground'
|
90
|
+
},{
|
91
|
+
tracking_number: 'test_tracking_number2',
|
92
|
+
tracking_url: nil,
|
93
|
+
carrier_name: 'USPS',
|
94
|
+
service: 'priority'
|
95
|
+
}]
|
96
|
+
send_notification = true
|
97
|
+
|
98
|
+
stub_faraday_request(stub_fulfill_order_object,
|
99
|
+
'post', "#{order_id}/fulfillments",
|
100
|
+
{"Content-Type"=>"application/json","Authorization"=>"Bearer test_key"},
|
101
|
+
{}, body_fixture.to_json)
|
102
|
+
|
103
|
+
client.fulfill_order(order_id, shipments, send_notification)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Squarespace::Config do
|
4
|
+
context 'the confgiuration' do
|
5
|
+
let(:config) { Squarespace::Config.new(app_name: 'test_app', api_key: 'test_key') }
|
6
|
+
|
7
|
+
it 'is present' do
|
8
|
+
expect(config.nil?).to be false
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has an api_url' do
|
12
|
+
expect(config.api_url).to eq('https://api.squarespace.com')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has an api_key' do
|
16
|
+
expect(config.api_key).to eq('test_key')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has an app_name' do
|
20
|
+
expect(config.app_name).to eq('test_app')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/squarespace.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'squarespace/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "squarespace"
|
8
|
+
spec.version = Squarespace::VERSION
|
9
|
+
spec.summary = %q{Ruby interface to the Squarespace API}
|
10
|
+
spec.description = %q{Ruby interface to the Squarespace API}
|
11
|
+
spec.homepage = "https://github.com/gabe-ochoa/squarespace"
|
12
|
+
spec.author = 'Gabe Ochoa'
|
13
|
+
spec.email = 'gabeochoa@gmail.com'
|
14
|
+
spec.homepage = 'http://rubygems.org/gems/squarespace'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "timecop"
|
28
|
+
|
29
|
+
spec.add_dependency "faraday"
|
30
|
+
spec.add_dependency "json"
|
31
|
+
spec.required_ruby_version = '~> 2.4.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: squarespace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabe Ochoa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Ruby interface to the Squarespace API
|
126
|
+
email: gabeochoa@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- ".gitignore"
|
132
|
+
- Gemfile
|
133
|
+
- Gemfile.lock
|
134
|
+
- LICENSE
|
135
|
+
- README.md
|
136
|
+
- lib/squarespace.rb
|
137
|
+
- lib/squarespace/client.rb
|
138
|
+
- lib/squarespace/configuration.rb
|
139
|
+
- lib/squarespace/order.rb
|
140
|
+
- lib/squarespace/version.rb
|
141
|
+
- spec/fixtures/fulfill_order_body.json
|
142
|
+
- spec/fixtures/fulfilled_orders_response.json
|
143
|
+
- spec/fixtures/order_response.json
|
144
|
+
- spec/fixtures/orders_response.json
|
145
|
+
- spec/fixtures/pending_orders_response.json
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/squarespace/client_spec.rb
|
148
|
+
- spec/squarespace/configuration_spec.rb
|
149
|
+
- spec/squarespace_spec.rb
|
150
|
+
- squarespace.gemspec
|
151
|
+
homepage: http://rubygems.org/gems/squarespace
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - "~>"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 2.4.0
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.5.2
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Ruby interface to the Squarespace API
|
175
|
+
test_files:
|
176
|
+
- spec/fixtures/fulfill_order_body.json
|
177
|
+
- spec/fixtures/fulfilled_orders_response.json
|
178
|
+
- spec/fixtures/order_response.json
|
179
|
+
- spec/fixtures/orders_response.json
|
180
|
+
- spec/fixtures/pending_orders_response.json
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
- spec/squarespace/client_spec.rb
|
183
|
+
- spec/squarespace/configuration_spec.rb
|
184
|
+
- spec/squarespace_spec.rb
|