beyond_api 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +48 -0
- data/GETTING_STARTED.md +0 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +55 -0
- data/LICENSE +19 -0
- data/README.md +51 -0
- data/Rakefile +11 -0
- data/beyond_api.gemspec +31 -0
- data/bin/console +18 -0
- data/bin/setup +8 -0
- data/lib/beyond_api.rb +37 -0
- data/lib/beyond_api/connection.rb +30 -0
- data/lib/beyond_api/ext.rb +43 -0
- data/lib/beyond_api/request.rb +55 -0
- data/lib/beyond_api/resources/base.rb +17 -0
- data/lib/beyond_api/resources/carts.rb +547 -0
- data/lib/beyond_api/resources/categories.rb +168 -0
- data/lib/beyond_api/resources/categories_view.rb +142 -0
- data/lib/beyond_api/resources/checkout_settings.rb +48 -0
- data/lib/beyond_api/resources/newsletter_target.rb +97 -0
- data/lib/beyond_api/resources/order_settings.rb +80 -0
- data/lib/beyond_api/resources/orders.rb +968 -0
- data/lib/beyond_api/resources/payment_methods.rb +192 -0
- data/lib/beyond_api/resources/product_attribute_definitions.rb +109 -0
- data/lib/beyond_api/resources/product_settings.rb +28 -0
- data/lib/beyond_api/resources/products.rb +245 -0
- data/lib/beyond_api/resources/products/attachments.rb +119 -0
- data/lib/beyond_api/resources/products/availability.rb +177 -0
- data/lib/beyond_api/resources/products/custom_attributes.rb +141 -0
- data/lib/beyond_api/resources/products/images.rb +165 -0
- data/lib/beyond_api/resources/products/searches.rb +52 -0
- data/lib/beyond_api/resources/products/variation_properties.rb +87 -0
- data/lib/beyond_api/resources/products_view.rb +158 -0
- data/lib/beyond_api/resources/scopes.rb +31 -0
- data/lib/beyond_api/resources/script_tags.rb +122 -0
- data/lib/beyond_api/resources/shipping_zones.rb +324 -0
- data/lib/beyond_api/resources/shop.rb +561 -0
- data/lib/beyond_api/resources/signers.rb +63 -0
- data/lib/beyond_api/resources/token.rb +41 -0
- data/lib/beyond_api/resources/users.rb +376 -0
- data/lib/beyond_api/resources/variations.rb +145 -0
- data/lib/beyond_api/resources/variations/availability.rb +105 -0
- data/lib/beyond_api/resources/webhook_subscriptions.rb +176 -0
- data/lib/beyond_api/session.rb +121 -0
- data/lib/beyond_api/utils.rb +51 -0
- data/lib/beyond_api/version.rb +3 -0
- data/lib/generators/beyond_api/install_generator.rb +13 -0
- data/lib/generators/templates/beyond_api_initializer.rb +29 -0
- metadata +194 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "beyond_api/utils"
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
module ProductAttachments
|
7
|
+
|
8
|
+
#
|
9
|
+
# A +POST+ request is used to list all the attachments of a product.
|
10
|
+
#
|
11
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/ecb997ce-79c3-4367-9373-058089a313e3/attachments' -i -X POST \
|
12
|
+
# -H 'Content-Type: application/hal+json' \
|
13
|
+
# -H 'Accept: application/hal+json' \
|
14
|
+
# -H 'Authorization: Bearer <Access token>' \
|
15
|
+
# -d '{
|
16
|
+
# "mimeType" : "application/pdf",
|
17
|
+
# "length" : 1,
|
18
|
+
# "label" : "Handbuch",
|
19
|
+
# "dataUri" : "my_document_1.pdf?hash=8a627f655c68f56dfbbf217ab7d5563281225666"
|
20
|
+
# }'
|
21
|
+
#
|
22
|
+
# @beyond_api.scopes +prod:u+
|
23
|
+
#
|
24
|
+
# @param product_id [String] the product UUID
|
25
|
+
# @option params [Integer] :size the page size
|
26
|
+
# @option params [Integer] :page the page number
|
27
|
+
#
|
28
|
+
# @return [OpenStruct]
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# body = {
|
32
|
+
# "mimeType" => "application/pdf",
|
33
|
+
# "length" => 1,
|
34
|
+
# "label" => "Handbuch",
|
35
|
+
# "dataUri" => "my_document_1.pdf?hash=8a627f655c68f56dfbbf217ab7d5563281225666"
|
36
|
+
# }
|
37
|
+
# @attachment = session.products.add_attachment("fd60a63e-c4c0-496d-af49-c4ed224cca2a", body)
|
38
|
+
#
|
39
|
+
def add_attachment(product_id, body)
|
40
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/attachments", body)
|
41
|
+
|
42
|
+
handle_response(response, status)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# A +GET+ request is used to retrieve a single attachment of a product.
|
47
|
+
#
|
48
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/eb11b53a-5017-4ae7-9ba1-c02c12c80b61/attachments/36933722-f13f-4ee2-858c-0835ae0a884e' -i -X GET \
|
49
|
+
# -H 'Content-Type: application/hal+json' \
|
50
|
+
# -H 'Accept: application/hal+json' \
|
51
|
+
# -H 'Authorization: Bearer <Access token>'
|
52
|
+
#
|
53
|
+
# @beyond_api.scopes +prod:r+
|
54
|
+
#
|
55
|
+
# @param product_id [String] the product UUID
|
56
|
+
# @param attachment_id [String] the attachment UUID
|
57
|
+
#
|
58
|
+
# @return [OpenStruct]
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# @attachment = session.products.attachment("fd60a63e-c4c0-496d-af49-c4ed224cca2a", "36933722-f13f-4ee2-858c-0835ae0a884e")
|
62
|
+
#
|
63
|
+
def attachment(product_id, attachment_id)
|
64
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attachments/#{attachment_id}")
|
65
|
+
|
66
|
+
handle_response(response, status)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# A +GET+ request is used to list all the attachments of a product.
|
71
|
+
#
|
72
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/fd60a63e-c4c0-496d-af49-c4ed224cca2a/attachments' -i -X GET \
|
73
|
+
# -H 'Content-Type: application/hal+json' \
|
74
|
+
# -H 'Accept: application/hal+json' \
|
75
|
+
# -H 'Authorization: Bearer <Access token>'
|
76
|
+
#
|
77
|
+
# @beyond_api.scopes +prod:r+
|
78
|
+
#
|
79
|
+
# @param product_id [String] the product UUID
|
80
|
+
# @option params [Integer] :size the page size
|
81
|
+
# @option params [Integer] :page the page number
|
82
|
+
#
|
83
|
+
# @return [OpenStruct]
|
84
|
+
#
|
85
|
+
# @example
|
86
|
+
# @attachments = session.products.attachments("fd60a63e-c4c0-496d-af49-c4ed224cca2a", size: 100, page: 0)
|
87
|
+
#
|
88
|
+
def attachments(product_id, params)
|
89
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attachments", params)
|
90
|
+
|
91
|
+
handle_response(response, status)
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# A +DELETE+ request is used to delete a product attachment
|
96
|
+
#
|
97
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/00add006-beaa-46fe-bb73-f8ebae15082d/attachments/9a44e585-571a-4253-9248-54a4c418c7e2' -i -X DELETE \
|
98
|
+
# -H 'Content-Type: application/hal+json' \
|
99
|
+
# -H 'Accept: application/hal+json' \
|
100
|
+
# -H 'Authorization: Bearer <Access token>'
|
101
|
+
#
|
102
|
+
# @beyond_api.scopes +prod:u+
|
103
|
+
#
|
104
|
+
# @param product_id [String] the product UUID
|
105
|
+
# @param attachment_id [String] the attachment UUID
|
106
|
+
#
|
107
|
+
# @return [true]
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# session.products.delete_attachment("fd60a63e-c4c0-496d-af49-c4ed224cca2a", "36933722-f13f-4ee2-858c-0835ae0a884e")
|
111
|
+
#
|
112
|
+
def delete_attachment(product_id, attachment_id)
|
113
|
+
response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/attachments/#{attachment_id}")
|
114
|
+
|
115
|
+
handle_response(response, status, respond_with_true: true)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "beyond_api/utils"
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
module ProductAvailability
|
7
|
+
|
8
|
+
#
|
9
|
+
# A +POST+ request is used to adjust the available stock of a product.
|
10
|
+
#
|
11
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/685f483e-cdda-40af-8091-d5bc31249409/availability/adjust-available-stock' -i -X POST \
|
12
|
+
# -H 'Content-Type: application/json' \
|
13
|
+
# -H 'Accept: application/hal+json' \
|
14
|
+
# -H 'Authorization: Bearer <Access token>' \
|
15
|
+
# -d '{ "relativeAmount" : -1 }'
|
16
|
+
#
|
17
|
+
# @beyond_api.scopes +prda:u+
|
18
|
+
#
|
19
|
+
# @param product_id [String] the product UUID
|
20
|
+
#
|
21
|
+
# @return [OpenStruct]
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# @availability = session.products.adjust_stock_level(product_id, { relativeAmount => -1 })
|
25
|
+
#
|
26
|
+
def adjust_stock_level(product_id, body)
|
27
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/enable-stock-management", body)
|
28
|
+
|
29
|
+
handle_response(response, status)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# A +GET+ request is used to retrieve the availability of a product.
|
34
|
+
#
|
35
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/fb22d408-00dc-47e3-ae58-e35769bdb428/availability' -i -X GET \
|
36
|
+
# -H 'Content-Type: application/json' \
|
37
|
+
# -H 'Accept: application/hal+json' \
|
38
|
+
# -H 'Authorization: Bearer <Access token>'
|
39
|
+
#
|
40
|
+
# @beyond_api.scopes +prda:r+
|
41
|
+
#
|
42
|
+
# @param product_id [String] the product UUID
|
43
|
+
#
|
44
|
+
# @return [OpenStruct]
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# @availability = session.products.availability("fb22d408-00dc-47e3-ae58-e35769bdb428")
|
48
|
+
#
|
49
|
+
def availability(product_id)
|
50
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/availability")
|
51
|
+
|
52
|
+
handle_response(response, status)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# A +POST+ request is used to disable purchasability for a product.
|
57
|
+
#
|
58
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/6b30255e-650f-475c-b345-e7247f957689/availability/disable-purchasability' -i -X POST \
|
59
|
+
# -H 'Content-Type: application/json' \
|
60
|
+
# -H 'Accept: application/hal+json' \
|
61
|
+
# -H 'Authorization: Bearer <Access token>'
|
62
|
+
#
|
63
|
+
# @beyond_api.scopes +prda:u+
|
64
|
+
#
|
65
|
+
# @param product_id [String] the product UUID
|
66
|
+
#
|
67
|
+
# @return true
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# session.products.disable_purchasability("17e3a92b-6f3b-4415-bd8f-c9c8921a5a73")
|
71
|
+
#
|
72
|
+
def disable_purchasability(product_id)
|
73
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/disable-purchasability")
|
74
|
+
|
75
|
+
handle_response(response, status, respond_with_true: true)
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# A +POST+ request is used to disable stock management for a product or variation product.
|
80
|
+
#
|
81
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/e966cb17-4047-4b82-ade4-33e7f0978c89/availability/disable-stock-management' -i -X POST \
|
82
|
+
# -H 'Content-Type: application/json' \
|
83
|
+
# -H 'Accept: application/hal+json' \
|
84
|
+
# -H 'Authorization: Bearer <Access token>'
|
85
|
+
#
|
86
|
+
# @beyond_api.scopes +prda:u+
|
87
|
+
#
|
88
|
+
# @param product_id [String] the product UUID
|
89
|
+
#
|
90
|
+
# @return true
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# session.products.disable_stock_management("e966cb17-4047-4b82-ade4-33e7f0978c89", respond_with_true: true)
|
94
|
+
#
|
95
|
+
def disable_stock_management(product_id)
|
96
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/disable-stock-management")
|
97
|
+
|
98
|
+
handle_response(response, status, respond_with_true: true)
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# A +POST+ request is used to enable purchasability for a product.
|
103
|
+
#
|
104
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/17e3a92b-6f3b-4415-bd8f-c9c8921a5a73/availability/enable-purchasability' -i -X POST \
|
105
|
+
# -H 'Content-Type: application/json' \
|
106
|
+
# -H 'Accept: application/hal+json' \
|
107
|
+
# -H 'Authorization: Bearer <Access token>'
|
108
|
+
#
|
109
|
+
# @beyond_api.scopes +prda:u+
|
110
|
+
#
|
111
|
+
# @param product_id [String] the product UUID
|
112
|
+
#
|
113
|
+
# @return true
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# session.products.enable_purchasability("17e3a92b-6f3b-4415-bd8f-c9c8921a5a73")
|
117
|
+
#
|
118
|
+
def enable_purchasability(product_id)
|
119
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/enable-purchasability")
|
120
|
+
|
121
|
+
handle_response(response, status, respond_with_true: true)
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# A +POST+ request is used to enable stock management for a product or variation product.
|
126
|
+
#
|
127
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/101fa968-9bb8-4dbe-b166-3add1fc1b35e/availability/enable-stock-management' -i -X POST \
|
128
|
+
# -H 'Content-Type: application/json' \
|
129
|
+
# -H 'Accept: application/hal+json' \
|
130
|
+
# -H 'Authorization: Bearer <Access token>' \
|
131
|
+
# -d '{ "initialAvailableStock" : 100, "stockThreshold" : 2 }'
|
132
|
+
#
|
133
|
+
# @beyond_api.scopes +prda:u+
|
134
|
+
#
|
135
|
+
# @param product_id [String] the product UUID
|
136
|
+
# @param body [Hash] the request body
|
137
|
+
#
|
138
|
+
# @return [OpenStruct]
|
139
|
+
#
|
140
|
+
# @example
|
141
|
+
# body = {
|
142
|
+
# "initialAvailableStock" => 100,
|
143
|
+
# "stockThreshold" => 2
|
144
|
+
# }
|
145
|
+
# @availability = session.products.enable_stock_management("101fa968-9bb8-4dbe-b166-3add1fc1b35e", body)
|
146
|
+
#
|
147
|
+
def enable_stock_management(product_id, body)
|
148
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/enable-stock-management", body)
|
149
|
+
|
150
|
+
handle_response(response, status)
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# A +POST+ request is used to update the reserve stock by changing the +stockThreshold+ value of a product or variation product (incl. all of its variations). Reserve stock refers to an inventory level that indicates that a product needs to be reordered.
|
155
|
+
#
|
156
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/f74b5f57-43cc-4176-97aa-c6eb9fdeb37c/availability/update-stock-threshold' -i -X POST \
|
157
|
+
# -H 'Content-Type: application/json' \
|
158
|
+
# -H 'Accept: application/hal+json' \
|
159
|
+
# -H 'Authorization: Bearer <Access token>' \
|
160
|
+
# -d '{ "stockThreshold" : 5 }'
|
161
|
+
#
|
162
|
+
# @beyond_api.scopes +prda:u+
|
163
|
+
#
|
164
|
+
# @param product_id [String] the product UUID
|
165
|
+
#
|
166
|
+
# @return [OpenStruct]
|
167
|
+
#
|
168
|
+
# @example
|
169
|
+
# session.products.update_reserve_stock("f74b5f57-43cc-4176-97aa-c6eb9fdeb37c", { stockThreshold => 5 })
|
170
|
+
#
|
171
|
+
def update_reserve_stock(product_id, body)
|
172
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/availability/update-stock-threshold", body)
|
173
|
+
|
174
|
+
handle_response(response, status)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "beyond_api/utils"
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
module ProductCustomAttribute
|
7
|
+
|
8
|
+
#
|
9
|
+
# A +POST+ request is used to create a product attribute, which defines the value of a certain {product attribute definition}[http://docs.beyondshop.cloud/#resources-product-attribute-definitions] for a specific {product}[http://docs.beyondshop.cloud/#resources-products].
|
10
|
+
#
|
11
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/0c0e1699-d2a4-44d0-bed9-64b2fa1a7713/attributes' -i -X POST \
|
12
|
+
# -H 'Content-Type: application/json' \
|
13
|
+
# -H 'Authorization: Bearer <Access token>' \
|
14
|
+
# -d '{
|
15
|
+
# "key" : "colour",
|
16
|
+
# "value" : "Yellow"
|
17
|
+
# }'
|
18
|
+
#
|
19
|
+
# @beyond_api.scopes +prat:c+
|
20
|
+
#
|
21
|
+
# @param product_id [String] the product UUID
|
22
|
+
# @param body [Hash] the request body
|
23
|
+
#
|
24
|
+
# @return [OpenStruct]
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# body = {
|
28
|
+
# "key" => "colour",
|
29
|
+
# "value" => "Yellow"
|
30
|
+
# }
|
31
|
+
#
|
32
|
+
# @custom_attribute = session.products.attachment("fd60a63e-c4c0-496d-af49-c4ed224cca2a", body)
|
33
|
+
#
|
34
|
+
def create_custom_attribute(product_id, body)
|
35
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/attributes", body)
|
36
|
+
|
37
|
+
handle_response(response, status)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# A +GET+ request is used to retrieve detailed information about a specific product attribute.
|
42
|
+
#
|
43
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/d389347c-568e-4785-8216-91e4f8850c66/attributes/key' -i -X GET \
|
44
|
+
# -H 'Content-Type: application/json' \
|
45
|
+
# -H 'Authorization: Bearer <Access token>'
|
46
|
+
#
|
47
|
+
# @beyond_api.scopes +prat:r+
|
48
|
+
#
|
49
|
+
# @param product_id [String] the product UUID
|
50
|
+
# @param attribute_name [String] the key of custom attribute
|
51
|
+
#
|
52
|
+
# @return [OpenStruct]
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
#
|
56
|
+
# @custom_attribute = session.products.custom_attribute("fd60a63e-c4c0-496d-af49-c4ed224cca2a", "key")
|
57
|
+
#
|
58
|
+
def custom_attribute(product_id, attribute_name)
|
59
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attributes/#{attribute_name}")
|
60
|
+
|
61
|
+
handle_response(response, status)
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# A +GET+ request is used to retrieve all product attributes for a product.
|
66
|
+
#
|
67
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/57f0ef04-9dac-462f-9dd4-606f7551cc7b/attributes' -i -X GET \
|
68
|
+
# -H 'Content-Type: application/json' \
|
69
|
+
# -H 'Authorization: Bearer <Access token>'
|
70
|
+
#
|
71
|
+
# @beyond_api.scopes +prat:r+
|
72
|
+
#
|
73
|
+
# @param product_id [String] the product UUID
|
74
|
+
#
|
75
|
+
# @return [OpenStruct]
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
#
|
79
|
+
# @custom_attributes = session.products.custom_attributes("fd60a63e-c4c0-496d-af49-c4ed224cca2a")
|
80
|
+
#
|
81
|
+
def custom_attributes(product_id)
|
82
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attributes")
|
83
|
+
|
84
|
+
handle_response(response, status)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# A +DELETE+ request is used to delete a product attribute.
|
89
|
+
#
|
90
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/fec3b6f3-83d0-467a-abc5-d51019e57b51/attributes/farbe' -i -X DELETE \
|
91
|
+
# -H 'Authorization: Bearer <Access token>'
|
92
|
+
#
|
93
|
+
# @beyond_api.scopes +prat:d+
|
94
|
+
#
|
95
|
+
# @param product_id [String] the product UUID
|
96
|
+
# @param attribute_name [String] the key of custom attribute
|
97
|
+
#
|
98
|
+
# @return [OpenStruct]
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
#
|
102
|
+
# session.products.custom_attribute("fd60a63e-c4c0-496d-af49-c4ed224cca2a", "key")
|
103
|
+
#
|
104
|
+
def delete_custom_attribute(product_id, attribute_name)
|
105
|
+
response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/attributes/#{attribute_name}")
|
106
|
+
|
107
|
+
handle_response(response, status, respond_with_true: true)
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# A +PUT+ request is used to update the value of a product attribute. If the specified product attribute doesn’t exist, it will be created with the response as described in {Create product attribute}[http://docs.beyondshop.cloud/#resources-product-attribute-create].
|
112
|
+
#
|
113
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/82ed44e9-664d-47c0-8b07-09adecfdbf20/attributes/key' -i -X PUT \
|
114
|
+
# -H 'Content-Type: application/json' \
|
115
|
+
# -H 'Authorization: Bearer <Access token>' \
|
116
|
+
# -d '{
|
117
|
+
# "value" : "green"
|
118
|
+
# }'
|
119
|
+
#
|
120
|
+
# @beyond_api.scopes +prat:u+
|
121
|
+
#
|
122
|
+
# @param product_id [String] the product UUID
|
123
|
+
# @param attribute_name [String] the key of custom attribute
|
124
|
+
# @param body [Hash] the request body
|
125
|
+
#
|
126
|
+
# @return [OpenStruct]
|
127
|
+
#
|
128
|
+
# @example
|
129
|
+
# body = {
|
130
|
+
# "value" : "green"
|
131
|
+
# }
|
132
|
+
#
|
133
|
+
# @custom_attribute = session.products.update_custom_attribute("fd60a63e-c4c0-496d-af49-c4ed224cca2a", "key", body)
|
134
|
+
#
|
135
|
+
def update_custom_attribute(product_id, attribute_name, body)
|
136
|
+
response, status = BeyondApi::Request.put(@session, "/products/#{product_id}/attributes/#{attribute_name}", body)
|
137
|
+
|
138
|
+
handle_response(response, status)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "beyond_api/utils"
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
module ProductImages
|
7
|
+
|
8
|
+
|
9
|
+
# A +POST+ request is used to create an image and add it to a product.
|
10
|
+
#
|
11
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/7a7d1f18-f760-46a9-b794-dbe5a88c6b44/images' -i -X POST \
|
12
|
+
# -H 'Content-Type: application/hal+json' \
|
13
|
+
# -H 'Accept: application/hal+json' \
|
14
|
+
# -H 'Authorization: Bearer <Access token>' \
|
15
|
+
# -d '{
|
16
|
+
# "dataUri" : "photostore-2.JPG?hash=8a627f655c68f56dfbbf217ab7d5563281225998"
|
17
|
+
# }'
|
18
|
+
#
|
19
|
+
# @beyond_api.scopes +prod:u+
|
20
|
+
#
|
21
|
+
# @param product_id [String] the product UUID
|
22
|
+
# @param image_uri [String] the image url
|
23
|
+
#
|
24
|
+
# @return [OpenStruct]
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# @image = session.products.add_image(product_id, { dataUri: "photostore-2.JPG?hash=8a627f655c68f56dfbbf217ab7d5563281225998" })
|
28
|
+
#
|
29
|
+
def add_image(product_id, image_uri)
|
30
|
+
response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/images", { dataUri: image_uri})
|
31
|
+
|
32
|
+
handle_response(response, status)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# A +DELETE+ request is used to delete a product image.
|
37
|
+
#
|
38
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/8f5e979e-4a47-47ca-84ce-7c026d623974/images/ac318d53-df29-4f43-9356-d91aed8bdb39' -i -X DELETE \
|
39
|
+
# -H 'Content-Type: application/hal+json' \
|
40
|
+
# -H 'Accept: application/hal+json' \
|
41
|
+
# -H 'Authorization: Bearer <Access token>'
|
42
|
+
#
|
43
|
+
# @beyond_api.scopes +prod:u+
|
44
|
+
#
|
45
|
+
# @param product_id [String] the product UUID
|
46
|
+
# @param image_id [String] the image UUID
|
47
|
+
#
|
48
|
+
# @return true
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# session.products.delete_image("8f5e979e-4a47-47ca-84ce-7c026d623974", "ac318d53-df29-4f43-9356-d91aed8bdb39")
|
52
|
+
#
|
53
|
+
def delete_image(product_id, image_id)
|
54
|
+
response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/images/#{image_id}")
|
55
|
+
|
56
|
+
handle_response(response, status, respond_with_true: true)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# A +GET+ request is used to retrieve the images of a product.
|
61
|
+
#
|
62
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/7f32696a-df56-4380-a91b-fffb97f025b4/images' -i -X GET \
|
63
|
+
# -H 'Content-Type: application/hal+json' \
|
64
|
+
# -H 'Accept: application/hal+json' \
|
65
|
+
# -H 'Authorization: Bearer <Access token>'
|
66
|
+
#
|
67
|
+
# @beyond_api.scopes +prod:r+
|
68
|
+
#
|
69
|
+
# @param product_id [String] the product UUID
|
70
|
+
# @option params [Integer] :size the page size
|
71
|
+
# @option params [Integer] :page the page number
|
72
|
+
#
|
73
|
+
# @return [OpenStruct]
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# @products = session.products.images("7f32696a-df56-4380-a91b-fffb97f025b4", { size: 20, page: 0 })
|
77
|
+
#
|
78
|
+
def images(product_id, params = {})
|
79
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/images", params)
|
80
|
+
|
81
|
+
handle_response(response, status)
|
82
|
+
end
|
83
|
+
|
84
|
+
# A +GET+ request is used to retrieve a single image of a product.
|
85
|
+
#
|
86
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/124c5c94-4e62-410a-8599-e5b29dae3491/images/715f5154-9fde-4213-bcab-41ceaaf8b70e' -i -X GET \
|
87
|
+
# -H 'Content-Type: application/hal+json' \
|
88
|
+
# -H 'Accept: application/hal+json' \
|
89
|
+
# -H 'Authorization: Bearer <Access token>'
|
90
|
+
#
|
91
|
+
# @beyond_api.scopes +prod:r+
|
92
|
+
#
|
93
|
+
# @param product_id [String] the product UUID
|
94
|
+
# @param image_id [String] the image UUID
|
95
|
+
#
|
96
|
+
# @return [OpenStruct]
|
97
|
+
#
|
98
|
+
# @example
|
99
|
+
# @image = session.products.image("124c5c94-4e62-410a-8599-e5b29dae3491", "715f5154-9fde-4213-bcab-41ceaaf8b70e")
|
100
|
+
#
|
101
|
+
def image(product_id, image_id)
|
102
|
+
response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/images/#{image_id}")
|
103
|
+
|
104
|
+
handle_response(response, status)
|
105
|
+
end
|
106
|
+
|
107
|
+
# A +PUT+ request is used to assign a product image as the default image. The request contains a single URI of the image to assign.
|
108
|
+
#
|
109
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/150015b9-0b9b-45a2-bcfb-f9006b16a8b8/default-image' -i -X PUT \
|
110
|
+
# -H 'Content-Type: text/uri-list' \
|
111
|
+
# -H 'Accept: application/json' \
|
112
|
+
# -H 'Authorization: Bearer <Access token>' \
|
113
|
+
# -d 'http://localhost/products/images/8ef3591c-d05f-4aa1-acf6-950ba51ec4f7'
|
114
|
+
#
|
115
|
+
# @beyond_api.scopes +prod:u+
|
116
|
+
#
|
117
|
+
# @param product_id [String] the product UUID
|
118
|
+
# @param image_id [String] the image UUID
|
119
|
+
#
|
120
|
+
# @return true
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# session.products.set_image_as_default("150015b9-0b9b-45a2-bcfb-f9006b16a8b8", "8ef3591c-d05f-4aa1-acf6-950ba51ec4f7")
|
124
|
+
#
|
125
|
+
def set_image_as_default(product_id, image_id)
|
126
|
+
response, status = BeyondApi::Request.put(@session, "/products/#{product_id}",
|
127
|
+
"#{@session.api_url}/productsimages/#{image_id}")
|
128
|
+
|
129
|
+
handle_response(response, status, respond_with_true: true)
|
130
|
+
end
|
131
|
+
|
132
|
+
# A +POST+ request is used to upload an image and add it to a product. The body of the request must contain the content of the image.
|
133
|
+
#
|
134
|
+
# $ curl --data-binary '@/home/epages/file.png' 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/images?fileName=file.png' -X POST \
|
135
|
+
# -H 'Content-Type: image/png' \
|
136
|
+
# -H 'Authorization: Bearer <Access token>'
|
137
|
+
#
|
138
|
+
# @beyond_api.scopes +prod:u+
|
139
|
+
#
|
140
|
+
# @param product_id [String] the product UUID
|
141
|
+
# @param image_path [String] the image path
|
142
|
+
# @param image_name [String] the image name
|
143
|
+
#
|
144
|
+
# @return true
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# session.products.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "/home/epages/file.png", "file.png")
|
148
|
+
#
|
149
|
+
def upload_image(product_id, image_path, image_name)
|
150
|
+
content_type = case File.extname(image_path)
|
151
|
+
when ".png"
|
152
|
+
"image/png"
|
153
|
+
when ".jpg", ".jpeg"
|
154
|
+
"image/jpeg"
|
155
|
+
when ".gif"
|
156
|
+
"image/gif"
|
157
|
+
end
|
158
|
+
image_binary = File.binread(image_path)
|
159
|
+
|
160
|
+
response, status = BeyondApi::Request.upload(@session, "/products/#{product_id}/images", image_binary, content_type, { file_name: image_name })
|
161
|
+
|
162
|
+
handle_response(response, status, respond_with_true: true)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|