beyond_api 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +4 -0
  7. data/CONTRIBUTING.md +48 -0
  8. data/GETTING_STARTED.md +0 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +55 -0
  11. data/LICENSE +19 -0
  12. data/README.md +51 -0
  13. data/Rakefile +11 -0
  14. data/beyond_api.gemspec +31 -0
  15. data/bin/console +18 -0
  16. data/bin/setup +8 -0
  17. data/lib/beyond_api.rb +37 -0
  18. data/lib/beyond_api/connection.rb +30 -0
  19. data/lib/beyond_api/ext.rb +43 -0
  20. data/lib/beyond_api/request.rb +55 -0
  21. data/lib/beyond_api/resources/base.rb +17 -0
  22. data/lib/beyond_api/resources/carts.rb +547 -0
  23. data/lib/beyond_api/resources/categories.rb +168 -0
  24. data/lib/beyond_api/resources/categories_view.rb +142 -0
  25. data/lib/beyond_api/resources/checkout_settings.rb +48 -0
  26. data/lib/beyond_api/resources/newsletter_target.rb +97 -0
  27. data/lib/beyond_api/resources/order_settings.rb +80 -0
  28. data/lib/beyond_api/resources/orders.rb +968 -0
  29. data/lib/beyond_api/resources/payment_methods.rb +192 -0
  30. data/lib/beyond_api/resources/product_attribute_definitions.rb +109 -0
  31. data/lib/beyond_api/resources/product_settings.rb +28 -0
  32. data/lib/beyond_api/resources/products.rb +245 -0
  33. data/lib/beyond_api/resources/products/attachments.rb +119 -0
  34. data/lib/beyond_api/resources/products/availability.rb +177 -0
  35. data/lib/beyond_api/resources/products/custom_attributes.rb +141 -0
  36. data/lib/beyond_api/resources/products/images.rb +165 -0
  37. data/lib/beyond_api/resources/products/searches.rb +52 -0
  38. data/lib/beyond_api/resources/products/variation_properties.rb +87 -0
  39. data/lib/beyond_api/resources/products_view.rb +158 -0
  40. data/lib/beyond_api/resources/scopes.rb +31 -0
  41. data/lib/beyond_api/resources/script_tags.rb +122 -0
  42. data/lib/beyond_api/resources/shipping_zones.rb +324 -0
  43. data/lib/beyond_api/resources/shop.rb +561 -0
  44. data/lib/beyond_api/resources/signers.rb +63 -0
  45. data/lib/beyond_api/resources/token.rb +41 -0
  46. data/lib/beyond_api/resources/users.rb +376 -0
  47. data/lib/beyond_api/resources/variations.rb +145 -0
  48. data/lib/beyond_api/resources/variations/availability.rb +105 -0
  49. data/lib/beyond_api/resources/webhook_subscriptions.rb +176 -0
  50. data/lib/beyond_api/session.rb +121 -0
  51. data/lib/beyond_api/utils.rb +51 -0
  52. data/lib/beyond_api/version.rb +3 -0
  53. data/lib/generators/beyond_api/install_generator.rb +13 -0
  54. data/lib/generators/templates/beyond_api_initializer.rb +29 -0
  55. metadata +194 -0
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ module Utils
5
+ extend self
6
+
7
+ def handle_response(response, status, respond_with_true: false)
8
+ if status.between?(200, 299)
9
+ return true if respond_with_true
10
+ response = sanitize_response(response)
11
+ BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
12
+ else
13
+ BeyondApi::Error.new(response)
14
+ end
15
+ end
16
+
17
+ def to_object_struct(data)
18
+ if data.is_a? Hash
19
+ return OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
20
+ elsif data.is_a? Array
21
+ return data.map { |o| to_object_struct(o) }
22
+ else
23
+ return data
24
+ end
25
+ end
26
+
27
+ def sanitize_response(hash)
28
+ {}.tap do |h|
29
+ hash.each do |key, value|
30
+ next if key == "_links" && BeyondApi.configuration.remove_response_links
31
+ key = sanitize_key(key) if BeyondApi.configuration.remove_response_key_underscores
32
+ h[key.underscore.to_sym] = transform(value)
33
+ end
34
+ end
35
+ end
36
+
37
+ def sanitize_key(key)
38
+ key.chars.first == "_" ? key[1..-1] : key
39
+ end
40
+
41
+ private
42
+
43
+ def transform(thing)
44
+ case thing
45
+ when Hash; sanitize_response(thing)
46
+ when Array; thing.map { |v| transform(v) }
47
+ else; thing
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module BeyondApi
2
+ VERSION = "0.1.0.pre".freeze
3
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+
8
+ def copy_initializer
9
+ template "beyond_api_initializer.rb", "config/initializers/beyond_api.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ BeyondApi.setup do |config|
4
+ # ==> Client configuration
5
+ config.client_id = nil
6
+ config.client_secret = nil
7
+
8
+ # ==> Api configuration
9
+ # Configure the open connection timeout in seconds. Default is 2 seconds.
10
+ # config.open_timeout = 2.seconds
11
+
12
+ # Configure the request timeout in seconds. Default is 5 seconds.
13
+ # config.timeout = 5.seconds
14
+
15
+ # ==> Response configuration
16
+ # Configure if :_links should be removed from response. Default is false and
17
+ # :_links are gonna be part of the response.
18
+ # config.remove_response_links = false
19
+
20
+ # Configure if first character underescores should be removed on response hash
21
+ # keys. For example, if set to true, :_id will become :id. Default is false.
22
+ # config.remove_response_key_underscores = false
23
+
24
+ # Configure if responses should be transformed to ObjectStructs. If set to
25
+ # true, it gives you the posibility to access response data on a doted way.
26
+ # With OpenStructs => response.embeded.products.first.id
27
+ # Without OpenStructs => response["embeded"]["products"].first["id"]
28
+ # config.object_struct_responses = false
29
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beyond_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Unai Abrisketa
8
+ - Kathia Salazar
9
+ - German San Emeterio
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2019-10-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: yard
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.9'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '0.9'
71
+ - !ruby/object:Gem::Dependency
72
+ name: faker
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.2'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '2.2'
85
+ - !ruby/object:Gem::Dependency
86
+ name: dotenv
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.7'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '2.7'
99
+ - !ruby/object:Gem::Dependency
100
+ name: faraday
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '0.15'
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0.15'
113
+ description:
114
+ email:
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - ".yardopts"
123
+ - CHANGELOG.md
124
+ - CONTRIBUTING.md
125
+ - GETTING_STARTED.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE
129
+ - README.md
130
+ - Rakefile
131
+ - beyond_api.gemspec
132
+ - bin/console
133
+ - bin/setup
134
+ - lib/beyond_api.rb
135
+ - lib/beyond_api/connection.rb
136
+ - lib/beyond_api/ext.rb
137
+ - lib/beyond_api/request.rb
138
+ - lib/beyond_api/resources/base.rb
139
+ - lib/beyond_api/resources/carts.rb
140
+ - lib/beyond_api/resources/categories.rb
141
+ - lib/beyond_api/resources/categories_view.rb
142
+ - lib/beyond_api/resources/checkout_settings.rb
143
+ - lib/beyond_api/resources/newsletter_target.rb
144
+ - lib/beyond_api/resources/order_settings.rb
145
+ - lib/beyond_api/resources/orders.rb
146
+ - lib/beyond_api/resources/payment_methods.rb
147
+ - lib/beyond_api/resources/product_attribute_definitions.rb
148
+ - lib/beyond_api/resources/product_settings.rb
149
+ - lib/beyond_api/resources/products.rb
150
+ - lib/beyond_api/resources/products/attachments.rb
151
+ - lib/beyond_api/resources/products/availability.rb
152
+ - lib/beyond_api/resources/products/custom_attributes.rb
153
+ - lib/beyond_api/resources/products/images.rb
154
+ - lib/beyond_api/resources/products/searches.rb
155
+ - lib/beyond_api/resources/products/variation_properties.rb
156
+ - lib/beyond_api/resources/products_view.rb
157
+ - lib/beyond_api/resources/scopes.rb
158
+ - lib/beyond_api/resources/script_tags.rb
159
+ - lib/beyond_api/resources/shipping_zones.rb
160
+ - lib/beyond_api/resources/shop.rb
161
+ - lib/beyond_api/resources/signers.rb
162
+ - lib/beyond_api/resources/token.rb
163
+ - lib/beyond_api/resources/users.rb
164
+ - lib/beyond_api/resources/variations.rb
165
+ - lib/beyond_api/resources/variations/availability.rb
166
+ - lib/beyond_api/resources/webhook_subscriptions.rb
167
+ - lib/beyond_api/session.rb
168
+ - lib/beyond_api/utils.rb
169
+ - lib/beyond_api/version.rb
170
+ - lib/generators/beyond_api/install_generator.rb
171
+ - lib/generators/templates/beyond_api_initializer.rb
172
+ homepage: https://github.com/ePages-de/beyond_api-ruby_client
173
+ licenses: []
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: 2.5.1
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">"
187
+ - !ruby/object:Gem::Version
188
+ version: 1.3.1
189
+ requirements: []
190
+ rubygems_version: 3.0.3
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Ruby client to access the Beyond API
194
+ test_files: []