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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd1f06c3ed79a3dfab23b4c5457efa992f47fa1e
|
4
|
+
data.tar.gz: 1e883c51f91e47e2ad0ea99ed8e436c6be9f04a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cfc1f3653130d3621ca580c6dcc17d02d1b9ccc5467b26c13a622b74cdec9da44eceb618141810f36d835a8dc857ca89665c2eba4f20476cf79726ea498ee0cf
|
7
|
+
data.tar.gz: 0ed4054566485d9aae747f56cc48e2a2d39618c7e67f4330a505d73ac74d928fd64b2e880daf9d00fd00f5d9733a80eb75ba4ff4a71b1e5f6c2ae5a183c9bbda
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
squarespace (0.0.1)
|
5
|
+
faraday
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.1)
|
12
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
13
|
+
coderay (1.1.1)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
docile (1.1.5)
|
18
|
+
faraday (0.12.1)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
hashdiff (0.3.4)
|
21
|
+
json (2.1.0)
|
22
|
+
method_source (0.8.2)
|
23
|
+
multipart-post (2.0.0)
|
24
|
+
pry (0.10.4)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.8.1)
|
27
|
+
slop (~> 3.4)
|
28
|
+
public_suffix (2.0.5)
|
29
|
+
rspec (3.6.0)
|
30
|
+
rspec-core (~> 3.6.0)
|
31
|
+
rspec-expectations (~> 3.6.0)
|
32
|
+
rspec-mocks (~> 3.6.0)
|
33
|
+
rspec-core (3.6.0)
|
34
|
+
rspec-support (~> 3.6.0)
|
35
|
+
rspec-expectations (3.6.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.6.0)
|
38
|
+
rspec-mocks (3.6.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.6.0)
|
41
|
+
rspec-support (3.6.0)
|
42
|
+
safe_yaml (1.0.4)
|
43
|
+
simplecov (0.14.1)
|
44
|
+
docile (~> 1.1.0)
|
45
|
+
json (>= 1.8, < 3)
|
46
|
+
simplecov-html (~> 0.10.0)
|
47
|
+
simplecov-html (0.10.1)
|
48
|
+
slop (3.6.0)
|
49
|
+
timecop (0.9.1)
|
50
|
+
webmock (3.0.1)
|
51
|
+
addressable (>= 2.3.6)
|
52
|
+
crack (>= 0.3.2)
|
53
|
+
hashdiff
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
bundler (~> 1.5)
|
60
|
+
pry
|
61
|
+
rspec
|
62
|
+
simplecov
|
63
|
+
squarespace!
|
64
|
+
timecop
|
65
|
+
webmock
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Gabe Ochoa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# SquareSpace Commerce API
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/squarespace)
|
4
|
+
|
5
|
+
Ruby gem for interacting with the Squarespace API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'squarespace'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install squarespace
|
20
|
+
|
21
|
+
|
22
|
+
# Example usage
|
23
|
+
|
24
|
+
## Initializing the client
|
25
|
+
```
|
26
|
+
client = Squarespace::Client.new(
|
27
|
+
app_name: 'YOUR_APP_NAME'
|
28
|
+
app_secret: 'YOUR_CLIENT_SECRET'
|
29
|
+
)
|
30
|
+
```
|
31
|
+
## Get an order
|
32
|
+
```
|
33
|
+
client.get_order(order_id)
|
34
|
+
```
|
35
|
+
## Get all orders
|
36
|
+
```
|
37
|
+
client.get_orders
|
38
|
+
```
|
39
|
+
## Get all orders with a specified fulfillment status
|
40
|
+
```
|
41
|
+
client.get_orders('pending')
|
42
|
+
client.get_orders('fulfilled')
|
43
|
+
client.get_orders('canceled')
|
44
|
+
```
|
45
|
+
## Fulfill an order
|
46
|
+
```
|
47
|
+
client.fulfill_order(order_id, shipments, send_notification)
|
48
|
+
```
|
49
|
+
|
50
|
+
`shipments` is a hash array in the form of
|
51
|
+
|
52
|
+
```
|
53
|
+
[{
|
54
|
+
tracking_number: 'test_tracking_number1',
|
55
|
+
tracking_url: 'https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=test_tracking_number2',
|
56
|
+
carrier_name: 'USPS',
|
57
|
+
service: 'ground'
|
58
|
+
},{
|
59
|
+
tracking_number: 'test_tracking_number2',
|
60
|
+
tracking_url: nil,
|
61
|
+
carrier_name: 'USPS',
|
62
|
+
service: 'prioritt'
|
63
|
+
}]
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
# Testing
|
68
|
+
|
69
|
+
`bundle exec rspec`
|
70
|
+
|
data/lib/squarespace.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'squarespace/client'
|
2
|
+
require 'squarespace/configuration'
|
3
|
+
require 'squarespace/order'
|
4
|
+
require 'squarespace/version'
|
5
|
+
|
6
|
+
module Squarespace
|
7
|
+
|
8
|
+
def self.configuration
|
9
|
+
@configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure(options = {})
|
13
|
+
@configuration = Configuration.new(options)
|
14
|
+
yield(configuration) if block_given?
|
15
|
+
self.configuration
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'logger'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module Squarespace
|
7
|
+
class Client
|
8
|
+
attr_reader :commerce_url, :logger
|
9
|
+
|
10
|
+
COMMERCE_API_VERSION = 0.1
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@logger = Logger.new(STDOUT)
|
14
|
+
@logger.level = options.delete('log_level') || 'INFO'
|
15
|
+
@config = Squarespace::Config.new(options)
|
16
|
+
@commerce_url = "#{@config.api_url}/#{COMMERCE_API_VERSION}/commerce/orders"
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_order(id)
|
20
|
+
order_response = commerce_request('get', id.to_s)
|
21
|
+
logger.debug("Order response: #{order_response.body}")
|
22
|
+
Order.new(JSON.parse(order_response.body))
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_orders(fulfillment_status = nil)
|
26
|
+
if fulfillment_status.nil?
|
27
|
+
order_response = commerce_request('get')
|
28
|
+
else
|
29
|
+
# binding.pry
|
30
|
+
order_response = commerce_request('get', '', {},
|
31
|
+
{"fulfillmentStatus"=>fulfillment_status.upcase})
|
32
|
+
end
|
33
|
+
|
34
|
+
logger.debug("Order response: #{order_response.body}")
|
35
|
+
Order.new(JSON.parse(order_response.body))
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_pending_orders
|
39
|
+
get_orders('pending')
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_fulfilled_orders
|
43
|
+
get_orders('fulfilled')
|
44
|
+
end
|
45
|
+
|
46
|
+
def fulfill_order(order_id, shipments, send_notification=true)
|
47
|
+
# fulfill_order(string, array[hash], boolean)
|
48
|
+
#
|
49
|
+
# Shipment array example:
|
50
|
+
#
|
51
|
+
# [{
|
52
|
+
# tracking_number: 'test_tracking_number1',
|
53
|
+
# tracking_url: 'https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=test_tracking_number2',
|
54
|
+
# carrier_name: 'USPS',
|
55
|
+
# service: 'ground'
|
56
|
+
# },{
|
57
|
+
# tracking_number: 'test_tracking_number2',
|
58
|
+
# tracking_url: nil,
|
59
|
+
# carrier_name: 'USPS',
|
60
|
+
# service: 'prioritt'
|
61
|
+
# }]
|
62
|
+
|
63
|
+
shipments_arry = []
|
64
|
+
|
65
|
+
shipments.each do |shipment|
|
66
|
+
shipments_arry << {
|
67
|
+
"carrierName": shipment[:carrier_name],
|
68
|
+
"service": shipment[:service],
|
69
|
+
"shipDate": "#{Time.now.utc.iso8601}",
|
70
|
+
"trackingNumber": shipment[:tracking_number],
|
71
|
+
"trackingUrl": shipment[:tracking_url]
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
request_body = {
|
76
|
+
"shipments": shipments_arry,
|
77
|
+
"shouldSendNotification": send_notification
|
78
|
+
}
|
79
|
+
|
80
|
+
commerce_request('post', "#{order_id}/fulfillments", {}, {}, request_body.to_json)
|
81
|
+
end
|
82
|
+
|
83
|
+
def commerce_request(method, route='', headers={}, parameters={}, body=nil)
|
84
|
+
response = connection(@commerce_url).send(method.downcase) do |req|
|
85
|
+
if method.eql?('post')
|
86
|
+
req.headers['Content-Type'] = 'application/json'
|
87
|
+
end
|
88
|
+
parameters.each { |k,v| req.params["#{k}"] = v } if parameters.any?
|
89
|
+
headers.each { |k,v| req.headers["#{k}"] = v } if headers.any?
|
90
|
+
|
91
|
+
# We always need an Authorization header
|
92
|
+
req.headers['Authorization'] = "Bearer #{@config.api_key}"
|
93
|
+
req.url route
|
94
|
+
req.body = body unless body.nil?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def connection(url)
|
101
|
+
Faraday.new(url: url) do |faraday|
|
102
|
+
faraday.request :url_encoded
|
103
|
+
faraday.adapter Faraday.default_adapter
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Squarespace
|
2
|
+
class Config
|
3
|
+
attr_reader :api_url, :api_key, :app_name
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@api_url = options[:api_url] || "https://api.squarespace.com"
|
7
|
+
|
8
|
+
# No default values
|
9
|
+
@app_name = options[:app_name]
|
10
|
+
@api_key = options[:api_key]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"shipments": [
|
3
|
+
{
|
4
|
+
"carrierName": "USPS",
|
5
|
+
"service": "ground",
|
6
|
+
"shipDate": "2017-01-29T22:19:26.980Z",
|
7
|
+
"trackingNumber": "test_tracking_number1",
|
8
|
+
"trackingUrl": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=test_tracking_number2"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"carrierName": "USPS",
|
12
|
+
"service": "priority",
|
13
|
+
"shipDate": "2017-01-29T22:19:26.980Z",
|
14
|
+
"trackingNumber": "test_tracking_number2",
|
15
|
+
"trackingUrl": null
|
16
|
+
}
|
17
|
+
],
|
18
|
+
"shouldSendNotification": true
|
19
|
+
}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
{
|
2
|
+
"pagination": {
|
3
|
+
"hasNextPage": false,
|
4
|
+
"nextPageCursor": null,
|
5
|
+
"nextPageUrl": null
|
6
|
+
},
|
7
|
+
"result": [
|
8
|
+
{
|
9
|
+
"billingAddress": {
|
10
|
+
"address1": "459 Broadway",
|
11
|
+
"address2": null,
|
12
|
+
"city": "New York",
|
13
|
+
"countryCode": "US",
|
14
|
+
"firstName": "Bob",
|
15
|
+
"lastName": "Loblaw",
|
16
|
+
"phone": "5553334444",
|
17
|
+
"postalCode": "10003",
|
18
|
+
"state": "NY"
|
19
|
+
},
|
20
|
+
"createdOn": "2016-12-23T15:58:07.187Z",
|
21
|
+
"customerEmail": "foo@example.com",
|
22
|
+
"discountLines": [
|
23
|
+
{
|
24
|
+
"amount": {
|
25
|
+
"currency": "USD",
|
26
|
+
"value": "1.00"
|
27
|
+
},
|
28
|
+
"description": "Fall Sale",
|
29
|
+
"promoCode": "FALLSALE"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"discountTotal": {
|
33
|
+
"currency": "USD",
|
34
|
+
"value": "1.00"
|
35
|
+
},
|
36
|
+
"formSubmission": [
|
37
|
+
{
|
38
|
+
"label": "How did you hear about us?",
|
39
|
+
"value": "Facebook"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"fulfillmentStatus": "FULFILLED",
|
43
|
+
"fulfillments": [],
|
44
|
+
"grandTotal": {
|
45
|
+
"currency": "USD",
|
46
|
+
"value": "57.70"
|
47
|
+
},
|
48
|
+
"id": "585d498fdee9f31a60284a37",
|
49
|
+
"internalNotes": [
|
50
|
+
{
|
51
|
+
"content": "First note"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"content": "Second note"
|
55
|
+
}
|
56
|
+
],
|
57
|
+
"lineItems": [
|
58
|
+
{
|
59
|
+
"customizations": null,
|
60
|
+
"id": "585d4975dee9f31a60284a16",
|
61
|
+
"imageUrl": "https://static.squarespace.com/universal/commerce/images/brine-32oz-spring-mix-v2.jpg?format=300w",
|
62
|
+
"productId": "565c8f3da7c8a3cf71d5fd0a",
|
63
|
+
"productName": "Product",
|
64
|
+
"quantity": 1,
|
65
|
+
"sku": "SQ3381024",
|
66
|
+
"unitPricePaid": {
|
67
|
+
"currency": "USD",
|
68
|
+
"value": "55.00"
|
69
|
+
},
|
70
|
+
"variantOptions": [
|
71
|
+
{
|
72
|
+
"optionName": "Size",
|
73
|
+
"value": "Large"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"optionName": "Color",
|
77
|
+
"value": "Black"
|
78
|
+
}
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"customizations": null,
|
83
|
+
"id": "585d4975dee9f31a60284a16",
|
84
|
+
"imageUrl": "https://static.squarespace.com/universal/commerce/images/brine-32oz-spring-mix-v2.jpg?format=300w",
|
85
|
+
"productId": "565c8f3da7c8a3cf71d5fd0a",
|
86
|
+
"productName": "Product",
|
87
|
+
"quantity": 1,
|
88
|
+
"sku": "SQ3381024",
|
89
|
+
"unitPricePaid": {
|
90
|
+
"currency": "USD",
|
91
|
+
"value": "55.00"
|
92
|
+
},
|
93
|
+
"variantOptions": [
|
94
|
+
{
|
95
|
+
"optionName": "Size",
|
96
|
+
"value": "Large"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"optionName": "Color",
|
100
|
+
"value": "Black"
|
101
|
+
}
|
102
|
+
]
|
103
|
+
}
|
104
|
+
],
|
105
|
+
"modifiedOn": "2016-12-23T15:58:07.187Z",
|
106
|
+
"orderNumber": "3",
|
107
|
+
"refundedTotal": {
|
108
|
+
"currency": "USD",
|
109
|
+
"value": "0.00"
|
110
|
+
},
|
111
|
+
"shippingAddress": {
|
112
|
+
"address1": "459 Broadway",
|
113
|
+
"address2": null,
|
114
|
+
"city": "New York",
|
115
|
+
"countryCode": "US",
|
116
|
+
"firstName": "Bob",
|
117
|
+
"lastName": "Loblaw",
|
118
|
+
"phone": "5553334444",
|
119
|
+
"postalCode": "10003",
|
120
|
+
"state": "NY"
|
121
|
+
},
|
122
|
+
"shippingLines": [
|
123
|
+
{
|
124
|
+
"amount": {
|
125
|
+
"currency": "USD",
|
126
|
+
"value": "1.00"
|
127
|
+
},
|
128
|
+
"method": "Flat Rate"
|
129
|
+
}
|
130
|
+
],
|
131
|
+
"shippingTotal": {
|
132
|
+
"currency": "USD",
|
133
|
+
"value": "1.00"
|
134
|
+
},
|
135
|
+
"subtotal": {
|
136
|
+
"currency": "USD",
|
137
|
+
"value": "55.00"
|
138
|
+
},
|
139
|
+
"taxTotal": {
|
140
|
+
"currency": "USD",
|
141
|
+
"value": "2.70"
|
142
|
+
},
|
143
|
+
"testmode": true
|
144
|
+
}
|
145
|
+
]
|
146
|
+
}
|