beyond_api 0.10.0.pre → 0.13.0.pre

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.
@@ -0,0 +1,252 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ module ShopLocations
7
+
8
+ #
9
+ # A +GET+ request is used to retrieve a list of all locations for the current shop.
10
+ #
11
+ # $ curl 'https://yourshop.api.urn/shop/locations' -i -X GET \
12
+ # -H 'Accept: application/hal+json' \
13
+ # -H 'Authorization: Bearer <Access token>'
14
+ #
15
+ # @beyond_api.scopes +loca:r+
16
+ #
17
+ # @option params [Boolean] :paginated
18
+ # @option params [Integer] :size the page size
19
+ # @option params [Integer] :page the page number
20
+ #
21
+ # @return [OpenStruct]
22
+ #
23
+ # @example
24
+ # @locations = session.shop.locations(size: 100, page: 0)
25
+ #
26
+ def locations(params = {})
27
+ handle_all_request("/shop/locations", :locations, params)
28
+ end
29
+
30
+ #
31
+ # A +POST+ request is used to create a location.
32
+ #
33
+ # $ curl 'https://yourshop.api.urn/shop/locations' -i -X POST \
34
+ # -H 'Content-Type: application/json;charset=UTF-8' \
35
+ # -H 'Accept: application/hal+json' \
36
+ # -H 'Authorization: Bearer <Access token>' \
37
+ # -d '{
38
+ # "languageCode" : "de",
39
+ # "storeCode" : "",
40
+ # "locationName" : "HealthyThings",
41
+ # "primaryPhone" : "01522 3097093",
42
+ # "address" : {
43
+ # "locality" : "Hamburg",
44
+ # "postalCode" : "20253",
45
+ # "regionCode" : "DE",
46
+ # "addressLines" : [ "Pilatuspool 2", "ePages GmbH" ]
47
+ # },
48
+ # "primaryCategory" : {
49
+ # "categoryId" : "gcid:store",
50
+ # "displayName" : "Geschaeft"
51
+ # },
52
+ # "websiteUrl" : "",
53
+ # "regularHours" : {
54
+ # "periods" : [ {
55
+ # "openDay" : "MONDAY",
56
+ # "openTime" : "18:00",
57
+ # "closeDay" : "TUESDAY",
58
+ # "closeTime" : "03:00"
59
+ # }, {
60
+ # "openDay" : "WEDNESDAY",
61
+ # "openTime" : "17:00",
62
+ # "closeDay" : "WEDNESDAY",
63
+ # "closeTime" : "23:00"
64
+ # } ]
65
+ # },
66
+ # "latLng" : {
67
+ # "latitude" : 53.5847424,
68
+ # "longitude" : 9.968901
69
+ # }
70
+ # }'
71
+ #
72
+ # @beyond_api.scopes +loca:c+
73
+ #
74
+ # @param body [Hash] the request body
75
+ #
76
+ # @return [OpenStruct]
77
+ #
78
+ # @example
79
+ # body = {
80
+ # "languageCode" => "de",
81
+ # "storeCode" => "",
82
+ # "locationName" => "HealthyThings",
83
+ # "primaryPhone" => "01522 3097093",
84
+ # "address" => {
85
+ # "locality" => "Hamburg",
86
+ # "postalCode" => "20253",
87
+ # "regionCode" => "DE",
88
+ # "addressLines" => [ "Pilatuspool 2", "ePages GmbH" ]
89
+ # },
90
+ # "primaryCategory" => {
91
+ # "categoryId" => "gcid:store",
92
+ # "displayName" => "Geschaeft"
93
+ # },
94
+ # "websiteUrl" => "",
95
+ # "regularHours" => {
96
+ # "periods" => [ {
97
+ # "openDay" => "MONDAY",
98
+ # "openTime" => "18:00",
99
+ # "closeDay" => "TUESDAY",
100
+ # "closeTime" => "03:00"
101
+ # }, {
102
+ # "openDay" => "WEDNESDAY",
103
+ # "openTime" => "17:00",
104
+ # "closeDay" => "WEDNESDAY",
105
+ # "closeTime" => "23:00"
106
+ # } ]
107
+ # },
108
+ # "latLng" : {
109
+ # "latitude" => 53.5847424,
110
+ # "longitude" => 9.968901
111
+ # }
112
+ # }
113
+ # @location = session.shop.create_location(body)
114
+ #
115
+ def create_location(body)
116
+ response, status = BeyondApi::Request.post(@session, "/shop/locations", body)
117
+
118
+ handle_response(response, status)
119
+ end
120
+
121
+ #
122
+ # A +DELETE+ request is used to delete a location.
123
+ #
124
+ # $ curl 'https://yourshop.api.urn/shop/locations/5bcf7c0a-d130-4cf8-af0c-5e57d4605be0' -i -X DELETE \
125
+ # -H 'Accept: application/hal+json' \
126
+ # -H 'Authorization: Bearer <Access token>'
127
+ #
128
+ # @beyond_api.scopes +loca:d+
129
+ #
130
+ # @param location_id [String] the location UUID
131
+ #
132
+ # @return true
133
+ #
134
+ # @example
135
+ # session.shop.delete_location("f461fb56-1984-4ade-bd4e-007c273cc923")
136
+ #
137
+ def delete_location(location_id)
138
+ response, status = BeyondApi::Request.delete(@session, "/shop/locations/#{location_id}")
139
+
140
+ handle_response(response, status, respond_with_true: true)
141
+ end
142
+
143
+ #
144
+ # A +GET+ request is used to retrieve a particular location by its id.
145
+ #
146
+ # $ curl 'https://yourshop.api.urn/shop/locations/09ca2715-cdf7-4af3-8b22-9ecf39d1e202' -i -X GET \
147
+ # -H 'Accept: application/hal+json' \
148
+ # -H 'Authorization: Bearer <Access token>'
149
+ #
150
+ # @beyond_api.scopes +loca:r+
151
+ #
152
+ # @param location_id [String] the location UUID
153
+ #
154
+ # @return [OpenStruct]
155
+ #
156
+ # @example
157
+ # @location = session.shop.location("27a94b71-9b17-4f06-9596-fbbf4d18021f")
158
+ #
159
+ def location(location_id)
160
+ response, status = BeyondApi::Request.get(@session, "/shop/locations/#{location_id}")
161
+
162
+ handle_response(response, status)
163
+ end
164
+
165
+ #
166
+ # A +PUT+ request is used to update a location.
167
+ #
168
+ # $ curl 'https://yourshop.api.urn/shop/locations/a7a2acfa-0243-4e52-8b56-81cb781ce61d' -i -X PUT \
169
+ # -H 'Content-Type: application/json;charset=UTF-8' \
170
+ # -H 'Accept: application/hal+json' \
171
+ # -H 'Authorization: Bearer <Access token>' \
172
+ # -d '{
173
+ # "languageCode" : "en",
174
+ # "storeCode" : "",
175
+ # "locationName" : "UnhealthyThings",
176
+ # "primaryPhone" : "01234 691997",
177
+ # "address" : {
178
+ # "locality" : "London",
179
+ # "postalCode" : "1",
180
+ # "regionCode" : "GB",
181
+ # "addressLines" : [ "St. James Square", "ePages Ltd" ]
182
+ # },
183
+ # "primaryCategory" : {
184
+ # "categoryId" : "gcid:store",
185
+ # "displayName" : "Shop"
186
+ # },
187
+ # "websiteUrl" : "",
188
+ # "regularHours" : {
189
+ # "periods" : [ {
190
+ # "openDay" : "SATURDAY",
191
+ # "openTime" : "06:00",
192
+ # "closeDay" : "SATURDAY",
193
+ # "closeTime" : "22:00"
194
+ # } ]
195
+ # },
196
+ # "latLng" : {
197
+ # "latitude" : 51.5072,
198
+ # "longitude" : -0.1353
199
+ # }
200
+ # }'
201
+ #
202
+ # @beyond_api.scopes +loca:u+
203
+ #
204
+ # @param location_id [String] the location UUID
205
+ # @param body [Hash] the request body
206
+ #
207
+ # @return [OpenStruct]
208
+ #
209
+ # @example
210
+ # body = {
211
+ # "languageCode" => "de",
212
+ # "storeCode" => "",
213
+ # "locationName" => "HealthyThings",
214
+ # "primaryPhone" => "01522 3097093",
215
+ # "address" => {
216
+ # "locality" => "Hamburg",
217
+ # "postalCode" => "20253",
218
+ # "regionCode" => "DE",
219
+ # "addressLines" => [ "Pilatuspool 2", "ePages GmbH" ]
220
+ # },
221
+ # "primaryCategory" => {
222
+ # "categoryId" => "gcid:store",
223
+ # "displayName" => "Geschaeft"
224
+ # },
225
+ # "websiteUrl" => "",
226
+ # "regularHours" => {
227
+ # "periods" => [ {
228
+ # "openDay" => "MONDAY",
229
+ # "openTime" => "18:00",
230
+ # "closeDay" => "TUESDAY",
231
+ # "closeTime" => "03:00"
232
+ # }, {
233
+ # "openDay" => "WEDNESDAY",
234
+ # "openTime" => "17:00",
235
+ # "closeDay" => "WEDNESDAY",
236
+ # "closeTime" => "23:00"
237
+ # } ]
238
+ # },
239
+ # "latLng" : {
240
+ # "latitude" => 53.5847424,
241
+ # "longitude" => 9.968901
242
+ # }
243
+ # }
244
+ # @location = session.shop.update_location("27a94b71-9b17-4f06-9596-fbbf4d18021f", body)
245
+ #
246
+ def update_location(location_id, body)
247
+ response, status = BeyondApi::Request.put(@session, "/shop/locations/#{location_id}", body)
248
+
249
+ handle_response(response, status)
250
+ end
251
+ end
252
+ end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "beyond_api/utils"
4
+
3
5
  module BeyondApi
