squarespace_api 0.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 +7 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +79 -0
- data/README.md +3 -0
- data/lib/helper/string.rb +13 -0
- data/lib/helper/uri_component_builder.rb +14 -0
- data/lib/squarespace_api/client.rb +50 -0
- data/lib/squarespace_api/config.rb +27 -0
- data/lib/squarespace_api/connection.rb +110 -0
- data/lib/squarespace_api/paginated_fetch.rb +13 -0
- data/lib/squarespace_api/resource.rb +19 -0
- data/lib/squarespace_api/resource_group.rb +35 -0
- data/lib/squarespace_api/resource_group_actions.rb +70 -0
- data/lib/squarespace_api/resource_groups/inventory.rb +17 -0
- data/lib/squarespace_api/resource_groups/inventory_adjustments.rb +8 -0
- data/lib/squarespace_api/resource_groups/order_fulfillments.rb +8 -0
- data/lib/squarespace_api/resource_groups/orders.rb +18 -0
- data/lib/squarespace_api/resource_groups/product_images.rb +29 -0
- data/lib/squarespace_api/resource_groups/product_variant_images.rb +8 -0
- data/lib/squarespace_api/resource_groups/product_variants.rb +8 -0
- data/lib/squarespace_api/resource_groups/products.rb +19 -0
- data/lib/squarespace_api/resource_groups/profiles.rb +23 -0
- data/lib/squarespace_api/resource_groups/store_pages.rb +14 -0
- data/lib/squarespace_api/resource_groups/tokens.rb +14 -0
- data/lib/squarespace_api/resource_groups/transactions.rb +19 -0
- data/lib/squarespace_api/resource_groups/webhook_subscriptions.rb +22 -0
- data/lib/squarespace_api/resources/website.rb +7 -0
- data/lib/squarespace_api/version.rb +3 -0
- data/lib/squarespace_api.rb +26 -0
- data/spec/fixtures/order_response.json +126 -0
- data/spec/fixtures/orders_response.json +151 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/squarespace_api/client_spec.rb +80 -0
- data/spec/squarespace_api/config_spec.rb +23 -0
- data/spec/squarespace_api/connection_spec.rb +58 -0
- data/spec/squarespace_api/resource_group_actions_spec.rb +71 -0
- data/spec/squarespace_api/resource_groups/orders_spec.rb +18 -0
- data/spec/squarespace_api/resource_groups/product_images_spec.rb +25 -0
- data/spec/squarespace_api/resource_groups/tokens_spec.rb +32 -0
- data/spec/squarespace_api/resource_groups/webhook_subscriptions_spec.rb +29 -0
- data/spec/squarespace_api/resource_spec.rb +19 -0
- data/spec/squarespace_api_spec.rb +21 -0
- data/squarespace_api.gemspec +22 -0
- metadata +196 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class Inventory < ResourceGroup
|
4
|
+
PATH = 'commerce/inventory'.freeze
|
5
|
+
allowed_actions :all, :update, :find_by_ids
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
inventory = where(id: id)
|
9
|
+
inventory ? inventory.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_collection(response)
|
13
|
+
response.body['inventory']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class Orders < ResourceGroup
|
4
|
+
PATH = 'commerce/orders'.freeze
|
5
|
+
allowed_actions :create, :all, :find
|
6
|
+
|
7
|
+
def fulfil(id, params = {})
|
8
|
+
OrderFulfillments.new(connection: connection).create(params.merge(order_id: id))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def parse_collection(response)
|
14
|
+
response.body['result']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class ProductImages < ResourceGroup
|
4
|
+
PATH = 'commerce/products/:product_id/images'.freeze
|
5
|
+
allowed_actions :update, :delete
|
6
|
+
|
7
|
+
def upload(file_path, params = {})
|
8
|
+
parse(
|
9
|
+
connection.upload_file(UriComponentBuidler.construct(resources_path, params), file_path)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def status(id, params)
|
14
|
+
parse(
|
15
|
+
connection
|
16
|
+
.get(UriComponentBuidler.construct(resource_path, params.merge(id: id)) + "/status")
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def order(id, params)
|
21
|
+
params = params.merge(id: id)
|
22
|
+
parse(
|
23
|
+
connection
|
24
|
+
.post(UriComponentBuidler.construct(resource_path, params) + "/order", params: params.to_json)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class Products < ResourceGroup
|
4
|
+
PATH = 'commerce/products'.freeze
|
5
|
+
allowed_actions :create, :all, :create, :delete, :update, :find_by_ids
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
products = where(id: id)
|
9
|
+
products ? products.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def parse_collection(response)
|
15
|
+
response.body['products']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class Profiles < ResourceGroup
|
4
|
+
PATH = 'profiles'.freeze
|
5
|
+
allowed_actions :all, :create
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
profiles = where(id: id)
|
9
|
+
profiles ? profiles.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(params = {})
|
13
|
+
create(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def parse_collection(response)
|
19
|
+
response.body['profiles']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class Transactions < ResourceGroup
|
4
|
+
PATH = 'commerce/transactions'.freeze
|
5
|
+
allowed_actions :all, :find_by_ids
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
transactions = find_by_ids([id])
|
9
|
+
transactions ? transactions.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def parse_collection(response)
|
15
|
+
response.body['documents']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SquarespaceApi
|
2
|
+
module ResourceGroups
|
3
|
+
class WebhookSubscriptions < ResourceGroup
|
4
|
+
PATH = 'webhook_subscriptions'.freeze
|
5
|
+
allowed_actions :all, :create, :update, :find, :delete
|
6
|
+
|
7
|
+
def send_test_notification(id = nil, params)
|
8
|
+
parse(
|
9
|
+
connection
|
10
|
+
.post(UriComponentBuidler.construct(resource_path, id: id) + "/actions/sendTestNotification", params: params.to_json)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def rotate_secret(id)
|
15
|
+
parse(
|
16
|
+
connection
|
17
|
+
.post(UriComponentBuidler.construct(resource_path, id: id) + "/actions/rotateSecret")
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper/string.rb'
|
2
|
+
require 'squarespace_api/config'
|
3
|
+
require 'squarespace_api/version'
|
4
|
+
require 'squarespace_api/resource'
|
5
|
+
require 'squarespace_api/resource_group'
|
6
|
+
require 'squarespace_api/client'
|
7
|
+
require 'squarespace_api/connection'
|
8
|
+
require 'squarespace_api/paginated_fetch'
|
9
|
+
require 'squarespace_api/resource_group_actions'
|
10
|
+
|
11
|
+
# Load all resource_groups, resources
|
12
|
+
Dir.glob("#{File.dirname(__FILE__)}/squarespace_api/resources/*").each { |file| require(file) }
|
13
|
+
Dir.glob("#{File.dirname(__FILE__)}/squarespace_api/resource_groups/*").each { |file| require(file) }
|
14
|
+
|
15
|
+
module SquarespaceApi
|
16
|
+
class << self
|
17
|
+
def configure
|
18
|
+
yield config if block_given?
|
19
|
+
config
|
20
|
+
end
|
21
|
+
|
22
|
+
def config
|
23
|
+
@_config ||= Config.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
{
|
2
|
+
"id": "585d498fdee9f31a60284a37",
|
3
|
+
"orderNumber": "3",
|
4
|
+
"createdOn": "2016-12-23T15:58:07.187Z",
|
5
|
+
"modifiedOn": "2016-12-23T15:58:07.187Z",
|
6
|
+
"channel": "web",
|
7
|
+
"testmode": true,
|
8
|
+
"customerEmail": "foo@example.com",
|
9
|
+
"billingAddress": {
|
10
|
+
"firstName": "Bob",
|
11
|
+
"lastName": "Loblaw",
|
12
|
+
"address1": "459 Broadway",
|
13
|
+
"address2": null,
|
14
|
+
"city": "New York",
|
15
|
+
"state": "NY",
|
16
|
+
"countryCode": "US",
|
17
|
+
"postalCode": "10003",
|
18
|
+
"phone": "5553334444"
|
19
|
+
},
|
20
|
+
"shippingAddress": {
|
21
|
+
"firstName": "Bob",
|
22
|
+
"lastName": "Loblaw",
|
23
|
+
"address1": "459 Broadway",
|
24
|
+
"address2": null,
|
25
|
+
"city": "New York",
|
26
|
+
"state": "NY",
|
27
|
+
"countryCode": "US",
|
28
|
+
"postalCode": "10003",
|
29
|
+
"phone": "5553334444"
|
30
|
+
},
|
31
|
+
"fulfillmentStatus": "PENDING",
|
32
|
+
"lineItems": [ {
|
33
|
+
"id": "585d4975dee9f31a60284a16",
|
34
|
+
"variantId": "88c16ee4-547b-445e-a392-bded9991ae30",
|
35
|
+
"sku": "SQ3381024",
|
36
|
+
"weight": 1.0,
|
37
|
+
"width": 2.0,
|
38
|
+
"length": 3.0,
|
39
|
+
"height": 4.0,
|
40
|
+
"productId": "565c8f3da7c8a3cf71d5fd0a",
|
41
|
+
"productName": "Product",
|
42
|
+
"quantity": 1,
|
43
|
+
"unitPricePaid": {
|
44
|
+
"value": "55.00",
|
45
|
+
"currency": "USD"
|
46
|
+
},
|
47
|
+
"variantOptions": [ {
|
48
|
+
"value": "Large",
|
49
|
+
"optionName": "Size"
|
50
|
+
}, {
|
51
|
+
"value": "Black",
|
52
|
+
"optionName": "Color"
|
53
|
+
} ],
|
54
|
+
"customizations": [ {
|
55
|
+
"label": "Shirt Emblem Location",
|
56
|
+
"value": "Middle Chest"
|
57
|
+
} ],
|
58
|
+
"lineItemType": "PHYSICAL_PRODUCT"
|
59
|
+
} ],
|
60
|
+
"internalNotes": [ {
|
61
|
+
"content": "First note"
|
62
|
+
}, {
|
63
|
+
"content": "Second note"
|
64
|
+
} ],
|
65
|
+
"shippingLines": [ {
|
66
|
+
"method": "Flat Rate",
|
67
|
+
"amount": {
|
68
|
+
"value": "1.00",
|
69
|
+
"currency": "USD"
|
70
|
+
}
|
71
|
+
} ],
|
72
|
+
"discountLines": [ {
|
73
|
+
"description": "Fall Sale",
|
74
|
+
"name": "Fall Sale",
|
75
|
+
"amount": {
|
76
|
+
"value": "1.00",
|
77
|
+
"currency": "USD"
|
78
|
+
},
|
79
|
+
"promoCode": "FALLSALE"
|
80
|
+
} ],
|
81
|
+
"formSubmission": [ {
|
82
|
+
"label": "How did you hear about us?",
|
83
|
+
"value": "Facebook"
|
84
|
+
} ],
|
85
|
+
"fulfillments": [
|
86
|
+
{
|
87
|
+
"shipDate": "2017-01-28T22:19:26.980Z",
|
88
|
+
"carrierName": "USPS",
|
89
|
+
"service": "Priority Mail",
|
90
|
+
"trackingNumber": "9400109699939624119857"
|
91
|
+
}, {
|
92
|
+
"shipDate": "2017-01-29T22:19:26.980Z",
|
93
|
+
"carrierName": "FedEx",
|
94
|
+
"service": "Same-Day Delivery",
|
95
|
+
"trackingNumber": "103932814692659"
|
96
|
+
}
|
97
|
+
],
|
98
|
+
"subtotal": {
|
99
|
+
"value": "55.00",
|
100
|
+
"currency": "USD"
|
101
|
+
},
|
102
|
+
"shippingTotal": {
|
103
|
+
"value": "1.00",
|
104
|
+
"currency": "USD"
|
105
|
+
},
|
106
|
+
"discountTotal": {
|
107
|
+
"value": "1.00",
|
108
|
+
"currency": "USD"
|
109
|
+
},
|
110
|
+
"taxTotal": {
|
111
|
+
"value": "2.70",
|
112
|
+
"currency": "USD"
|
113
|
+
},
|
114
|
+
"refundedTotal": {
|
115
|
+
"value": "0.00",
|
116
|
+
"currency": "USD"
|
117
|
+
},
|
118
|
+
"grandTotal" : {
|
119
|
+
"value" : "57.70",
|
120
|
+
"currency" : "USD"
|
121
|
+
},
|
122
|
+
"channelName": "External Channel",
|
123
|
+
"externalOrderReference": "TEST-123456",
|
124
|
+
"fulfilledOn": "2017-01-30T22:18:37.480Z",
|
125
|
+
"priceTaxInterpretation": "INCLUSIVE"
|
126
|
+
}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
{
|
2
|
+
"result": [
|
3
|
+
{
|
4
|
+
"id": "585d498fdee9f31a60284a37",
|
5
|
+
"orderNumber": "3",
|
6
|
+
"createdOn": "2016-12-23T15:58:07.187Z",
|
7
|
+
"modifiedOn": "2016-12-23T15:58:07.187Z",
|
8
|
+
"channel": "web",
|
9
|
+
"testmode": true,
|
10
|
+
"customerEmail": "foo@example.com",
|
11
|
+
"billingAddress": {
|
12
|
+
"firstName": "Bob",
|
13
|
+
"lastName": "Loblaw",
|
14
|
+
"address1": "459 Broadway",
|
15
|
+
"address2": null,
|
16
|
+
"city": "New York",
|
17
|
+
"state": "NY",
|
18
|
+
"countryCode": "US",
|
19
|
+
"postalCode": "10003",
|
20
|
+
"phone": "5553334444"
|
21
|
+
},
|
22
|
+
"shippingAddress": {
|
23
|
+
"firstName": "Bob",
|
24
|
+
"lastName": "Loblaw",
|
25
|
+
"address1": "459 Broadway",
|
26
|
+
"address2": null,
|
27
|
+
"city": "New York",
|
28
|
+
"state": "NY",
|
29
|
+
"countryCode": "US",
|
30
|
+
"postalCode": "10003",
|
31
|
+
"phone": "5553334444"
|
32
|
+
},
|
33
|
+
"fulfillmentStatus": "PENDING",
|
34
|
+
"lineItems": [
|
35
|
+
{
|
36
|
+
"id": "585d4975dee9f31a60284a16",
|
37
|
+
"variantId": "88c16ee4-547b-445e-a392-bded9991ae30",
|
38
|
+
"sku": "SQ3381024",
|
39
|
+
"weight": 1.0,
|
40
|
+
"width": 2.0,
|
41
|
+
"length": 3.0,
|
42
|
+
"height": 4.0,
|
43
|
+
"productId": "565c8f3da7c8a3cf71d5fd0a",
|
44
|
+
"productName": "Product",
|
45
|
+
"quantity": 1,
|
46
|
+
"unitPricePaid": {
|
47
|
+
"value": "55.00",
|
48
|
+
"currency": "USD"
|
49
|
+
},
|
50
|
+
"variantOptions": [
|
51
|
+
{
|
52
|
+
"value": "Large",
|
53
|
+
"optionName": "Size"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"value": "Black",
|
57
|
+
"optionName": "Color"
|
58
|
+
}
|
59
|
+
],
|
60
|
+
"customizations": [
|
61
|
+
{
|
62
|
+
"label": "Shirt Emblem Location",
|
63
|
+
"value": "Middle Chest"
|
64
|
+
}
|
65
|
+
],
|
66
|
+
"lineItemType": "PHYSICAL_PRODUCT"
|
67
|
+
}
|
68
|
+
],
|
69
|
+
"internalNotes": [
|
70
|
+
{
|
71
|
+
"content": "First note"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"content": "Second note"
|
75
|
+
}
|
76
|
+
],
|
77
|
+
"shippingLines": [
|
78
|
+
{
|
79
|
+
"method": "Flat Rate",
|
80
|
+
"amount": {
|
81
|
+
"value": "1.00",
|
82
|
+
"currency": "USD"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
],
|
86
|
+
"discountLines": [
|
87
|
+
{
|
88
|
+
"description": "Fall Sale",
|
89
|
+
"name": "Fall Sale",
|
90
|
+
"amount": {
|
91
|
+
"value": "1.00",
|
92
|
+
"currency": "USD"
|
93
|
+
},
|
94
|
+
"promoCode": "FALLSALE"
|
95
|
+
}
|
96
|
+
],
|
97
|
+
"formSubmission": [
|
98
|
+
{
|
99
|
+
"label": "How did you hear about us?",
|
100
|
+
"value": "Facebook"
|
101
|
+
}
|
102
|
+
],
|
103
|
+
"fulfillments": [
|
104
|
+
{
|
105
|
+
"shipDate": "2017-01-28T22:19:26.980Z",
|
106
|
+
"carrierName": "USPS",
|
107
|
+
"service": "Priority Mail",
|
108
|
+
"trackingNumber": "9400109699939624119857"
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"shipDate": "2017-01-29T22:19:26.980Z",
|
112
|
+
"carrierName": "FedEx",
|
113
|
+
"service": "Same-Day Delivery",
|
114
|
+
"trackingNumber": "103932814692659"
|
115
|
+
}
|
116
|
+
],
|
117
|
+
"subtotal": {
|
118
|
+
"value": "55.00",
|
119
|
+
"currency": "USD"
|
120
|
+
},
|
121
|
+
"shippingTotal": {
|
122
|
+
"value": "1.00",
|
123
|
+
"currency": "USD"
|
124
|
+
},
|
125
|
+
"discountTotal": {
|
126
|
+
"value": "1.00",
|
127
|
+
"currency": "USD"
|
128
|
+
},
|
129
|
+
"taxTotal": {
|
130
|
+
"value": "2.70",
|
131
|
+
"currency": "USD"
|
132
|
+
},
|
133
|
+
"refundedTotal": {
|
134
|
+
"value": "0.00",
|
135
|
+
"currency": "USD"
|
136
|
+
},
|
137
|
+
"grandTotal": {
|
138
|
+
"value": "57.70",
|
139
|
+
"currency": "USD"
|
140
|
+
},
|
141
|
+
"channelName": "External Channel",
|
142
|
+
"externalOrderReference": "TEST-123456",
|
143
|
+
"fulfilledOn": "2017-01-30T22:18:37.480Z",
|
144
|
+
"priceTaxInterpretation": "INCLUSIVE"
|
145
|
+
}
|
146
|
+
],
|
147
|
+
"pagination": {
|
148
|
+
"hasNextPage": false,
|
149
|
+
"nextPageCursor": "b342f5367c664d3c99aa56f44f95ab0a"
|
150
|
+
}
|
151
|
+
}
|