dooca_commerce 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dooca_commerce.rb +54 -2
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 847b94bb2b5eeccc601e7ea0c809f686a42142212b6ddd27cc35cf09dc42c5fa
4
- data.tar.gz: 415a7f99123aa96c5c42568e62a0c43ccbb2771f58263339667a320bcccd4579
3
+ metadata.gz: fb05b281b4833e7e98c7f4c4557d72324132191638cd7bbc6abfc256e12b48ec
4
+ data.tar.gz: fb8e384411649ca865657a0cc9845901b44464ddf0ddea3ff477365e0beb738d
5
5
  SHA512:
6
- metadata.gz: 1127f0083c39c595efd2de8791de642fe04adfee9cc2778fc44e70a1269ca34d0c05023fccfdd9002fad55cfa2149fe76863cd55c93e52ac6c0e250d64b57b78
7
- data.tar.gz: 9fcc3ebc6c6af3b9fa0002f7e80d61482067998b2a16f3857e8b2b15fc0a98f1794a95510b2609470bf4c9575c7feb844d401698795073aaab009ad0264c9f5a
6
+ metadata.gz: 809b7d6bc5f214db09999fa34834f0df8d5ee66c435e76666d1d4d6f2f2ecd8ad249ac9654355976c85ea0cdc348740edf01128b6b8d068ea45603f83ffadad2
7
+ data.tar.gz: 8c9cc86a2db205966e8fcc2441de4ed11d82ff30ce791e52c121384bbbf0d82fd923a419a8679c9a5f6fe8d9e6c0e8709b7ee681ac152119ad8164e76fed46d6
@@ -1,5 +1,57 @@
1
+ require 'faraday'
2
+ require 'response_handler'
3
+
1
4
  class DoocaCommerce
2
- def self.hi
3
- puts "Hello world!"
5
+
6
+ def initialize(token:)
7
+ @token = token
8
+ @handler = ResponseHandler
9
+ end
10
+
11
+ attr_reader :token, :handler
12
+
13
+ def fetch_products(query = {})
14
+ response = connection.get("/products", query)
15
+
16
+ handler.new(response).parse!
17
+ end
18
+
19
+ def fetch_product(query = {})
20
+ response = connection.get("/products", query)
21
+
22
+ handler.new(response, single_from_list: true).parse!
23
+ end
24
+
25
+ def fetch_variations(query = {})
26
+ response = connection.get("/variations", query)
27
+
28
+ handler.new(response).parse!
29
+ end
30
+
31
+ def fetch_variation(query = {})
32
+ response = connection.get("/variations", query)
33
+
34
+ handler.new(response, single_from_list: true).parse!
35
+ end
36
+
37
+ def update_stock_and_price(product_id:, body:)
38
+ response = connection.put("/products/#{product_id}", body.to_json)
39
+
40
+ handler.new(response).parse!
41
+ end
42
+
43
+ private
44
+
45
+ URL = "https://api.dooca.store"
46
+
47
+ def headers
48
+ {
49
+ "Content-Type" => "application/json",
50
+ "Authorization": "Bearer #{token}"
51
+ }
52
+ end
53
+
54
+ def connection
55
+ @connection ||= Faraday.new(url: URL, headers: headers)
4
56
  end
5
57
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dooca_commerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-17 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-12-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'
13
27
  description: A Ruby implementation of Dooca Commerce API
14
28
  email: lucianocordeiro1991@hotmail.com
15
29
  executables: []