beyond_api 0.11.1.pre → 0.15.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e68b42556a0a1c1038d1c234fba9910fc847c0250ed3c2426091996ffe5c703
4
- data.tar.gz: d2507537ae0cfee8e216322dc5a74d66f73b31c7a4279f4b043e8f67ff43e04e
3
+ metadata.gz: 438360193bc7064cbd6591e9dc088aeb81f162aac26bff0ac1f891f45b5b9993
4
+ data.tar.gz: 57f358035cc7aa0ee5ee0795eecb3f887b5f534d470342348d70c6e6c6f1ac48
5
5
  SHA512:
6
- metadata.gz: bebea8aaf4fb068465618d308c0fb7439272853f49b6e964acc8e5c685057541a182d13619da7f431c1fbc9a3aac5f5310ff0f279633ea51cbd07df80dc2aebf
7
- data.tar.gz: 5a237fd7ffdde5902f8a198dd80f60a3e668ca80440d5929981ecd7f2154ca397cd11f3017e6572d56ef65394157e6df591bfc9794ba311376455c37e1af780c
6
+ metadata.gz: 284505c3dc6af706bd3851fe62c885ce2aec79c76a997b2c07f20a23d5745c3a7d16c337177de9579b25c0fe9440b2b9e04f5cfdd2ec377362effb2a98df7b0b
7
+ data.tar.gz: eb9168f92793a47673646fcb8ac36bd6c5103596620a1003a143242a938ceba156429fe3760f41672c705a23f367ad2be40d6607c0f112ecdf16be1ead96a0b1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,47 @@
1
+ ### v0.15.0.pre
2
+
3
+ * features
4
+ * Add pickup options methods
5
+ * `PickupOptions#all`
6
+ * `PickupOptions#create`
7
+
8
+ ### v0.14.0.pre
9
+
10
+ * deprecations
11
+ * Remove `Products#assign_variation_images_differentiator`
12
+
13
+ * features
14
+ * Add `Products#assign_variation_attribute_as_differentiator`
15
+
16
+ ### v0.13.0.pre
17
+
18
+ * features
19
+ * Add payment method definitions methods
20
+ * `PaymentMethodDefinitions#all`
21
+ * `PaymentMethodDefinitions#create`
22
+ * `PaymentMethodDefinitions#delete`
23
+ * `PaymentMethodDefinitions#find`
24
+ * `PaymentMethodDefinitions#update`
25
+ * Add possibility to log request `headers` and `bodies`
26
+
27
+ ### v0.12.1.pre
28
+
29
+ * bug-fixes
30
+ * Fix camelize function for hashes containing arrays
31
+
32
+ ### v0.12.0.pre
33
+
34
+ * features
35
+ * Add locations methods
36
+ * `Locations#all`
37
+ * `Locations#create`
38
+ * `Locations#delete`
39
+ * `Locations#find`
40
+ * `Locations#update`
41
+
42
+ * enhancements
43
+ * Use `autoload` instead of `require`
44
+
1
45
  ### v0.11.1.pre
2
46
 
3
47
  * bug-fixes
data/Gemfile.lock CHANGED
@@ -1,42 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.11.1.pre)
4
+ beyond_api (0.15.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- coderay (1.1.2)
11
- concurrent-ruby (1.1.5)
12
- diff-lcs (1.3)
13
- dotenv (2.7.5)
14
- faker (2.4.0)
15
- i18n (~> 1.6.0)
16
- faraday (0.17.3)
10
+ coderay (1.1.3)
11
+ concurrent-ruby (1.1.9)
12
+ diff-lcs (1.4.4)
13
+ dotenv (2.7.6)
14
+ faker (2.18.0)
15
+ i18n (>= 1.6, < 2)
16
+ faraday (0.17.4)
17
17
  multipart-post (>= 1.2, < 3)
18
- i18n (1.6.0)
18
+ i18n (1.8.10)
19
19
  concurrent-ruby (~> 1.0)
20
- method_source (0.9.2)
20
+ method_source (1.0.0)
21
21
  multipart-post (2.1.1)
22
- pry (0.12.2)
23
- coderay (~> 1.1.0)
24
- method_source (~> 0.9.0)
22
+ pry (0.14.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
25
  rake (10.5.0)
26
- rspec (3.8.0)
27
- rspec-core (~> 3.8.0)
28
- rspec-expectations (~> 3.8.0)
29
- rspec-mocks (~> 3.8.0)
30
- rspec-core (3.8.2)
31
- rspec-support (~> 3.8.0)
32
- rspec-expectations (3.8.4)
26
+ rspec (3.10.0)
27
+ rspec-core (~> 3.10.0)
28
+ rspec-expectations (~> 3.10.0)
29
+ rspec-mocks (~> 3.10.0)
30
+ rspec-core (3.10.1)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.1)
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-mocks (3.8.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.2)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-support (3.8.2)
39
- yard (0.9.20)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.2)
39
+ yard (0.9.26)
40
40
 