4
6
  class Token
5
7
  class InvalidSessionError < StandardError; end
6
8
 
9
+ include BeyondApi::Utils
10
+
7
11
  attr_reader :session
8
12
 
9
13
  def initialize(session)
@@ -44,7 +48,7 @@ module BeyondApi
44
48
  @session.refresh_token = response["refresh_token"]
45
49
  @session
46
50
  else
47
- BeyondApi::Error.new(response)
51
+ handle_error(response, status)
48
52
  end
49
53
  end
50
54
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "beyond_api/utils"
4
- require "beyond_api/resources/variations/images"
5
- require "beyond_api/resources/variations/availability"
6
4
 
7
5
  module BeyondApi
6
+ autoload :Images, "beyond_api/resources/variations/images"
7
+ autoload :Availability, "beyond_api/resources/variations/availability"
8
+
8
9
  class Variations < Base
9
10
  include BeyondApi::VariationImages
10
11
  include BeyondApi::VariationAvailability
@@ -1,28 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "beyond_api/resources/base"
4
- require "beyond_api/resources/carts"
5
- require "beyond_api/resources/categories_view"
6
- require "beyond_api/resources/categories"
7
- require "beyond_api/resources/checkout_settings"
8
- require "beyond_api/resources/customers"
9
- require "beyond_api/resources/newsletter_target"
10
- require "beyond_api/resources/order_settings"
11
- require "beyond_api/resources/orders"
12
- require "beyond_api/resources/payment_methods"
13
- require "beyond_api/resources/product_attribute_definitions"
14
- require "beyond_api/resources/products_view"
15
- require "beyond_api/resources/products"
16
- require "beyond_api/resources/script_tags"
17
- require "beyond_api/resources/shipping_zones"
18
- require "beyond_api/resources/shop"
19
- require "beyond_api/resources/signers"
20
- require "beyond_api/resources/token"
21
- require "beyond_api/resources/users"
22
- require "beyond_api/resources/variations"
23
- require "beyond_api/resources/webhook_subscriptions"
24
-
25
3
  module BeyondApi
