flex_commerce_api 0.7 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +45 -0
- data/.github/workflows/gempush.yml +31 -0
- data/.ruby-version +1 -1
- data/README.md +40 -5
- data/flex-commerce-api.gemspec +1 -2
- data/lib/flex_commerce_api/base_resource.rb +1 -0
- data/lib/flex_commerce_api/config.rb +20 -4
- data/lib/flex_commerce_api/json_api_client_extension/forwarded_for_middleware.rb +17 -0
- data/lib/flex_commerce_api/version.rb +1 -1
- data/lib/json_struct.rb +12 -16
- data/lib/paypal_express/cart_shipping_method.rb +3 -5
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ca38dba4a1fd2e2fc35b89ae3f66a7c22ba83ce2300bfcc5ccca0eb56febdcd
|
4
|
+
data.tar.gz: 551f7ba8158e64c66d2c076fabbdb99279a3441fdc27ff5ac6799c041808b378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e148bcc1259523c421add780130a28a3d445696c086e4b894f56a4432d480c512b08da6aa4e575d06f040f05000db776301759a993dc8920aff2be069cf83922
|
7
|
+
data.tar.gz: be0b5a2e09f14d3638ab5d7ff75da1953f5c5fdf19c57c44ef5af67aaaffb1be0f81ecfe98225df8b81a1fba6185d71aee7b16d62e7d0e6c86f796ce8a122de3
|
@@ -0,0 +1,45 @@
|
|
1
|
+
version: '2.1'
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build-ruby-27:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.7.0
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- rubygems-27-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
|
12
|
+
- rubygems-27-cache-{{ .Branch }}
|
13
|
+
- rubygems-27-cache
|
14
|
+
- run: bundle install --path vendor/bundle
|
15
|
+
- save_cache:
|
16
|
+
key: rubygems-27-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
|
17
|
+
paths:
|
18
|
+
- vendor/bundle
|
19
|
+
- run: bundle exec rspec
|
20
|
+
|
21
|
+
build-ruby-25:
|
22
|
+
docker:
|
23
|
+
- image: circleci/ruby:2.5.3
|
24
|
+
steps:
|
25
|
+
- checkout
|
26
|
+
- restore_cache:
|
27
|
+
keys:
|
28
|
+
- rubygems-25-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
|
29
|
+
- rubygems-25-cache-{{ .Branch }}
|
30
|
+
- rubygems-25-cache
|
31
|
+
- run: gem install bundler -v "~> 1.17"
|
32
|
+
- run: bundle install --path vendor/bundle
|
33
|
+
- save_cache:
|
34
|
+
key: rubygems-25-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
|
35
|
+
paths:
|
36
|
+
- vendor/bundle
|
37
|
+
- run: bundle exec rspec
|
38
|
+
|
39
|
+
|
40
|
+
workflows:
|
41
|
+
version: 2
|
42
|
+
build:
|
43
|
+
jobs:
|
44
|
+
- build-ruby-27
|
45
|
+
- build-ruby-25
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
paths:
|
8
|
+
- "lib/flex_commerce_api/version.rb"
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
name: Build + Publish
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.7
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
version: 2.7.x
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.0
|
data/README.md
CHANGED
@@ -12,15 +12,19 @@ gem 'flex-commerce-api'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
16
18
|
|
17
19
|
Or install it yourself as:
|
18
20
|
|
19
|
-
|
21
|
+
```
|
22
|
+
$ gem install flex-commerce-api
|
23
|
+
```
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
The gem provides many models in the FlexCommerce namespace.
|
27
|
+
The gem provides many models in the FlexCommerce namespace. The example below is a rails controller
|
24
28
|
accessing a list of products.
|
25
29
|
|
26
30
|
```ruby
|
@@ -31,15 +35,46 @@ class ProductsController < ApplicationController
|
|
31
35
|
@products = FlexCommerce::Product.paginate(params[:page])
|
32
36
|
end
|
33
37
|
end
|
34
|
-
|
35
38
|
```
|
36
39
|
|
37
40
|
To any rails developer this will look familiar.
|
38
41
|
|
39
42
|
However, we do not force you to use rails. We appreciate that there are many frameworks out there
|
40
43
|
and whilst rails is an excellent tool, for smaller projects you may want to look at others such
|
41
|
-
as
|
44
|
+
as Sinatra etc...
|
45
|
+
|
46
|
+
### Client IP address tracing in Rails apps
|
47
|
+
|
48
|
+
Add the request store gem to your Gemfile and install
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
gem "request-store"
|
52
|
+
```
|
53
|
+
|
54
|
+
```sh
|
55
|
+
bundle install
|
56
|
+
```
|
42
57
|
|
58
|
+
```ruby
|
59
|
+
# application_controller.rb
|
60
|
+
class ApplicationController
|
61
|
+
before_action :set_request_ip
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def set_request_ip
|
66
|
+
RequestStore[:request_ip] = request.remote_ip
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
Configure the API client to pick up set value
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
FlexCommerceApi.config do |config|
|
75
|
+
config.forwarded_for = ->{ RequestStore[:request_ip] }
|
76
|
+
end
|
77
|
+
```
|
43
78
|
|
44
79
|
## Development
|
45
80
|
|
data/flex-commerce-api.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "flex_commerce_api/version"
|
@@ -19,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
19
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
19
|
spec.require_paths = ["lib"]
|
21
20
|
|
22
|
-
spec.add_development_dependency "bundler", "
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.17"
|
23
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
23
|
spec.add_development_dependency "rspec", "~> 3.3"
|
25
24
|
spec.add_development_dependency "webmock", "~> 1.21"
|
@@ -10,6 +10,7 @@ require "flex_commerce_api/json_api_client_extension/status_middleware"
|
|
10
10
|
require "flex_commerce_api/json_api_client_extension/json_format_middleware"
|
11
11
|
require "flex_commerce_api/json_api_client_extension/previewed_request_middleware"
|
12
12
|
require "flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware"
|
13
|
+
require "flex_commerce_api/json_api_client_extension/forwarded_for_middleware"
|
13
14
|
require "flex_commerce_api/json_api_client_extension/has_many_association_proxy"
|
14
15
|
require "flex_commerce_api/json_api_client_extension/builder"
|
15
16
|
require "flex_commerce_api/json_api_client_extension/flexible_connection"
|
@@ -27,14 +27,31 @@ module FlexCommerceApi
|
|
27
27
|
# section of the admin panel
|
28
28
|
# @!attribute order_test_mode
|
29
29
|
# The order test mode.This config determines if orders are processed as test or real orders
|
30
|
-
|
30
|
+
|
31
|
+
attr_accessor(
|
32
|
+
:flex_root_url,
|
33
|
+
:flex_api_key,
|
34
|
+
:flex_account,
|
35
|
+
:logger,
|
36
|
+
:adapter,
|
37
|
+
:http_cache,
|
38
|
+
:open_timeout,
|
39
|
+
:timeout,
|
40
|
+
:paypal_login,
|
41
|
+
:paypal_password,
|
42
|
+
:paypal_signature,
|
43
|
+
:order_test_mode,
|
44
|
+
:paypal_connection_errors_no_of_retries,
|
45
|
+
:forwarded_for
|
46
|
+
)
|
47
|
+
|
31
48
|
attr_reader :api_version
|
32
49
|
|
33
50
|
def initialize
|
34
51
|
self.order_test_mode = false
|
35
52
|
self.http_cache = {}
|
36
|
-
self.open_timeout = ENV.fetch(
|
37
|
-
self.timeout = ENV.fetch(
|
53
|
+
self.open_timeout = ENV.fetch("SHIFT_OPEN_TIMEOUT", 2).to_i
|
54
|
+
self.timeout = ENV.fetch("SHIFT_TIMEOUT", 15).to_i
|
38
55
|
end
|
39
56
|
|
40
57
|
# The api base URL
|
@@ -50,6 +67,5 @@ module FlexCommerceApi
|
|
50
67
|
def reconfigure_all!
|
51
68
|
FlexCommerceApi::BaseResource.reconfigure_all if FlexCommerceApi.const_defined? "ApiBase"
|
52
69
|
end
|
53
|
-
|
54
70
|
end
|
55
71
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module JsonApiClientExtension
|
3
|
+
# Looks for a lambda defined on the config, calls and assigns it to the
|
4
|
+
# outgoing request headers
|
5
|
+
class ForwardedForMiddleware < Faraday::Middleware
|
6
|
+
def call(env)
|
7
|
+
forwarded_for = FlexCommerceApi.config.forwarded_for
|
8
|
+
|
9
|
+
if forwarded_for.respond_to?(:call)
|
10
|
+
env[:request_headers]["X-Forwarded-For"] = forwarded_for.call
|
11
|
+
end
|
12
|
+
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/json_struct.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "ostruct"
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
class JsonStruct < OpenStruct
|
5
|
-
def initialize(hash=nil)
|
6
|
-
|
5
|
+
def initialize(hash = nil)
|
7
6
|
@table = {}
|
8
7
|
@hash_table = {}
|
9
8
|
|
10
9
|
if hash
|
11
|
-
recurse =
|
10
|
+
recurse = proc { |item|
|
12
11
|
values = []
|
13
12
|
|
14
13
|
item.each do |val|
|
@@ -25,18 +24,16 @@ class JsonStruct < OpenStruct
|
|
25
24
|
item.push(*values)
|
26
25
|
|
27
26
|
item
|
28
|
-
|
29
|
-
|
30
|
-
hash.each do |k,v|
|
27
|
+
}
|
31
28
|
|
29
|
+
hash.each do |k, v|
|
32
30
|
if v.is_a?(Array)
|
33
31
|
recurse.call(v)
|
34
32
|
end
|
35
33
|
|
36
34
|
@table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
|
37
35
|
@hash_table[k.to_sym] = v
|
38
|
-
new_ostruct_member(k)
|
39
|
-
|
36
|
+
new_ostruct_member!(k)
|
40
37
|
end
|
41
38
|
end
|
42
39
|
end
|
@@ -45,8 +42,8 @@ class JsonStruct < OpenStruct
|
|
45
42
|
op = {}
|
46
43
|
|
47
44
|
@table.each_pair do |key, value|
|
48
|
-
if value.is_a?(Array)
|
49
|
-
|
45
|
+
op[key] = if value.is_a?(Array)
|
46
|
+
value.map do |item|
|
50
47
|
if item.is_a?(self.class)
|
51
48
|
item.to_h
|
52
49
|
else
|
@@ -54,20 +51,19 @@ class JsonStruct < OpenStruct
|
|
54
51
|
end
|
55
52
|
end
|
56
53
|
elsif value.is_a?(self.class)
|
57
|
-
|
54
|
+
value.to_h
|
58
55
|
else
|
59
|
-
|
56
|
+
value
|
60
57
|
end
|
61
58
|
end
|
62
59
|
op
|
63
60
|
end
|
64
61
|
|
65
62
|
def as_json(*args)
|
66
|
-
|
63
|
+
to_h
|
67
64
|
end
|
68
65
|
|
69
66
|
def to_json
|
70
67
|
JSON.dump(to_h)
|
71
68
|
end
|
72
|
-
|
73
|
-
end
|
69
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "bigdecimal"
|
2
2
|
|
3
3
|
# @module FlexCommerce::PaypalExpress
|
4
4
|
module FlexCommerce
|
5
5
|
module PaypalExpress
|
6
6
|
# @class CartShippingMethod
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# Used to decorate shipping methods based on Promotions
|
9
9
|
class CartShippingMethod < SimpleDelegator
|
10
|
-
|
11
|
-
ZERO = BigDecimal.new(0)
|
10
|
+
ZERO = BigDecimal(0)
|
12
11
|
|
13
12
|
def initialize(shipping_method, free)
|
14
13
|
super(shipping_method)
|
@@ -32,7 +31,6 @@ module FlexCommerce
|
|
32
31
|
private
|
33
32
|
|
34
33
|
attr_accessor :free
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex_commerce_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.17'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -275,7 +275,9 @@ executables: []
|
|
275
275
|
extensions: []
|
276
276
|
extra_rdoc_files: []
|
277
277
|
files:
|
278
|
+
- ".circleci/config.yml"
|
278
279
|
- ".env.example"
|
280
|
+
- ".github/workflows/gempush.yml"
|
279
281
|
- ".gitignore"
|
280
282
|
- ".rspec"
|
281
283
|
- ".rubocop.yml"
|
@@ -386,6 +388,7 @@ files:
|
|
386
388
|
- lib/flex_commerce_api/json_api_client_extension/builder.rb
|
387
389
|
- lib/flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware.rb
|
388
390
|
- lib/flex_commerce_api/json_api_client_extension/flexible_connection.rb
|
391
|
+
- lib/flex_commerce_api/json_api_client_extension/forwarded_for_middleware.rb
|
389
392
|
- lib/flex_commerce_api/json_api_client_extension/has_many_association_proxy.rb
|
390
393
|
- lib/flex_commerce_api/json_api_client_extension/included_data.rb
|
391
394
|
- lib/flex_commerce_api/json_api_client_extension/json_format_middleware.rb
|
@@ -462,8 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
462
465
|
- !ruby/object:Gem::Version
|
463
466
|
version: '0'
|
464
467
|
requirements: []
|
465
|
-
|
466
|
-
rubygems_version: 2.7.7
|
468
|
+
rubygems_version: 3.1.2
|
467
469
|
signing_key:
|
468
470
|
specification_version: 4
|
469
471
|
summary: Access the flex-commerce API
|