dashx 0.1.1 → 0.1.2
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/dashx/client.rb +65 -16
- data/lib/dashx/config.rb +2 -0
- data/lib/dashx/version.rb +1 -1
- data/lib/dashx.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92167d2944237c5e38d7a961e7667ee28b9d0f1c538ccbcf85e74774f0d069d7
|
4
|
+
data.tar.gz: f60d37b643ca4bc774e07dd2ea0943a40c1f512b8dc567074c3fcb26e024a8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4d621ad99514c4dd92422ead8c0b516312a484c82442eaf76906a4741c0c382fb84be685d2caeae0273d93a539c83737290eed4d9e48fbf33b8639e0746c77
|
7
|
+
data.tar.gz: 794c3c582620a41e44aa1fa0014eb267a33173f42de3c066108e0cd3cf5c39bc7062296f4f2626f0423d313783e1062e0184683237823041d206d83ca033af44
|
data/lib/dashx/client.rb
CHANGED
@@ -3,42 +3,90 @@ require 'httparty'
|
|
3
3
|
module DashX
|
4
4
|
class Client
|
5
5
|
include HTTParty
|
6
|
-
base_uri 'https://api.dashx.com
|
6
|
+
base_uri 'https://api.dashx.com'
|
7
|
+
|
8
|
+
CREATE_DELIVERY_REQUEST = 'mutation CreateDelivery($input: CreateDeliveryInput!) {
|
9
|
+
createDelivery(input: $input) {
|
10
|
+
id
|
11
|
+
}
|
12
|
+
}
|
13
|
+
'
|
14
|
+
|
15
|
+
IDENTIFY_ACCOUNT_REQUEST = 'mutation IdentifyAccount($input: IdentifyAccountInput!) {
|
16
|
+
identifyAccount(input: $input) {
|
17
|
+
id
|
18
|
+
}
|
19
|
+
}
|
20
|
+
'
|
21
|
+
|
22
|
+
TRACK_EVENT_REQUEST = 'mutation TrackEvent($input: TrackEventInput!) {
|
23
|
+
trackEvent(input: $input) {
|
24
|
+
id
|
25
|
+
}
|
26
|
+
}
|
27
|
+
'
|
7
28
|
|
8
29
|
def initialize(config)
|
9
30
|
@config = config
|
10
31
|
|
11
32
|
self.class.base_uri(config.base_uri)
|
12
|
-
|
33
|
+
|
34
|
+
headers = {
|
13
35
|
'X-Public-Key' => config.public_key,
|
14
|
-
'X-Private-Key' => config.private_key
|
15
|
-
}
|
16
|
-
|
36
|
+
'X-Private-Key' => config.private_key,
|
37
|
+
}
|
38
|
+
|
39
|
+
if !config.target_environment.nil?
|
40
|
+
headers['X-Target-Environment'] = config.target_environment
|
41
|
+
end
|
42
|
+
|
43
|
+
if !config.target_installation.nil?
|
44
|
+
headers['X-Target-Installation'] = config.target_installation
|
45
|
+
end
|
46
|
+
|
47
|
+
self.class.headers(headers)
|
48
|
+
end
|
49
|
+
|
50
|
+
def deliver(urn, parcel)
|
51
|
+
options = if urn.is_a? String && parcel != nil
|
52
|
+
symbolize_keys! parcel
|
53
|
+
check_presence!(parcel[:to], 'Recipient (:to)')
|
54
|
+
|
55
|
+
contentTypeIdentifier, contentIdentifier = urn.split('/', 1)
|
17
56
|
|
18
|
-
|
19
|
-
|
57
|
+
{
|
58
|
+
contentTypeIdentifier: contentTypeIdentifier,
|
59
|
+
contentIdentifier: contentIdentifier,
|
60
|
+
attachments: [],
|
61
|
+
cc: [],
|
62
|
+
bcc: [],
|
63
|
+
}.merge(parcel)
|
64
|
+
else
|
65
|
+
symbolize_keys! urn
|
66
|
+
check_presence!(urn[:from], 'Sender (:from)')
|
20
67
|
|
21
|
-
|
68
|
+
{ attachments: [], cc: [], bcc: [] }.merge(urn)
|
69
|
+
end
|
22
70
|
|
23
|
-
|
71
|
+
make_graphql_request(CREATE_DELIVERY_REQUEST, options)
|
24
72
|
end
|
25
73
|
|
26
|
-
def identify(uid, options
|
74
|
+
def identify(uid, options)
|
27
75
|
symbolize_keys! options
|
28
76
|
|
29
|
-
params = if uid.is_a? String
|
77
|
+
params = if uid.is_a? String && options != nil
|
30
78
|
{ uid: uid }.merge(options)
|
31
79
|
else
|
32
|
-
{
|
80
|
+
{ anonymousUid: SecureRandom.uuid }.merge(uid)
|
33
81
|
end
|
34
82
|
|
35
|
-
|
83
|
+
make_graphql_request(IDENTIFY_ACCOUNT_REQUEST, params)
|
36
84
|
end
|
37
85
|
|
38
86
|
def track(event, uid, data = nil)
|
39
87
|
symbolize_keys! data unless data.nil?
|
40
88
|
|
41
|
-
|
89
|
+
make_graphql_request(TRACK_EVENT_REQUEST, { event: event, uid: uid, data: data })
|
42
90
|
end
|
43
91
|
|
44
92
|
def generate_identity_token(uid)
|
@@ -55,8 +103,9 @@ module DashX
|
|
55
103
|
|
56
104
|
private
|
57
105
|
|
58
|
-
def
|
59
|
-
|
106
|
+
def make_graphql_request(request, params)
|
107
|
+
body = { query: request, variables: { input: params } }.to_json
|
108
|
+
request = self.class.post('/graphql', { body: body })
|
60
109
|
end
|
61
110
|
|
62
111
|
def symbolize_keys!(hash)
|
data/lib/dashx/config.rb
CHANGED
data/lib/dashx/version.rb
CHANGED
data/lib/dashx.rb
CHANGED
@@ -11,11 +11,11 @@ module DashX
|
|
11
11
|
@clients[client_name] = DashX::Client.new(config)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.deliver(parcel)
|
15
|
-
@clients[:default].deliver(parcel)
|
14
|
+
def self.deliver(urn, parcel)
|
15
|
+
@clients[:default].deliver(urn, parcel)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.identify(uid
|
18
|
+
def self.identify(uid, options)
|
19
19
|
@clients[:default].identify(uid, options)
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dashx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DashX
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|