4
+ autoload :Base, "beyond_api/resources/base"
5
+ autoload :Carts, "beyond_api/resources/carts"
6
+ autoload :CategoriesView, "beyond_api/resources/categories_view"
7
+ autoload :Categories, "beyond_api/resources/categories"
8
+ autoload :CheckoutSettings, "beyond_api/resources/checkout_settings"
9
+ autoload :Customers, "beyond_api/resources/customers"
10
+ autoload :NewsletterTarget, "beyond_api/resources/newsletter_target"
11
+ autoload :OrderSettings, "beyond_api/resources/order_settings"
12
+ autoload :Orders, "beyond_api/resources/orders"
13
+ autoload :PaymentMethodDefinitions, "beyond_api/resources/payment_method_definitions"
14
+ autoload :PaymentMethods, "beyond_api/resources/payment_methods"
15
+ autoload :ProductAttributeDefinitions, "beyond_api/resources/product_attribute_definitions"
16
+ autoload :ProductsView, "beyond_api/resources/products_view"
17
+ autoload :Products, "beyond_api/resources/products"
18
+ autoload :ScriptTags, "beyond_api/resources/script_tags"
19
+ autoload :ShippingZones, "beyond_api/resources/shipping_zones"
20
+ autoload :Shop, "beyond_api/resources/shop"
21
+ autoload :Signers, "beyond_api/resources/signers"
22
+ autoload :Token, "beyond_api/resources/token"
23
+ autoload :Users, "beyond_api/resources/users"
24
+ autoload :Variations, "beyond_api/resources/variations"
25
+ autoload :WebhookSubscriptions, "beyond_api/resources/webhook_subscriptions"
26
+
26
27
  class Session