41
41
  PLATFORMS
42
42
  ruby
data/lib/beyond_api.rb CHANGED
@@ -1,23 +1,18 @@
1
1
  require "beyond_api/version"
2
2
 
3
- require "beyond_api/connection"
4
- require "beyond_api/request"
5
- require "beyond_api/session"
6
- require "beyond_api/error"
3
+ require "logger"
7
4
 
8
5
  require "beyond_api/ext"
9
6
  require "beyond_api/utils"
10
7
 
11
- require "logger"
12
-
13
8
  module BeyondApi
14
- def self.logger
15
- @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
16
- end
9
+ autoload :Connection, "beyond_api/connection"
10
+ autoload :Error, "beyond_api/error"
11
+ autoload :Logger, "beyond_api/logger"
12
+ autoload :Request, "beyond_api/request"
13
+ autoload :Session, "beyond_api/session"
17
14
 
18
- def self.logger=(logger)
19
- @@logger = logger
20
- end
15
+ extend BeyondApi::Logger
21
16
 
22
17
  class << self
23
18
  attr_accessor :configuration
@@ -31,7 +26,8 @@ module BeyondApi
31
26
 
32
27
  class Configuration
33
28
  attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
34
- :remove_response_key_underscores, :object_struct_responses, :raise_error_requests
29
+ :remove_response_key_underscores, :object_struct_responses, :raise_error_requests,
30
+ :log_headers, :log_bodies, :log_level
35
31
 
36
32
  def initialize
37
33
  @client_id = nil
@@ -42,6 +38,10 @@ module BeyondApi
42
38
  @remove_response_key_underscores = false
43
39
  @object_struct_responses = false
44
40
  @raise_error_requests = false
41
+
42
+ @log_level = :info
43
+ @log_headers = false
44
+ @log_bodies = false
45
45
  end
46
46
  end
47
47
  end
@@ -4,10 +4,15 @@ require 'faraday'
4
4
 
5
5
  module BeyondApi
6
6
  class Connection
7
+ LOGGER = ::BeyondApi.logger
8
+ LOGGER.level = Kernel.const_get("::Logger::#{BeyondApi.configuration.log_level.to_s.upcase}")
9
+
7
10
  def self.default
8
11
  Faraday.new(ssl: { verify: true }) do |faraday|
9
12
  faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
10
13
  faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
14
+ faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
15
+ bodies: BeyondApi.configuration.log_bodies }
11
16
  faraday.headers['Accept'] = 'application/json'
12
17
  faraday.headers['Content-Type'] = 'application/json'
13
18
  faraday.request(:multipart)
@@ -20,6 +25,8 @@ module BeyondApi
20
25
  Faraday.new(ssl: { verify: true }) do |faraday|
21
26
  faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
22
27
  faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
28
+ faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
29
+ bodies: BeyondApi.configuration.log_bodies }
23
30
  faraday.headers['Accept'] = 'application/json'
24
31
  faraday.adapter(:net_http)
