customerx_tracking 1.0.0 → 2.0.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 +4 -4
- data/lib/customerx_tracking/base.rb +24 -0
- data/lib/customerx_tracking/requestor.rb +22 -0
- data/lib/customerx_tracking/tracker.rb +7 -0
- data/lib/customerx_tracking/version.rb +1 -1
- data/lib/customerx_tracking.rb +50 -4
- metadata +8 -7
- data/lib/customerx_tracking/client.rb +0 -32
- data/lib/customerx_tracking/configuration.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f5db5d0d8185cb42c3968df3cf4cbd3c2ff2d36d395859d7f899b319d62870b
|
4
|
+
data.tar.gz: dc3ef6f2ae4cbd8545381175559d1346ee75e36fb0697a12760a02523a84d8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11afbdbd44dc8b17c5c3b00f86c1ea69cf88eb0f290c563cab7e617318d2c12a52b02e401fd732081ddf87e922d75b57f5027c7e5dce2d12c99aef7a0ebec8fc
|
7
|
+
data.tar.gz: c404db573b9be5e3cad8fb6c8643bea68b136c4e57ba7bc44a2e99e66dceb417c73478a08d883550cba8de8a56da9ad33c3df60df5c7f82e680b63b14de35390
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CustomerxTracking
|
2
|
+
class Base
|
3
|
+
def connection
|
4
|
+
@connection ||= Faraday.new(faraday_options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def authorizations_is_not_present?
|
8
|
+
::CustomerxTracking.credential.nil? || ::CustomerxTracking.key.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def faraday_options
|
14
|
+
{
|
15
|
+
headers: {
|
16
|
+
accept: "application/json",
|
17
|
+
credential: ::CustomerxTracking.credential,
|
18
|
+
key: ::CustomerxTracking.key
|
19
|
+
},
|
20
|
+
url: ::CustomerxTracking.base_url
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CustomerxTracking
|
2
|
+
class Requestor < Base
|
3
|
+
def initialize
|
4
|
+
raise 'credential and key should be set' if authorizations_is_not_present?
|
5
|
+
end
|
6
|
+
|
7
|
+
def request(meth, params = nil)
|
8
|
+
meth = meth.downcase
|
9
|
+
|
10
|
+
begin
|
11
|
+
response = connection.method(meth).call do |req|
|
12
|
+
(if meth == :get then req.params = params else req.body = params end) if params
|
13
|
+
end
|
14
|
+
rescue
|
15
|
+
raise 'it was not possible to carry out the request'
|
16
|
+
end
|
17
|
+
|
18
|
+
p response
|
19
|
+
{ status: response.status, body: JSON.parse(response.body) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/customerx_tracking.rb
CHANGED
@@ -1,7 +1,53 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
# Module main of CustomerX Tracking
|
2
|
+
module CustomerxTracking
|
3
|
+
@base_url = 'https://tracking.customerx.com.br/api/v1/trackings'
|
4
|
+
@credential
|
5
|
+
@key
|
6
|
+
@authorization
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
yield self
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.base_url
|
13
|
+
@base_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.base_url=(base_url)
|
17
|
+
@base_url = base_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.credential
|
21
|
+
@credential
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.credential=(credential)
|
25
|
+
@credential = credential
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.key
|
29
|
+
@key
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.key=(key)
|
33
|
+
@key = key
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.authorization
|
37
|
+
@authorization
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.authorization=(authorization)
|
41
|
+
@authorization = authorization
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
require 'faraday'
|
46
|
+
require 'json'
|
4
47
|
|
5
|
-
|
48
|
+
# Core
|
49
|
+
require 'customerx_tracking/base'
|
50
|
+
require 'customerx_tracking/requestor'
|
6
51
|
|
7
|
-
|
52
|
+
# Tracker
|
53
|
+
require 'customerx_tracking/tracker'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customerx_tracking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Grassi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,16 +39,17 @@ extensions: []
|
|
39
39
|
extra_rdoc_files: []
|
40
40
|
files:
|
41
41
|
- lib/customerx_tracking.rb
|
42
|
-
- lib/customerx_tracking/
|
43
|
-
- lib/customerx_tracking/
|
42
|
+
- lib/customerx_tracking/base.rb
|
43
|
+
- lib/customerx_tracking/requestor.rb
|
44
|
+
- lib/customerx_tracking/tracker.rb
|
44
45
|
- lib/customerx_tracking/version.rb
|
45
|
-
homepage: https://
|
46
|
+
homepage: https://github.com/CustomerX-CX/customerx_tracking_client_rb
|
46
47
|
licenses:
|
47
48
|
- MIT
|
48
49
|
metadata:
|
49
50
|
bug_tracker_uri: https://github.com/CustomerX-CX/customerx_tracking_client_rb/issues
|
50
|
-
changelog_uri: https://github.com/CustomerX-CX/customerx_tracking_client_rb/CHANGELOG.md
|
51
|
-
|
51
|
+
changelog_uri: https://github.com/CustomerX-CX/customerx_tracking_client_rb/blob/master/CHANGELOG.md
|
52
|
+
releases_uri: https://github.com/CustomerX-CX/customerx_tracking_client_rb/releases/tag/2.0.0
|
52
53
|
post_install_message:
|
53
54
|
rdoc_options: []
|
54
55
|
require_paths:
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "faraday"
|
2
|
-
|
3
|
-
require "customerx_tracking/configuration"
|
4
|
-
|
5
|
-
module CustomerxTracking
|
6
|
-
class Client
|
7
|
-
# @return [Configuration] Config instance
|
8
|
-
attr_reader :config
|
9
|
-
|
10
|
-
# Creates a new {Client} instance and yields {#config}.
|
11
|
-
def initialize
|
12
|
-
raise ArgumentError, "block not given" unless block_given?
|
13
|
-
|
14
|
-
@config = CustomerxTracking::Configuration.new
|
15
|
-
yield config
|
16
|
-
end
|
17
|
-
|
18
|
-
# Send tracking of API Tracking CustomerX
|
19
|
-
def tracker(external_id_client:, type_tracking:, identifier:, email:, options: {})
|
20
|
-
Faraday.new.post do |req|
|
21
|
-
req.url "https://tracking.customerx.com.br/api/v1/trackings"
|
22
|
-
req.headers = @config.options[:headers]
|
23
|
-
req.body = {
|
24
|
-
external_id_client: external_id_client,
|
25
|
-
type_tracking: type_tracking,
|
26
|
-
identifier: identifier,
|
27
|
-
email: email
|
28
|
-
}.merge(options)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module CustomerxTracking
|
2
|
-
# Holds the configuration options for the client and connection
|
3
|
-
class Configuration
|
4
|
-
# @return [String] The basic auth credential.
|
5
|
-
attr_accessor :credential
|
6
|
-
|
7
|
-
# @return [String] The basic auth key.
|
8
|
-
attr_accessor :key
|
9
|
-
|
10
|
-
# Sets accept and user_agent headers
|
11
|
-
#
|
12
|
-
# @return [Hash] Faraday-formatted hash of options.
|
13
|
-
def options
|
14
|
-
{
|
15
|
-
headers: {
|
16
|
-
accept: "application/json",
|
17
|
-
credential: @credential,
|
18
|
-
key: @key
|
19
|
-
}
|
20
|
-
}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|