27
28
  attr_reader :api_url
28
29
  attr_accessor :access_token, :refresh_token
@@ -65,6 +66,10 @@ module BeyondApi
65
66
  BeyondApi::Orders.new(self)
66
67
  end
67
68
 
69
+ def payment_method_definitions
70
+ BeyondApi::PaymentMethodDefinitions.new(self)
71
+ end
72
+
68
73
  def payment_methods
69
74
  BeyondApi::PaymentMethods.new(self)
70
75
  end
@@ -10,11 +10,16 @@ module BeyondApi
10
10
  response = sanitize_response(response)
11
11
  BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
12
12
  else
13
- BeyondApi.logger.error "[Beyond API] #{response}"
14
- BeyondApi.configuration.raise_error_requests ? raise(response.to_s) : BeyondApi::Error.new(response)
13
+ handle_error(response, status)
15
14
  end
16
15
  end
17
16
 
17
+ def handle_error(response, status)
18
+ BeyondApi.logger.error "[Beyond API] #{status}: #{response}"
19
+ error = BeyondApi::Error.new(response, status)
20
+ BeyondApi.configuration.raise_error_requests ? raise(error) : error
21
+ end
22
+
18
23
  def to_object_struct(data)
19
24
  if data.is_a? Hash
20
25
  return OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
@@ -1,3 +1,3 @@
1
1
  module BeyondApi
2
- VERSION = "0.10.0.pre".freeze
2
+ VERSION = "0.13.0.pre".freeze
3
3
  end
@@ -12,6 +12,21 @@ BeyondApi.setup do |config|
12
12
  # Configure the request timeout in seconds. Default is 5 seconds.
13
13
  # config.timeout = 5.seconds
14
14
 
15
+ # ==> Log configuration
16
+
17
+ # Configure the log level. Must be one of :debug, :info, :warn, :error,
18
+ # :fatal or :unknown. Default is :info.
19
+ #
20
+ # config.log_level = :info
21
+
22
+ # Configure is response headers should be logged. Default is false.
23
+ #
24
+ # config.log_headers = false
25
+
26
+ # Configure is response bodies should be logged. Default is false.
27
+ #
28
+ # config.log_bodies = false
29
+
15
30
  # ==> Response configuration
16
31
  # Configure if :_links should be removed from response. Default is false and
17
32
  # :_links are gonna be part of the response.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.pre
4
+ version: 0.13.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-05-15 00:00:00.000000000 Z
13
+ date: 2020-10-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/beyond_api/connection.rb
136
136
  - lib/beyond_api/error.rb
137
137
  - lib/beyond_api/ext.rb
138
+ - lib/beyond_api/logger.rb
138
139
  - lib/beyond_api/request.rb
139
140
  - lib/beyond_api/resources/base.rb
140
141
  - lib/beyond_api/resources/carts.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/beyond_api/resources/newsletter_target.rb
146
147
  - lib/beyond_api/resources/order_settings.rb
147
148
  - lib/beyond_api/resources/orders.rb
149
+ - lib/beyond_api/resources/payment_method_definitions.rb
148
150
  - lib/beyond_api/resources/payment_methods.rb
149
151
  - lib/beyond_api/resources/product_attribute_definitions.rb
150
152
  - lib/beyond_api/resources/products.rb
@@ -160,6 +162,11 @@ files:
160
162
  - lib/beyond_api/resources/script_tags.rb
161
163
  - lib/beyond_api/resources/shipping_zones.rb
162
164
  - lib/beyond_api/resources/shop.rb
165
+ - lib/beyond_api/resources/shops/address.rb
166
+ - lib/beyond_api/resources/shops/attributes.rb
167
+ - lib/beyond_api/resources/shops/images.rb
168
+ - lib/beyond_api/resources/shops/legals.rb
169
+ - lib/beyond_api/resources/shops/locations.rb
163
170
  - lib/beyond_api/resources/signers.rb
164
171
  - lib/beyond_api/resources/token.rb
165
172
  - lib/beyond_api/resources/users.rb
@@ -190,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
197
  - !ruby/object:Gem::Version
191
198
  version: 1.3.1
192
199
  requirements: []
193
- rubygems_version: 3.0.3
200
+ rubygems_version: 3.1.2
194
201
  signing_key:
195
202
  specification_version: 4
196
203
  summary: Ruby client to access the Beyond API