25
32
  faraday.basic_auth(BeyondApi.configuration.client_id,
@@ -4,7 +4,14 @@ class Hash
4
4
  def deep_transform_keys(&block)
5
5
  result = {}
6
6
  each do |key, value|
7
- result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
7
+ result[yield(key)] = case value
8
+ when Hash
9
+ value.deep_transform_keys(&block)
10
+ when Array
11
+ value.camelize_keys
12
+ else
13
+ value
14
+ end
8
15
  end
9
16
  result
10
17
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ module Logger
5
+ def logger
6
+ @@logger ||= defined?(Rails) ? ::Rails.logger : ::Logger.new($stdout)
7
+ end
8
+
9
+ def logger=(logger)
10
+ @@logger = logger
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class PaymentMethodDefinitions < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +POST+ request is used to create a payment method definition on system level.
11
+ #
12
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions' -i -X POST \
13
+ # -H 'Content-Type: application/json' \
14
+ # -H 'Accept: application/hal+json' \
15
+ # -H 'Authorization: Bearer <Access token>' \
16
+ # -d '{
17
+ # "name": "credit-card",
18
+ # "referralUriTemplate": "https://example.com/merchants",
19
+ # "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
20
+ # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
21
+ # "createPaymentUriTemplate": "https://example.com/payments",
22
+ # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
23
+ # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
24
+ # "sandbox": "true",
25
+ # "workflow": "PAYMENT_ON_BUY",
26
+ # "captureWorkflow": "CAPTURE_ON_ORDER",
27
+ # "refund": "NO_REFUND",
28
+ # "logos": [{
29
+ # "setName" : "official",
30
+ # "variant" : "STOREFRONT",
31
+ # "uri" : "https://example.com/static/storefront.png"
32
+ # }],
33
+ # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
34
+ # "en-US" : "Allow your customers to pay by credit card."
35
+ # },
36
+ # "officialDescription": {
37
+ # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
38
+ # "en-US" : "Allow your customers to pay by credit card."
39
+ # },
40
+ # "defaultName": {
41
+ # "de-DE" : "Kreditkarte",
42
+ # "en-US" : "Credit card"
43
+ # },
44
+ # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
45
+ #
46
+ # @beyond_api.scopes +paym:m+
47
+ #
48
+ # @param body [Hash] the request body
49
+ #
50
+ # @return [OpenStruct]
51
+ #
52
+ # @example
53
+ # @payment_method_definitions = session.payment_method_definitions.create(body)
54
+ #
55
+ def create(body)
56
+ response, status = BeyondApi::Request.post(@session, "/payment-method-definitions", body)
57
+
58
+ handle_response(response, status)
59
+ end
60
+
61
+ #
62
+ # A +GET+ request is used to list all payment method definitions on system level.
63
+ #
64
+ # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions' -i -X GET \
65
+ # -H 'Accept: application/hal+json' \
66
+ # -H 'Authorization: Bearer <Access token>'
67
+ #
68
+ # @beyond_api.scopes +paym:m+
69
+ #
70
+ # @option params [Boolean] :paginated
71
+ # @option params [Integer] :size the page size
72
+ # @option params [Integer] :page the page number
73
+ #
74
+ # @return [OpenStruct]
75
+ #
76
+ # @example
77
+ # @payment_method_definitions = session.payment_method_definitions.all(size: 100, page: 0)
78
+ #
79
+ def all(params = {})
80
+ handle_all_request("/payment-method-definitions", :payment_method_definitions, params)
81
+ end
82
+
83
+ #
84
+ # A +GET+ request is used to deactivate a payment method.
85
+ #
86
+ # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X GET \
87
+ # -H 'Accept: application/hal+json' \
88
+ # -H 'Authorization: Bearer <Access token>'
89
+ #
90
+ # @beyond_api.scopes +pymt:u+
91
+ #
92
+ # @param payment_method_definition_id [String] the payment method definition UUID
93
+ #
94
+ # @return [OpenStruct]
95
+ #
96
+ # @example
97
+ # @payment_method_definition = session.payment_methods.find("credit-card")
98
+ #
99
+ def find(payment_method_definition_id)
100
+ response, status = BeyondApi::Request.get(@session, "/payment-method-definitions/#{payment_method_definition_id}")
101
+
102
+ handle_response(response, status)
103
+ end
104
+
105
+ #
106
+ # A +PUT+ request is used to update a payment method definition on system level.
107
+ #
108
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X PUT \
109
+ # -H 'Content-Type: application/json' \
110
+ # -H 'Accept: application/hal+json' \
111
+ # -H 'Authorization: Bearer <Access token>' \
112
+ # -d '{
113
+ # "name": "credit-card-updated",
114
+ # "referralUriTemplate": "https://example.com/merchants",
115
+ # "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
116
+ # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
117
+ # "createPaymentUriTemplate": "https://example.com/payments",
118
+ # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
119
+ # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
120
+ # "workflow": "PAYMENT_ON_SELECTION",
121
+ # "captureWorkflow": "CAPTURE_ON_DEMAND",
122
+ # "refund": "NO_REFUND",
123
+ # "logos": [{
124
+ # "setName" : "official",
125
+ # "variant" : "STOREFRONT",
126
+ # "uri" : "https://example.com/static/storefront.png"
127
+ # }],
128
+ # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
129
+ # "en-US" : "Allow your customers to pay by credit card."
130
+ # },
131
+ # "officialDescription": {
132
+ # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
133
+ # "en-US" : "Allow your customers to pay by credit card."
134
+ # },
135
+ # "defaultName": {
136
+ # "de-DE" : "Kreditkarte",
137
+ # "en-US" : "Credit card"
138
+ # },
139
+ # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
140
+ #
141
+ # @beyond_api.scopes +paym:m+
142
+ #
143
+ # @param payment_method_definition_id [String] the payment method definition UUID
144
+ # @param body [Hash] the request body
145
+ #
146
+ # @return [OpenStruct]
147
+ #
148
+ # @example
149
+ # @payment_method_definition = session.payment_method_definitions.update("credit_card", body)
150
+ #
151
+ def update(payment_method_definition_id, body)
152
+ response, status = BeyondApi::Request.put(@session, "/payment-method-definitions/#{payment_method_definition_id}")
153
+
154
+ handle_response(response, status)
155
+ end
156
+
157
+ #
158
+ # A +DELETE+ request is used to delete a payment method definition on system level.
159
+ #
160
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X DELETE \
161
+ # -H 'Accept: application/hal+json' \
162
+ # -H 'Authorization: Bearer <Access token>'
163
+ #
164
+ # @return true
165
+ #
166
+ # @example
167
+ # session.payment_method_definitions.delete("credit-card")
168
+ #
169
+ def delete(payment_method_definition_id)
170
+ response, status = BeyondApi::Request.delete(@session, "/payment-method-definitions/#{payment_method_definition_id}", body)
171
+
172
+ handle_response(response, status, respond_with_true: true)
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class PickupOptions < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +GET+ request is used to list all pickup options of the shop in a paged way.
11
+ #
12
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options' -i -X GET \
13
+ # -H 'Accept: application/hal+json' \
14
+ # -H 'Authorization: Bearer <Access token>'
15
+ #
16
+ # @option params [Boolean] :paginated
17
+ # @option params [Integer] :size the page size
18
+ # @option params [Integer] :page the page number
19
+ #
20
+ # @return [OpenStruct]
21
+ #
22
+ # @example
23
+ # @pickup_options = session.pickup_options.all(size: 100, page: 0)
24
+ #
25
+ def all(params = {})
26
+ handle_all_request("/pickup-options", :pickup_options, params)
27
+ end
28
+
29
+ #
30
+ # A +POST+ request is used to create a pickup option.
31
+ #
32
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options' -i -X POST \
33
+ # -H 'Content-Type: application/json' \
34
+ # -H 'Authorization: Bearer <Access token>' \
35
+ # -d '{
36
+ # "name" : "My little Cornershop - St.Ives",
37
+ # "description" : "We will send you an email when your items are ready for pickup. Please bring a copy of your order confirmation.",
38
+ # "taxClass" : "REGULAR",
39
+ # "freePickupValue" : {
40
+ # "currency" : "EUR",
41
+ # "amount" : 50
42
+ # },
43
+ # "fixedPrice" : {
44
+ # "taxModel" : "GROSS",
45
+ # "currency" : "EUR",
46
+ # "amount" : 1
47
+ # },
48
+ # "phoneNumberRequired" : true,
49
+ # "locationId" : "cb554eb6-2768-4491-afd2-6bcd0aec0937"
50
+ # }'
51
+ #
52
+ # @beyond_api.scopes +shpz:c+
53
+ #
54
+ # @param body [Hash] the request body
55
+ #
56
+ # @return [OpenStruct]
57
+ #
58
+ # @example
59
+ # body = {
60
+ # name: "My little Cornershop - St.Ives",
61
+ # description: "We will send you an email when your items are ready for pickup. Please bring a copy of your order confirmation.",
62
+ # tax_class: "REGULAR",
63
+ # free_pickup_value: {
64
+ # currency: "EUR",
65
+ # amount: 50
66
+ # },
67
+ # fixed_price: {
68
+ # tax_model: "GROSS",
69
+ # currency: "EUR",
70
+ # amount: 1
71
+ # },
72
+ # phone_number_required: true,
73
+ # location_id: "cb554eb6-2768-4491-afd2-6bcd0aec0937"
74
+ # }
75
+ #
76
+ # @pickup_option = session.pickup_options.create(body)
77
+ #
78
+ def create(body)
79
+ response, status = BeyondApi::Request.post(@session, "/pickup-options", body)
80
+
81
+ handle_response(response, status)
82
+ end
83
+ end
84
+ end