neomode_client 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 56d4b478bc81ac99b648b9eeae5cb82dcbe7ffa6eaa501644a4358f75d7db327
4
+ data.tar.gz: f8bdc9649a90ff3eb537b5c9e87ec881e008f802d3bfb8252342dc521ce5a5f3
5
+ SHA512:
6
+ metadata.gz: 360bf7a82eeafc9384d793d55dee7088551590aad178968314459552c45a2c53eb3bfd65390042b7fd95a1b7ef555b501a772e3e3e0be0eedbe73abcfe6ff9da
7
+ data.tar.gz: c31255daae73113db615bd0fc0682672d5211c334ce8c06d5fe531e06a0b3dc2adbea92fe0e7a598642795a9fa70386547f4855ad746aa1c995d2d76e6d01e8c
@@ -0,0 +1,43 @@
1
+ module NeomodeClient
2
+ class Api
3
+ include NeomodeClient
4
+
5
+ def initialize(args)
6
+ @token = args[:token]
7
+ @is_production = args[:is_production]
8
+ end
9
+
10
+ def send_products(body)
11
+ response = connection.put("/management/catalog/products", body.to_json)
12
+
13
+ handler.new(response).parse!
14
+ end
15
+
16
+ def update_quantity(body)
17
+ response = connection.put("/management/catalog/stocks", body.to_json)
18
+
19
+ handler.new(response).parse!
20
+ end
21
+
22
+ def update_price(body)
23
+ response = connection.put("/management/catalog/prices", body.to_json)
24
+
25
+ handler.new(response).parse!
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :token, :is_production
31
+
32
+ def connection
33
+ Faraday.new(url: mount_url(is_production), headers: headers)
34
+ end
35
+
36
+ def headers
37
+ {
38
+ "Content-Type" => "application/json",
39
+ "Authorization": "Bearer #{token}"
40
+ }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+
2
+ module NeomodeClient
3
+ class Auth
4
+ include NeomodeClient
5
+
6
+ def initialize(args)
7
+ @client_id = args[:client_id]
8
+ @client_secret = args[:client_secret]
9
+ @is_production = args[:is_production]
10
+ end
11
+
12
+ def self.generate_token(args)
13
+ new(args).generate_token
14
+ end
15
+
16
+ def generate_token
17
+ response = connection.post("/auth/token/anonymous", body.to_json)
18
+
19
+ handler.new(response).parse!
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :client_id, :client_secret, :is_production
25
+
26
+ def body
27
+ {
28
+ clientId: client_id,
29
+ clientSecret: client_secret,
30
+ scope: "lori",
31
+ }
32
+ end
33
+
34
+ def connection
35
+ Faraday.new(url: mount_url(is_production), headers: headers)
36
+ end
37
+
38
+ def headers
39
+ {
40
+ "Content-Type" => "application/json"
41
+ }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ require 'faraday'
2
+ require 'response_handler'
3
+ require 'neomode_client/auth'
4
+ require 'neomode_client/api'
5
+
6
+ module NeomodeClient
7
+ def mount_url(is_production)
8
+ "https://#{is_production ? "api" : "dev-api"}.neomode.com.br"
9
+ end
10
+
11
+ def handler
12
+ ResponseHandler
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ class ResponseHandler
2
+
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ attr_reader :response, :single_from_list
8
+
9
+ def parse!
10
+ success? ? handle_success : handle_error
11
+ end
12
+
13
+ private
14
+
15
+ def handle_success
16
+ payload.success = true
17
+
18
+ payload
19
+ end
20
+
21
+ def handle_error
22
+ payload.success = false
23
+
24
+ payload
25
+ end
26
+
27
+ def payload
28
+ @payload ||= JSON.parse(response.body.presence || "{}", object_class: OpenStruct)
29
+ end
30
+
31
+ def success?
32
+ (200..204).include?(response.status)
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neomode_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luciano Cesar Cordeiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-22 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: A Ruby implementation of Neomode Client API
28
+ email: lucianocordeiro1991@hotmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/neomode_client.rb
34
+ - lib/neomode_client/api.rb
35
+ - lib/neomode_client/auth.rb
36
+ - lib/response_handler.rb
37
+ homepage: https://rubygems.org/gems/neomode_client
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.2.3
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Neomode Client!
60
+ test_files: []