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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc6513e97ac7ec622da979d66f36a36b71d6febf5190408ece1a5fafcf2890e2
|
4
|
+
data.tar.gz: 1e13365c3d4ac79de3a813de39ee413d228a09fb5f2959eaca203ad89f7cff70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8185d244d86bbc9931a30d0d611c9c1de3eb00542804f774b43336cb18814be42e087b38a110a4f8646257ed2bd6880984d3938c07f96f70eafcab765acdbb54
|
7
|
+
data.tar.gz: 962ad63c5b9e943b60d9a4e17bb565c0e3beef244bd0d269b24da076a4cb90d5612644da73508b2fce4cf3d3f1ce4524d139d72f23ee73a5d9b3f304c238ea9a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--tag beyond_api.scopes:"Scopes"
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Contributing to Beyond API Ruby Client
|
2
|
+
|
3
|
+
We love pull requests from everyone. Here are some ways _you_ can contribute:
|
4
|
+
|
5
|
+
* by using alpha, beta, and prerelease versions
|
6
|
+
* by reporting bugs
|
7
|
+
* by suggesting new features
|
8
|
+
* by writing or editing documentation
|
9
|
+
* by writing specifications
|
10
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
11
|
+
* by refactoring code
|
12
|
+
* by closing [issues][]
|
13
|
+
* by reviewing patches
|
14
|
+
|
15
|
+
[issues]: https://github.com/ePages-de/beyond_api-ruby_client/issues
|
16
|
+
|
17
|
+
## Submitting an Issue
|
18
|
+
|
19
|
+
* We use the [GitHub issue tracker][issues] to track bugs and features.
|
20
|
+
* Before submitting a bug report or feature request, check to make sure it hasn't already been submitted.
|
21
|
+
* When submitting a bug report, please include a [Gist][] that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with failing specs.
|
22
|
+
|
23
|
+
[gist]: https://gist.github.com/
|
24
|
+
|
25
|
+
## Cleaning up issues
|
26
|
+
|
27
|
+
* Issues that have no response from the submitter will be closed after 30 days.
|
28
|
+
* Issues will be closed once they're assumed to be fixed or answered. If the maintainer is wrong, it can be opened again.
|
29
|
+
* If your issue is closed by mistake, please understand and explain the issue. We will happily reopen the issue.
|
30
|
+
|
31
|
+
## Submitting a Pull Request
|
32
|
+
|
33
|
+
1. [Fork][fork] the [official repository][repo].
|
34
|
+
2. [Create a topic branch.][branch]
|
35
|
+
3. Implement your feature or bug fix.
|
36
|
+
4. Add, commit, and push your changes.
|
37
|
+
5. [Submit a pull request.][pr]
|
38
|
+
|
39
|
+
## Notes
|
40
|
+
|
41
|
+
* Please don't update the Gem version.
|
42
|
+
|
43
|
+
[repo]: https://github.com/ePages-de/beyond_api-ruby_client/tree/master
|
44
|
+
[fork]: https://help.github.com/articles/fork-a-repo/
|
45
|
+
[branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
|
46
|
+
[pr]: https://help.github.com/articles/using-pull-requests/
|
47
|
+
|
48
|
+
Inspired by https://github.com/thoughtbot/factory_bot/blob/master/CONTRIBUTING.md
|
data/GETTING_STARTED.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
beyond_api (0.1.0.pre)
|
5
|
+
faraday (~> 0.15)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
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.15.4)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
i18n (1.6.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
method_source (0.9.2)
|
21
|
+
multipart-post (2.1.1)
|
22
|
+
pry (0.12.2)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
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)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-mocks (3.8.1)
|
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)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
beyond_api!
|
46
|
+
bundler (~> 2.0)
|
47
|
+
dotenv (~> 2.7)
|
48
|
+
faker (~> 2.2)
|
49
|
+
pry
|
50
|
+
rake (~> 10.0)
|
51
|
+
rspec (~> 3.0)
|
52
|
+
yard (~> 0.9)
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2019 ePages GmbH
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
18
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
19
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Beyond API Ruby Client
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem "beyond_api"
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
$ bundle install
|
15
|
+
```
|
16
|
+
|
17
|
+
Next, you need to run the generator:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ rails generate beyond_api:install
|
21
|
+
```
|
22
|
+
|
23
|
+
This will generate the configuration file on `config/initializers/beyond_api.rb`. Set the `client_id` and `client_secret` values to get started.
|
24
|
+
|
25
|
+
> ⚠️ **Be careful!** Don't expose your `client_id` and `client_secret` or publish them on GitHub or any other service. Use [Rails Credentials](https://guides.rubyonrails.org/security.html#custom-credentials) or a gem like [dotenv](https://github.com/bkeepers/dotenv) to save your environment variables.
|
26
|
+
|
27
|
+
To install the gem manually from your shell, run:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ gem install beyond_api
|
31
|
+
```
|
32
|
+
|
33
|
+
## Documentation
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
Check out the repo an run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Please see [CONTRIBUTING](https://github.com/ePages-de/beyond_api-ruby_client/blob/master/CONTRIBUTING.md).
|
44
|
+
|
45
|
+
## Changelog
|
46
|
+
|
47
|
+
Beyond API's changelog is available [here](https://github.com/ePages-de/beyond_api-ruby_client/blob/master/CHANGELOG.md).
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
beyond_api is Copyright © 2019 ePages GmbH. It is free software, and may be redistributed under the terms specified in the [LICENSE](https://github.com/ePages-de/beyond_api-ruby_client/blob/master/LICENSE) file.
|
data/Rakefile
ADDED
data/beyond_api.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "beyond_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "beyond_api"
|
8
|
+
spec.version = BeyondApi::VERSION
|
9
|
+
spec.authors = ["Unai Abrisketa", "Kathia Salazar", "German San Emeterio"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby client to access the Beyond API"
|
12
|
+
spec.homepage = "https://github.com/ePages-de/beyond_api-ruby_client"
|
13
|
+
|
14
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = ">= 2.5.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
27
|
+
spec.add_development_dependency "faker", "~> 2.2"
|
28
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
29
|
+
|
30
|
+
spec.add_dependency "faraday", "~> 0.15"
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dotenv/load"
|
5
|
+
require "beyond_api"
|
6
|
+
|
7
|
+
unless ENV["CLIENT_ID"].nil? and ENV["CLIENT_SECRET"].nil?
|
8
|
+
BeyondApi.setup do |config|
|
9
|
+
config.client_id = ENV["CLIENT_ID"]
|
10
|
+
config.client_secret = ENV["CLIENT_SECRET"]
|
11
|
+
config.remove_response_links = true
|
12
|
+
config.remove_response_key_underscores = true
|
13
|
+
config.object_struct_responses = false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "pry"
|
18
|
+
Pry.start
|
data/bin/setup
ADDED
data/lib/beyond_api.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "beyond_api/version"
|
2
|
+
|
3
|
+
require "beyond_api/connection"
|
4
|
+
require "beyond_api/request"
|
5
|
+
require "beyond_api/session"
|
6
|
+
|
7
|
+
require "beyond_api/ext"
|
8
|
+
require "beyond_api/utils"
|
9
|
+
|
10
|
+
module BeyondApi
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.setup
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
|
20
|
+
yield configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
class Configuration
|
24
|
+
attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
|
25
|
+
:remove_response_key_underscores, :object_struct_responses
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@client_id = nil
|
29
|
+
@client_secret = nil
|
30
|
+
@open_timeout = 2
|
31
|
+
@timeout = 5
|
32
|
+
@remove_response_links = false
|
33
|
+
@remove_response_key_underscores = false
|
34
|
+
@object_struct_responses = false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
class Connection
|
7
|
+
def self.default
|
8
|
+
Faraday.new(ssl: { verify: true }) do |faraday|
|
9
|
+
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
|
10
|
+
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
|
11
|
+
faraday.headers['Accept'] = 'application/json'
|
12
|
+
faraday.headers['Content-Type'] = 'application/json'
|
13
|
+
faraday.request(:multipart)
|
14
|
+
faraday.request(:url_encoded)
|
15
|
+
faraday.adapter(:net_http)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.token
|
20
|
+
Faraday.new(ssl: { verify: true }) do |faraday|
|
21
|
+
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
|
22
|
+
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
|
23
|
+
faraday.headers['Accept'] = 'application/json'
|
24
|
+
faraday.adapter(:net_http)
|
25
|
+
faraday.basic_auth(BeyondApi.configuration.client_id,
|
26
|
+
BeyondApi.configuration.client_secret)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def deep_transform_keys(&block)
|
5
|
+
result = {}
|
6
|
+
each do |key, value|
|
7
|
+
result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
|
8
|
+
end
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
def camelize_keys
|
13
|
+
deep_transform_keys { |key| key.to_s.camelize(false) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def underscorize_keys
|
17
|
+
deep_transform_keys { |key| key.to_s.underscore }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class String
|
22
|
+
def blank?
|
23
|
+
respond_to?(:empty?) ? !!empty? : !self
|
24
|
+
end
|
25
|
+
|
26
|
+
def underscore
|
27
|
+
self.gsub(/::/, '/').
|
28
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
29
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
30
|
+
tr("-", "_").
|
31
|
+
downcase
|
32
|
+
end
|
33
|
+
|
34
|
+
def camelize(uppercase_first_letter = true)
|
35
|
+
string = self
|
36
|
+
if uppercase_first_letter
|
37
|
+
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
38
|
+
else
|
39
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
40
|
+
end
|
41
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module BeyondApi
|
6
|
+
class Request
|
7
|
+
class << self
|
8
|
+
[:get, :delete].each do |method|
|
9
|
+
define_method(method) do |session, path, params = {}|
|
10
|
+
response = BeyondApi::Connection.default.send(method) do |request|
|
11
|
+
request.url(session.api_url + path)
|
12
|
+
request.headers['Authorization'] = "Bearer #{ session.access_token }"
|
13
|
+
request.params = params.to_h.camelize_keys
|
14
|
+
end
|
15
|
+
|
16
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
[:post, :put, :patch].each do |method|
|
21
|
+
define_method(method) do |session, path, body = {}, params = {}|
|
22
|
+
response = BeyondApi::Connection.default.send(method) do |request|
|
23
|
+
request.url(session.api_url + path)
|
24
|
+
request.headers['Authorization'] = "Bearer #{ session.access_token }"
|
25
|
+
request.params = params.to_h.camelize_keys
|
26
|
+
request.body = body.to_h.camelize_keys.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.upload(session, path, file_binary, content_type, params)
|
35
|
+
response = BeyondApi::Connection.default.post do |request|
|
36
|
+
request.url(session.api_url + path)
|
37
|
+
request.headers['Authorization'] = "Bearer #{ session.access_token }"
|
38
|
+
request.headers['Content-Type'] = content_type
|
39
|
+
request.params = params.to_h.camelize_keys
|
40
|
+
request.body = file_binary
|
41
|
+
end
|
42
|
+
|
43
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.token(url, params)
|
47
|
+
response = BeyondApi::Connection.token.post do |request|
|
48
|
+
request.url(url)
|
49
|
+
request.params = params
|
50
|
+
end
|
51
|
+
|
52
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|