arctic-vendor 0.2.2 → 0.2.3
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 +51 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +2 -3
- data/documentation/CHANGELOG.md +137 -0
- data/documentation/CODE_OF_CONDUCT.md +46 -0
- data/documentation/Gemfile +11 -0
- data/documentation/Gemfile.lock +130 -0
- data/documentation/LICENSE +13 -0
- data/documentation/Procfile +1 -0
- data/documentation/README.md +118 -0
- data/documentation/build/fonts/slate.eot +0 -0
- data/documentation/build/fonts/slate.svg +14 -0
- data/documentation/build/fonts/slate.ttf +0 -0
- data/documentation/build/fonts/slate.woff +0 -0
- data/documentation/build/fonts/slate.woff2 +0 -0
- data/documentation/build/images/logo.png +0 -0
- data/documentation/build/images/navbar.png +0 -0
- data/documentation/build/index.html +564 -0
- data/documentation/build/javascripts/all.js +131 -0
- data/documentation/build/javascripts/all_nosearch.js +31 -0
- data/documentation/build/stylesheets/print.css +1 -0
- data/documentation/build/stylesheets/screen.css +1 -0
- data/documentation/config.rb +57 -0
- data/documentation/deploy.sh +215 -0
- data/documentation/font-selection.json +148 -0
- data/documentation/lib/multilang.rb +16 -0
- data/documentation/lib/nesting_unique_head.rb +22 -0
- data/documentation/lib/toc_data.rb +30 -0
- data/documentation/lib/unique_head.rb +24 -0
- data/documentation/source/fonts/slate.eot +0 -0
- data/documentation/source/fonts/slate.svg +14 -0
- data/documentation/source/fonts/slate.ttf +0 -0
- data/documentation/source/fonts/slate.woff +0 -0
- data/documentation/source/fonts/slate.woff2 +0 -0
- data/documentation/source/images/logo.png +0 -0
- data/documentation/source/images/navbar.png +0 -0
- data/documentation/source/includes/_errors.md +17 -0
- data/documentation/source/index.html.md +150 -0
- data/documentation/source/javascripts/all.js +2 -0
- data/documentation/source/javascripts/all_nosearch.js +16 -0
- data/documentation/source/javascripts/app/_lang.js +164 -0
- data/documentation/source/javascripts/app/_search.js +98 -0
- data/documentation/source/javascripts/app/_toc.js +114 -0
- data/documentation/source/javascripts/lib/_energize.js +169 -0
- data/documentation/source/javascripts/lib/_imagesloaded.min.js +7 -0
- data/documentation/source/javascripts/lib/_jquery.highlight.js +108 -0
- data/documentation/source/javascripts/lib/_jquery.js +9831 -0
- data/documentation/source/javascripts/lib/_lunr.js +1910 -0
- data/documentation/source/layouts/layout.erb +116 -0
- data/documentation/source/stylesheets/_icon-font.scss +38 -0
- data/documentation/source/stylesheets/_normalize.scss +427 -0
- data/documentation/source/stylesheets/_rtl.scss +140 -0
- data/documentation/source/stylesheets/_variables.scss +103 -0
- data/documentation/source/stylesheets/_variables2.scss +147 -0
- data/documentation/source/stylesheets/print.css.scss +148 -0
- data/documentation/source/stylesheets/screen.css.scss +712 -0
- data/lib/arctic/vendor/api.rb +38 -4
- data/lib/arctic/vendor/product.rb +47 -0
- data/lib/arctic/vendor/vendor.rb +7 -6
- data/lib/arctic/vendor/version.rb +1 -1
- data/vendor.gemspec +1 -1
- metadata +57 -16
data/lib/arctic/vendor/api.rb
CHANGED
@@ -2,6 +2,8 @@ require 'faraday'
|
|
2
2
|
require 'json'
|
3
3
|
require 'active_support/all'
|
4
4
|
|
5
|
+
require_relative 'product'
|
6
|
+
|
5
7
|
module Arctic
|
6
8
|
module Vendor
|
7
9
|
class API
|
@@ -45,8 +47,15 @@ module Arctic
|
|
45
47
|
end
|
46
48
|
|
47
49
|
# Retrieve products from the Core API
|
48
|
-
def list_products(account_id, shop_id)
|
49
|
-
|
50
|
+
def list_products(account_id, shop_id, **params)
|
51
|
+
make_paginated_request(:get, "accounts/#{account_id}/shops/#{shop_id}/products", params: params) do |products|
|
52
|
+
yield products.collect { |prod| Arctic::Vendor::Product.new account_id, shop_id, prod, self }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_product(account_id, shop_id, product_id)
|
57
|
+
product_id = URI.escape product_id
|
58
|
+
make_request :get, "accounts/#{account_id}/shops/#{shop_id}/products/#{product_id}"
|
50
59
|
end
|
51
60
|
|
52
61
|
# Marks the shop as synchronized by the vendor
|
@@ -54,6 +63,11 @@ module Arctic
|
|
54
63
|
make_request :put, "accounts/#{account_id}/shops/#{shop_id}/synchronized"
|
55
64
|
end
|
56
65
|
|
66
|
+
# Marks the shop as synchronized by the vendor
|
67
|
+
def update_product_state(account_id, shop_id, product_id, state)
|
68
|
+
make_request :put, "accounts/#{account_id}/shops/#{shop_id}/products/#{product_id}/state/#{state}"
|
69
|
+
end
|
70
|
+
|
57
71
|
private
|
58
72
|
|
59
73
|
def make_batch_request(*args, **options)
|
@@ -61,7 +75,7 @@ module Arctic
|
|
61
75
|
Arctic::Vendor.threaded(batches) { |batch| make_request *args, **(options.merge(body: batch)) }
|
62
76
|
end
|
63
77
|
|
64
|
-
def
|
78
|
+
def raw_request(method, path, body: {}, params: {})
|
65
79
|
# Remove preceeding slash to avoid going from base url /v1 to /
|
66
80
|
path = path.reverse.chomp('/').reverse
|
67
81
|
|
@@ -74,6 +88,10 @@ module Arctic
|
|
74
88
|
|
75
89
|
r.body = body.to_json if body.any?
|
76
90
|
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def make_request(method, path, body: {}, params: {})
|
94
|
+
response = raw_request method, path, body: body, params: params
|
77
95
|
|
78
96
|
json = begin
|
79
97
|
JSON.parse(response.body)
|
@@ -83,10 +101,26 @@ module Arctic
|
|
83
101
|
|
84
102
|
raise json['error'] if json.is_a?(Hash) && json['error']
|
85
103
|
|
86
|
-
Arctic.logger.info "#{method.to_s.upcase} #{path}: #{response.status}"
|
104
|
+
Arctic.logger.info "#{method.to_s.upcase} #{path}?#{params.to_query}: #{response.status}"
|
87
105
|
|
88
106
|
json
|
89
107
|
end
|
108
|
+
|
109
|
+
def make_paginated_request(method, path, body: {}, params: {})
|
110
|
+
response = raw_request :head, path, body: body, params: params
|
111
|
+
Arctic.logger.debug "Pagination response headers: #{response.headers}"
|
112
|
+
|
113
|
+
page = response.headers['page'] || 1
|
114
|
+
per_page = response.headers['per-page'] || 1
|
115
|
+
total_record = response.headers['total'] || 1
|
116
|
+
pages = (total_record.to_f / per_page.to_f).ceil
|
117
|
+
collection = (1..pages).to_a
|
118
|
+
|
119
|
+
Arctic::Vendor.threaded collection do |n|
|
120
|
+
params = params.merge page: n
|
121
|
+
yield make_request method, path, body: body, params: params
|
122
|
+
end
|
123
|
+
end
|
90
124
|
end
|
91
125
|
end
|
92
126
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Arctic
|
2
|
+
module Vendor
|
3
|
+
class Product
|
4
|
+
class Characteristics
|
5
|
+
def initialize(characteristics)
|
6
|
+
@characteristics = characteristics
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(name, *args)
|
10
|
+
@characteristics[name.to_s]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader \
|
15
|
+
:sku,
|
16
|
+
:characteristics,
|
17
|
+
:api,
|
18
|
+
:account_id,
|
19
|
+
:shop_id,
|
20
|
+
:state,
|
21
|
+
:master,
|
22
|
+
:price,
|
23
|
+
:currency,
|
24
|
+
:categories,
|
25
|
+
:images
|
26
|
+
|
27
|
+
def initialize(account_id, shop_id, product_hash, api_instance)
|
28
|
+
@api = api_instance
|
29
|
+
|
30
|
+
@shop_id = shop_id
|
31
|
+
@account_id = account_id
|
32
|
+
|
33
|
+
@sku = product_hash.fetch 'sku'
|
34
|
+
@characteristics = Characteristics.new product_hash.fetch 'characteristics'
|
35
|
+
|
36
|
+
@categories = product_hash.fetch 'categories', []
|
37
|
+
|
38
|
+
@state = product_hash.fetch 'state'
|
39
|
+
@master = product_hash.fetch 'master'
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_state(state)
|
43
|
+
api.update_product_state account_id, shop_id, sku, state
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/arctic/vendor/vendor.rb
CHANGED
@@ -23,8 +23,8 @@ module Arctic
|
|
23
23
|
end
|
24
24
|
module_function :each_shop
|
25
25
|
|
26
|
-
def api
|
27
|
-
@api ||= Arctic::Vendor::API.new
|
26
|
+
def api(*args)
|
27
|
+
@api ||= Arctic::Vendor::API.new(*args)
|
28
28
|
end
|
29
29
|
module_function :api
|
30
30
|
|
@@ -55,15 +55,16 @@ module Arctic
|
|
55
55
|
|
56
56
|
# Fetches all products from the Core API and distributes them to the
|
57
57
|
# target vendors
|
58
|
-
def distribute_products
|
58
|
+
def distribute_products(batch_size: 100)
|
59
59
|
Arctic.logger.info "Distributing products to target vendor..."
|
60
60
|
products_count = 0
|
61
61
|
|
62
62
|
seconds = time do
|
63
63
|
each_shop(type: :target) do |shop, account|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
api.list_products(account['id'], shop['id'], per_page: batch_size) do |products|
|
65
|
+
products_count += products.size
|
66
|
+
yield shop, products
|
67
|
+
end
|
67
68
|
api.synchronized account['id'], shop['id']
|
68
69
|
end
|
69
70
|
end
|
data/vendor.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = %w(lib)
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
# spec.add_development_dependency "bundler", "~> 1.16"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_runtime_dependency "faraday", "~> 0.14"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arctic-vendor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kampp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.16'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.16'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +74,7 @@ executables: []
|
|
88
74
|
extensions: []
|
89
75
|
extra_rdoc_files: []
|
90
76
|
files:
|
77
|
+
- ".circleci/config.yml"
|
91
78
|
- ".gitignore"
|
92
79
|
- ".rspec"
|
93
80
|
- ".travis.yml"
|
@@ -99,8 +86,62 @@ files:
|
|
99
86
|
- Rakefile
|
100
87
|
- bin/console
|
101
88
|
- bin/setup
|
89
|
+
- documentation/CHANGELOG.md
|
90
|
+
- documentation/CODE_OF_CONDUCT.md
|
91
|
+
- documentation/Gemfile
|
92
|
+
- documentation/Gemfile.lock
|
93
|
+
- documentation/LICENSE
|
94
|
+
- documentation/Procfile
|
95
|
+
- documentation/README.md
|
96
|
+
- documentation/build/fonts/slate.eot
|
97
|
+
- documentation/build/fonts/slate.svg
|
98
|
+
- documentation/build/fonts/slate.ttf
|
99
|
+
- documentation/build/fonts/slate.woff
|
100
|
+
- documentation/build/fonts/slate.woff2
|
101
|
+
- documentation/build/images/logo.png
|
102
|
+
- documentation/build/images/navbar.png
|
103
|
+
- documentation/build/index.html
|
104
|
+
- documentation/build/javascripts/all.js
|
105
|
+
- documentation/build/javascripts/all_nosearch.js
|
106
|
+
- documentation/build/stylesheets/print.css
|
107
|
+
- documentation/build/stylesheets/screen.css
|
108
|
+
- documentation/config.rb
|
109
|
+
- documentation/deploy.sh
|
110
|
+
- documentation/font-selection.json
|
111
|
+
- documentation/lib/multilang.rb
|
112
|
+
- documentation/lib/nesting_unique_head.rb
|
113
|
+
- documentation/lib/toc_data.rb
|
114
|
+
- documentation/lib/unique_head.rb
|
115
|
+
- documentation/source/fonts/slate.eot
|
116
|
+
- documentation/source/fonts/slate.svg
|
117
|
+
- documentation/source/fonts/slate.ttf
|
118
|
+
- documentation/source/fonts/slate.woff
|
119
|
+
- documentation/source/fonts/slate.woff2
|
120
|
+
- documentation/source/images/logo.png
|
121
|
+
- documentation/source/images/navbar.png
|
122
|
+
- documentation/source/includes/_errors.md
|
123
|
+
- documentation/source/index.html.md
|
124
|
+
- documentation/source/javascripts/all.js
|
125
|
+
- documentation/source/javascripts/all_nosearch.js
|
126
|
+
- documentation/source/javascripts/app/_lang.js
|
127
|
+
- documentation/source/javascripts/app/_search.js
|
128
|
+
- documentation/source/javascripts/app/_toc.js
|
129
|
+
- documentation/source/javascripts/lib/_energize.js
|
130
|
+
- documentation/source/javascripts/lib/_imagesloaded.min.js
|
131
|
+
- documentation/source/javascripts/lib/_jquery.highlight.js
|
132
|
+
- documentation/source/javascripts/lib/_jquery.js
|
133
|
+
- documentation/source/javascripts/lib/_lunr.js
|
134
|
+
- documentation/source/layouts/layout.erb
|
135
|
+
- documentation/source/stylesheets/_icon-font.scss
|
136
|
+
- documentation/source/stylesheets/_normalize.scss
|
137
|
+
- documentation/source/stylesheets/_rtl.scss
|
138
|
+
- documentation/source/stylesheets/_variables.scss
|
139
|
+
- documentation/source/stylesheets/_variables2.scss
|
140
|
+
- documentation/source/stylesheets/print.css.scss
|
141
|
+
- documentation/source/stylesheets/screen.css.scss
|
102
142
|
- lib/arctic/vendor.rb
|
103
143
|
- lib/arctic/vendor/api.rb
|
144
|
+
- lib/arctic/vendor/product.rb
|
104
145
|
- lib/arctic/vendor/uri.rb
|
105
146
|
- lib/arctic/vendor/vendor.rb
|
106
147
|
- lib/arctic/vendor/version.rb
|