custom_gateway 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/custom_gateway.rb +26 -0
- data/lib/custom_gateway/configuration.rb +5 -0
- data/lib/custom_gateway/errors/auth_error.rb +3 -0
- data/lib/custom_gateway/models/category.rb +11 -0
- data/lib/custom_gateway/models/product.rb +96 -0
- data/lib/custom_gateway/services/base.rb +39 -0
- data/lib/custom_gateway/services/categories.rb +42 -0
- data/lib/custom_gateway/services/products.rb +83 -0
- data/lib/custom_gateway/version.rb +3 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6b8ec6698a62326d18d984364cd50a44c530817
|
4
|
+
data.tar.gz: ebe8a154c1b173bdf38aee2ef6b55b9fdcca1b37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b8218c4676c9e588e9ae43c446f3129ad14dd7c3bec439e5a3872f20c4813a121a74fba4192a822a602158fa32ea18cb1847e234357fec7cb01988f705dd425
|
7
|
+
data.tar.gz: 425c428edffaf72cac7430689dd52bdbb2ccda22049c5fa0538f3bd2518d65548f060b0bfaff72a9803da4ecbe46a6c550a0ed30a073c9ed273abc6c7fd4d9e1
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require "custom_gateway/configuration"
|
6
|
+
require "custom_gateway/version"
|
7
|
+
require "custom_gateway/models/product"
|
8
|
+
require "custom_gateway/models/category"
|
9
|
+
require "custom_gateway/services/base"
|
10
|
+
require "custom_gateway/services/categories"
|
11
|
+
require "custom_gateway/services/products"
|
12
|
+
require "custom_gateway/errors/auth_error"
|
13
|
+
|
14
|
+
module CustomGateway
|
15
|
+
class << self
|
16
|
+
attr_writer :configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.config
|
24
|
+
yield(configuration)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module CustomGateway
|
2
|
+
class Product
|
3
|
+
attr_accessor :id, :ref, :name, :retail_sku, :product_code, :machine_type,
|
4
|
+
:space, :is_locked, :load_count, :last_load, :last_modified,
|
5
|
+
:print_job_count, :product_sample_count, :date_created, :type,
|
6
|
+
:legacy_3d, :default_app, :default_app_config, :default_app_pc,
|
7
|
+
:default_app_g, :default_app_ddp, :default_app_dd, :always_use_px,
|
8
|
+
:default_app_locale, :base_product_id, :base_stock_product_id,
|
9
|
+
:product_state_overlay_id, :artwork_output_type, :product_image_ref,
|
10
|
+
:has_texture_png, :has_model_dae, :has_webgl_model_dae, :parent_id,
|
11
|
+
:has_reflection_model_dae, :creator_user_id, :background_image_ref,
|
12
|
+
:space_conversion_product, :base_product, :snapshot_small_url,
|
13
|
+
:snapshot_large_url, :bespoke_image_url, :background_image_url,
|
14
|
+
:acl_can_write, :supplier_name, :supplier_company_ref_id, :supplier_type,
|
15
|
+
:supplier_company_name, :supplier_customer_ref_id, :creator_user_username
|
16
|
+
|
17
|
+
def initialize(params)
|
18
|
+
self.id = params['id'] || ''
|
19
|
+
self.ref = params['ref'] || ''
|
20
|
+
self.name = params['name'] || ''
|
21
|
+
self.retail_sku = params['retail_sku'] || ''
|
22
|
+
self.product_code = params['productCode'] || ''
|
23
|
+
self.machine_type = params['machine_type'] || ''
|
24
|
+
self.space = params['space'] || ''
|
25
|
+
self.is_locked = params['is_locked'] || ''
|
26
|
+
self.load_count = params['load_count'] || ''
|
27
|
+
self.last_load = params['last_load'] || ''
|
28
|
+
self.last_modified = params['last_modified'] || ''
|
29
|
+
self.print_job_count = params['print_job_count'] || ''
|
30
|
+
self.product_sample_count = params['product_sample_count'] || ''
|
31
|
+
self.date_created = params['date_created'] || ''
|
32
|
+
self.type = params['type'] || ''
|
33
|
+
self.legacy_3d = params['legacy_3d'] || ''
|
34
|
+
self.default_app = params['default_app'] || ''
|
35
|
+
self.default_app_config = params['default_app_config'] || ''
|
36
|
+
self.default_app_locale = params['default_app_locale'] || ''
|
37
|
+
self.default_app_pc = params['default_app_pc'] || ''
|
38
|
+
self.default_app_g = params['default_app_g'] || ''
|
39
|
+
self.default_app_ddp = params['default_app_ddp'] || ''
|
40
|
+
self.default_app_dd = params['default_app_dd'] || ''
|
41
|
+
self.always_use_px = params['always_use_px'] || ''
|
42
|
+
self.base_product_id = params['base_product_id'] || ''
|
43
|
+
self.base_stock_product_id = params['base_stock_product_id'] || ''
|
44
|
+
self.product_state_overlay_id = params['product_state_overlay_id'] || ''
|
45
|
+
self.artwork_output_type = params['artwork_output_type'] || ''
|
46
|
+
self.product_image_ref = params['product_image_ref'] || ''
|
47
|
+
self.has_texture_png = params['has_texture_png'] || ''
|
48
|
+
self.has_model_dae = params['has_model_dae'] || ''
|
49
|
+
self.has_webgl_model_dae = params['has_webgl_model_dae'] || ''
|
50
|
+
self.has_reflection_model_dae = params['has_reflection_model_dae'] || ''
|
51
|
+
self.background_image_ref = params['background_image_ref'] || ''
|
52
|
+
self.creator_user_id = params['creator_user_id'] || ''
|
53
|
+
self.parent_id = params['parent_id'] || ''
|
54
|
+
self.space_conversion_product = params['space_conversion_product'] || ''
|
55
|
+
self.base_product = params['base_product'] || ''
|
56
|
+
self.supplier_name = params['supplierName'] || ''
|
57
|
+
self.supplier_company_ref_id = params['supplier_company_ref_id'] || ''
|
58
|
+
|
59
|
+
self.snapshot_small_url = ''
|
60
|
+
self.snapshot_large_url = ''
|
61
|
+
if params.key?('snapshots')
|
62
|
+
self.snapshot_small_url = params['snapshots']['small'] || ''
|
63
|
+
self.snapshot_large_url = params['snapshots']['large'] || ''
|
64
|
+
end
|
65
|
+
|
66
|
+
self.bespoke_image_url = ''
|
67
|
+
if params.key?('bespoke_image')
|
68
|
+
self.bespoke_image_url = params['bespoke_image']['url'] || ''
|
69
|
+
end
|
70
|
+
|
71
|
+
self.background_image_url = ''
|
72
|
+
if params.key?('background_image')
|
73
|
+
self.background_image_url = params['background_image']['url'] || ''
|
74
|
+
end
|
75
|
+
|
76
|
+
self.acl_can_write = ''
|
77
|
+
if params.key?('acl')
|
78
|
+
self.acl_can_write = params['acl']['can_write'] || ''
|
79
|
+
end
|
80
|
+
|
81
|
+
self.supplier_company_name = ''
|
82
|
+
self.supplier_customer_ref_id = ''
|
83
|
+
self.supplier_type = ''
|
84
|
+
if params.key?('supplier')
|
85
|
+
self.supplier_company_name = params['supplier']['company_name'] || ''
|
86
|
+
self.supplier_customer_ref_id = params['supplier']['customer_ref_id'] || ''
|
87
|
+
self.supplier_type = params['supplier']['type'] || ''
|
88
|
+
end
|
89
|
+
|
90
|
+
self.creator_user_username = ''
|
91
|
+
if params.key?('creator_user')
|
92
|
+
self.creator_user_username = params['creator_user']['username'] || ''
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CustomGateway
|
2
|
+
class Base
|
3
|
+
|
4
|
+
API_INTERNAL_LOGIN = "/apis/internal/login"
|
5
|
+
API_INTERNAL_GRAPHQL = "/apis/internal/graphql"
|
6
|
+
|
7
|
+
attr_accessor :http_client
|
8
|
+
attr_accessor :g3d_cppoms
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.http_client = Faraday.new('https://cpp.custom-gateway.net/v2') do |b|
|
12
|
+
b.request :json
|
13
|
+
b.response :json, content_type: 'application/json'
|
14
|
+
b.adapter Faraday.default_adapter
|
15
|
+
end
|
16
|
+
|
17
|
+
auth!
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def auth!
|
23
|
+
username = CustomGateway.configuration.username
|
24
|
+
password = CustomGateway.configuration.password
|
25
|
+
|
26
|
+
response = http_client.post(API_INTERNAL_LOGIN, { 'username': username, 'password' => password })
|
27
|
+
if response.status == 200
|
28
|
+
self.g3d_cppoms = response.headers['set-cookie']
|
29
|
+
http_client.headers['Cookie'] = g3d_cppoms
|
30
|
+
else
|
31
|
+
raise CustomGateway::AuthError, "Auth failed: #{response.body['error']['message']}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def auth_failure?(response)
|
36
|
+
response.body.key?('error') && response.body['error']['message'] == 'Authentication required'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module CustomGateway
|
4
|
+
module CPP
|
5
|
+
class Categories < Base
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.all
|
9
|
+
instance.all
|
10
|
+
end
|
11
|
+
|
12
|
+
def all
|
13
|
+
params = {
|
14
|
+
"query": "fragment pages on PaginatorInterface {\npages {\npageCount\nitemCountPerPage\nfirst\ncurrent\nlast\nnext\nfirstPageInRange\nlastPageInRange\ncurrentItemCount\ntotalItemCount\nfirstItemNumber\nlastItemNumber\npagesInRange\n}\n}\nquery paginator($filter: Json, $order: Json, $page: Int, $count: Int) {\npaginator: product_categories(filter: $filter, order: $order, page: $page, count: $count) {\n... pages,\n\nitems {\nid, name, full_path\n}\n}\n}",
|
15
|
+
"variables": {
|
16
|
+
"order": {
|
17
|
+
"full_path": "ASC"
|
18
|
+
},
|
19
|
+
"count": 100,
|
20
|
+
"page": 1
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
response = http_client.post(API_INTERNAL_GRAPHQL, params)
|
25
|
+
if response.status == 200
|
26
|
+
categories = []
|
27
|
+
response.body['data']['paginator']['items'].each { |c| categories << CustomGateway::Category.new(c) }
|
28
|
+
|
29
|
+
{
|
30
|
+
pages: response.body['data']['paginator']['pages'],
|
31
|
+
categories: categories
|
32
|
+
}
|
33
|
+
else
|
34
|
+
if auth_failure?(response)
|
35
|
+
self.auth!
|
36
|
+
self.all
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module CustomGateway
|
4
|
+
module CPP
|
5
|
+
class Products < Base
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.all(category: nil, term: nil)
|
9
|
+
instance.all(category, term)
|
10
|
+
end
|
11
|
+
|
12
|
+
def all(category, term)
|
13
|
+
filter = {
|
14
|
+
"type_flags": {
|
15
|
+
"8": nil,
|
16
|
+
"32": nil,
|
17
|
+
"64": nil,
|
18
|
+
"128": nil,
|
19
|
+
"256": nil,
|
20
|
+
"512": nil,
|
21
|
+
"1024": nil,
|
22
|
+
"2048": nil,
|
23
|
+
"4096": nil
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
filter['category_id'] = category unless category.nil?
|
28
|
+
filter['term'] = term unless term.nil?
|
29
|
+
|
30
|
+
params = {
|
31
|
+
"query": "fragment pages on PaginatorInterface {\npages {\npageCount\nitemCountPerPage\nfirst\ncurrent\nlast\nnext\nfirstPageInRange\nlastPageInRange\ncurrentItemCount\ntotalItemCount\nfirstItemNumber\nlastItemNumber\npagesInRange\n}\n}\nquery paginator($filter: Json, $order: Json, $page: Int, $count: Int) {\npaginator: products(filter: $filter, order: $order, page: $page, count: $count) {\n... pages,\n\nitems {\n\nid\nref\nbase_product_id\nname\nproductCode\nretail_sku\nsupplierName\nis_locked\ntype\n\nlegacy_3d {\ntexture_map_url\nmodel_url\nreflection_model_url\nwebgl_model_url\n}\n\nbase_product {\nid\nname\nproductCode\nsupplierName\nmachine_type\n}\n\nbase_stock_product {\nid\nname\nproductCode\nsupplierName\n}\n\nsnapshots { small, large }\nbespoke_image { url }\n\n}\n}\n}",
|
32
|
+
"variables": {
|
33
|
+
"filter": filter,
|
34
|
+
"order": {
|
35
|
+
"id": "DESC"
|
36
|
+
},
|
37
|
+
"count": 20,
|
38
|
+
"page": 1
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
response = http_client.post(API_INTERNAL_GRAPHQL, params)
|
43
|
+
if response.status == 200
|
44
|
+
products = []
|
45
|
+
response.body['data']['paginator']['items'].each { |p| products << CustomGateway::Product.new(p) }
|
46
|
+
|
47
|
+
{
|
48
|
+
pages: response.body['data']['paginator']['pages'],
|
49
|
+
products: products
|
50
|
+
}
|
51
|
+
else
|
52
|
+
if auth_failure?(response)
|
53
|
+
self.auth!
|
54
|
+
self.all
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find(id)
|
60
|
+
instance.find(id)
|
61
|
+
end
|
62
|
+
|
63
|
+
def find(id)
|
64
|
+
params = {
|
65
|
+
"query": "query($id: ID!) {\nproduct(id: $id) {\nid,ref,name,supplierName,retail_sku,productCode,machine_type,supplier_company_ref_id,space,is_locked,load_count,last_load,last_modified,print_job_count,product_sample_count,date_created,type,default_app,default_app_config,default_app_locale,default_app_pc,default_app_g,default_app_ddp,default_app_dd,always_use_px,base_product_id,base_stock_product_id,product_state_overlay_id,artwork_output_type,product_image_ref,has_texture_png,has_model_dae,has_webgl_model_dae,has_reflection_model_dae,background_image_ref,creator_user_id,parent_id,space_conversion_product\n\nbase_product {\nid,ref,name,supplierName,retail_sku,productCode,machine_type,supplier_company_ref_id,space,is_locked,load_count,last_load,last_modified,print_job_count,product_sample_count,date_created,type,default_app,default_app_config,default_app_locale,default_app_pc,default_app_g,default_app_ddp,default_app_dd,always_use_px,base_product_id,base_stock_product_id,product_state_overlay_id,artwork_output_type,product_image_ref,has_texture_png,has_model_dae,has_webgl_model_dae,has_reflection_model_dae,background_image_ref,creator_user_id,parent_id,space_conversion_product\n\nsupplier {\ncompany_name\ncustomer_ref_id\ntype\n}\n}\n\nbespoke_image { url }\n\nbackground_image { url }\n\nacl {\ncan_write\n},\n\nsupplier {\ncompany_name\ncustomer_ref_id\ntype\n}\n\ncreator_user {\nusername\n}\n}\n}",
|
66
|
+
"variables": {
|
67
|
+
"id": id
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
response = http_client.post(API_INTERNAL_GRAPHQL, params)
|
72
|
+
if response.status == 200
|
73
|
+
CustomGateway::Product.new(response.body['data']['product'])
|
74
|
+
else
|
75
|
+
if auth_failure?(response)
|
76
|
+
self.auth!
|
77
|
+
self.find(id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: custom_gateway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- João Ricardo Bastos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- joaoricardobastos@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/custom_gateway.rb
|
91
|
+
- lib/custom_gateway/configuration.rb
|
92
|
+
- lib/custom_gateway/errors/auth_error.rb
|
93
|
+
- lib/custom_gateway/models/category.rb
|
94
|
+
- lib/custom_gateway/models/product.rb
|
95
|
+
- lib/custom_gateway/services/base.rb
|
96
|
+
- lib/custom_gateway/services/categories.rb
|
97
|
+
- lib/custom_gateway/services/products.rb
|
98
|
+
- lib/custom_gateway/version.rb
|
99
|
+
homepage: https://github.com/joaozig/custom-gateway-sdk
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
allowed_push_host: https://rubygems.org/
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.6.13
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Unofficial ruby's custom_gateway sdk
|
124
|
+
test_files: []
|