custom_gateway 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f6b8ec6698a62326d18d984364cd50a44c530817
4
- data.tar.gz: ebe8a154c1b173bdf38aee2ef6b55b9fdcca1b37
2
+ SHA256:
3
+ metadata.gz: 24a501a729536ca5cbe4c359ad30e38f4747098ef3922f434a1e89a720ca446f
4
+ data.tar.gz: 418b5aecd25b73ed641daa3428ae238ea8ffbfcf155ac4cd538b88ca961ec8ff
5
5
  SHA512:
6
- metadata.gz: 8b8218c4676c9e588e9ae43c446f3129ad14dd7c3bec439e5a3872f20c4813a121a74fba4192a822a602158fa32ea18cb1847e234357fec7cb01988f705dd425
7
- data.tar.gz: 425c428edffaf72cac7430689dd52bdbb2ccda22049c5fa0538f3bd2518d65548f060b0bfaff72a9803da4ecbe46a6c550a0ed30a073c9ed273abc6c7fd4d9e1
6
+ metadata.gz: ca10dfc3fffd4befb10b99999122291551dc9dfb30845b7d67d42bdf1c3f328f75f7f91785d4a66fa2f0cb6f4f1724b61accea399a137ed79f006e76fac3d638
7
+ data.tar.gz: 3785270600627f846a1cd9d18fa69743ee98e28bd96e9c406cdfbe1772fbdc6984f5fe99ecc0e206fa477e957311029541a6e3ab4e79cf12c4b4d4fbf8b1f5de
@@ -5,6 +5,66 @@ module CustomGateway
5
5
  class Products < Base
6
6
  include Singleton
7
7
 
8
+ def self.query(variables)
9
+ instance.query(variables)
10
+ end
11
+
12
+ def query(variables)
13
+ payload = {
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: 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}",
15
+ "variables": variables
16
+ }
17
+
18
+ response = http_client.post(API_INTERNAL_GRAPHQL, payload)
19
+ if response.status == 200
20
+ products = []
21
+ response.body['data']['paginator']['items'].each { |p| products << CustomGateway::Product.new(p) }
22
+
23
+ {
24
+ pages: response.body['data']['paginator']['pages'],
25
+ products: products
26
+ }
27
+ else
28
+ if auth_failure?(response)
29
+ self.auth!
30
+ self.query(variables)
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.blank(page: 1, count: 20)
36
+ instance.blank(page, count)
37
+ end
38
+
39
+ def blank(page, count)
40
+ filter = {
41
+ "type_flags": {
42
+ "8": nil,
43
+ "32": nil,
44
+ "64": nil,
45
+ "128": nil,
46
+ "256": nil,
47
+ "512": nil,
48
+ "1024": nil,
49
+ "2048": nil,
50
+ "4096": true # blank type
51
+ }
52
+ }
53
+
54
+ filter['type'] = '4096'
55
+
56
+ variables = {
57
+ "filter": filter,
58
+ "order": {
59
+ "id": "DESC"
60
+ },
61
+ "count": count,
62
+ "page": page
63
+ }
64
+
65
+ self.query(variables)
66
+ end
67
+
8
68
  def self.all(category: nil, term: nil)
9
69
  instance.all(category, term)
10
70
  end
@@ -27,33 +87,16 @@ module CustomGateway
27
87
  filter['category_id'] = category unless category.nil?
28
88
  filter['term'] = term unless term.nil?
29
89
 
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
- }
90
+ variables = {
91
+ "filter": filter,
92
+ "order": {
93
+ "id": "DESC"
94
+ },
95
+ "count": 20,
96
+ "page": 1
40
97
  }
41
98
 
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
99
+ self.query(variables)
57
100
  end
58
101
 
59
102
  def self.find(id)
@@ -1,3 +1,3 @@
1
1
  module CustomGateway
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Ricardo Bastos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.6.13
120
+ rubygems_version: 2.7.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Unofficial ruby's custom_gateway sdk