dooca_commerce 1.0.1 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb05b281b4833e7e98c7f4c4557d72324132191638cd7bbc6abfc256e12b48ec
4
- data.tar.gz: fb8e384411649ca865657a0cc9845901b44464ddf0ddea3ff477365e0beb738d
3
+ metadata.gz: 43b4d0da62e063f804c9a223ed013a18c113e1869ab1602207bf1d9cb71bb404
4
+ data.tar.gz: e2c48b41fb5990d95467308cf2a5558ad31ed2817612833b4cb607744e78d721
5
5
  SHA512:
6
- metadata.gz: 809b7d6bc5f214db09999fa34834f0df8d5ee66c435e76666d1d4d6f2f2ecd8ad249ac9654355976c85ea0cdc348740edf01128b6b8d068ea45603f83ffadad2
7
- data.tar.gz: 8c9cc86a2db205966e8fcc2441de4ed11d82ff30ce791e52c121384bbbf0d82fd923a419a8679c9a5f6fe8d9e6c0e8709b7ee681ac152119ad8164e76fed46d6
6
+ metadata.gz: 681e5bf4e585c6b013b9961508b37be6d6609a1c47ba176146288be9cea73bbac903819cd912c08e9c74ca9367638c56002a1b5efd6afd68ec564c249dfd0371
7
+ data.tar.gz: db094d2bdbb06604ba0bfb84dd48330c11bd966c0c60d43481f53ad29060012027f0fa95ea1c446de19c9cb853a64cd4ac3cd5f848329e3b895fa63f2b814a4a
@@ -34,12 +34,156 @@ class DoocaCommerce
34
34
  handler.new(response, single_from_list: true).parse!
35
35
  end
36
36
 
37
- def update_stock_and_price(product_id:, body:)
37
+ def fetch_categories(query = {})
38
+ response = connection.get("/categories", query)
39
+
40
+ handler.new(response).parse!
41
+ end
42
+
43
+ def fetch_category(category_id:)
44
+ response = connection.get("/categories/#{category_id}")
45
+
46
+ handler.new(response).parse!
47
+ end
48
+
49
+ def fetch_orders(query = {})
50
+ response = connection.get("/orders", query)
51
+
52
+ handler.new(response).parse!
53
+ end
54
+
55
+ def fetch_order(order_id:)
56
+ response = connection.get("/orders/#{order_id}")
57
+
58
+ handler.new(response).parse!
59
+ end
60
+
61
+ def fetch_colors(query = {})
62
+ response = connection.get("/colors", query)
63
+
64
+ handler.new(response).parse!
65
+ end
66
+
67
+ def fetch_brands(query = {})
68
+ response = connection.get("/brands", query)
69
+
70
+ handler.new(response).parse!
71
+ end
72
+
73
+ def fetch_attributes(query = {})
74
+ response = connection.get("/attributes", query)
75
+
76
+ handler.new(response).parse!
77
+ end
78
+
79
+ def create_product(body)
80
+ response = connection.post("/products", body.to_json)
81
+
82
+ handler.new(response).parse!
83
+ end
84
+
85
+ def update_product(product_id:, body:)
38
86
  response = connection.put("/products/#{product_id}", body.to_json)
39
87
 
40
88
  handler.new(response).parse!
41
89
  end
42
90
 
91
+ def create_variation(body)
92
+ response = connection.post("/variations", body.to_json)
93
+
94
+ handler.new(response).parse!
95
+ end
96
+
97
+ def update_variation(variation_id:, body:)
98
+ response = connection.put("/variations/#{variation_id}", body.to_json)
99
+
100
+ handler.new(response).parse!
101
+ end
102
+
103
+ def create_category(body)
104
+ response = connection.post("/categories", body.to_json)
105
+
106
+ handler.new(response).parse!
107
+ end
108
+
109
+ def update_category(category_id:, body:)
110
+ response = connection.put("/categories/#{category_id}", body.to_json)
111
+
112
+ handler.new(response).parse!
113
+ end
114
+
115
+ def create_brand(body)
116
+ response = connection.post("/brands", body.to_json)
117
+
118
+ handler.new(response).parse!
119
+ end
120
+
121
+ def update_brand(brand_id:, body:)
122
+ response = connection.put("/brands/#{brand_id}", body.to_json)
123
+
124
+ handler.new(response).parse!
125
+ end
126
+
127
+ def create_color(body)
128
+ response = connection.post("/colors", body.to_json)
129
+
130
+ handler.new(response).parse!
131
+ end
132
+
133
+ def update_color(color_id:, body:)
134
+ response = connection.put("/colors/#{color_id}", body.to_json)
135
+
136
+ handler.new(response).parse!
137
+ end
138
+
139
+ def create_attribute(body)
140
+ response = connection.post("/attributes", body.to_json)
141
+
142
+ handler.new(response).parse!
143
+ end
144
+
145
+ def update_attribute(attribute_id:, body:)
146
+ response = connection.put("/attributes/#{attribute_id}", body.to_json)
147
+
148
+ handler.new(response).parse!
149
+ end
150
+
151
+ def create_attribute_value(body)
152
+ response = connection.post("/attributes/values", body.to_json)
153
+
154
+ handler.new(response).parse!
155
+ end
156
+
157
+ def update_attribute_value(attribute_value_id:, body:)
158
+ response = connection.put("/attributes/values/#{attribute_value_id}", body.to_json)
159
+
160
+ handler.new(response).parse!
161
+ end
162
+
163
+ def create_fulfillment(order_id:)
164
+ response = connection.post("/orders/#{order_id}/fulfillment")
165
+
166
+ handler.new(response).parse!
167
+ end
168
+
169
+ def update_invoice(order_id:, body:)
170
+ response = connection.put("/orders/#{order_id}/fulfillment/invoiced", body.to_json)
171
+
172
+ handler.new(response).parse!
173
+ end
174
+
175
+ def update_tracking(order_id:, body:)
176
+ response = connection.put("/orders/#{order_id}/fulfillment/shipped", body.to_json)
177
+
178
+ handler.new(response).parse!
179
+ end
180
+
181
+ def mark_as_delivered(order_id:)
182
+ response = connection.put("/orders/#{order_id}/fulfillment/delivered")
183
+
184
+ handler.new(response).parse!
185
+ end
186
+
43
187
  private
44
188
 
45
189
  URL = "https://api.dooca.store"
@@ -0,0 +1,37 @@
1
+ class ResponseHandler
2
+
3
+ def initialize(response, single_from_list: false)
4
+ @response = response
5
+ @single_from_list = single_from_list
6
+ end
7
+
8
+ attr_reader :response, :single_from_list
9
+
10
+ def parse!
11
+ success? ? handle_success : handle_error
12
+ end
13
+
14
+ private
15
+
16
+ def handle_success
17
+ @payload = payload.data.first if single_from_list
18
+
19
+ payload.success = true
20
+
21
+ payload
22
+ end
23
+
24
+ def handle_error
25
+ payload.success = false
26
+
27
+ payload
28
+ end
29
+
30
+ def payload
31
+ @payload ||= JSON.parse(response.body, object_class: OpenStruct)
32
+ end
33
+
34
+ def success?
35
+ single_from_list ? payload.data&.first.present? : (200..204).include?(response.status)
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dooca_commerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Cesar Cordeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-27 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -31,6 +31,7 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/dooca_commerce.rb
34
+ - lib/response_handler.rb
34
35
  homepage: https://rubygems.org/gems/doca_commerce
35
36
  licenses:
36
37
  - MIT