dashx 0.1.2 → 0.3.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/README.md +23 -2
- data/lib/dashx/client.rb +52 -28
- data/lib/dashx/version.rb +1 -1
- data/lib/dashx.rb +5 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ad40758bc5f6cd2a2112d112e5d5f89116236223d49d4f587e4e5b3e1fec29
|
4
|
+
data.tar.gz: 1e69514d594c29381d72bb39fa88601b19c8172344fee5cd09f23f815d2d9fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8259173a1f98ea91ebd618ce630c7852bc5e95d2088e250a52867aa24dbdc4a20267c30566d4c972c525bd455737010d3a7fae8accb93bc188f98eebd2d1893
|
7
|
+
data.tar.gz: 1ed90ead1e57ac5d62caebe5717469af66e01dc44b6ccc083511d102919cfd94b4decf57263620c0eb97f9c94fa532b05f71cd0878f77023d3314f81e6af4a0a
|
data/README.md
CHANGED
@@ -89,9 +89,30 @@ DashX.track('event_name', 'uid_of_user', { hello: 'world' })
|
|
89
89
|
|
90
90
|
## Development
|
91
91
|
|
92
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
92
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
93
93
|
|
94
|
-
|
94
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
95
|
+
|
96
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
97
|
+
|
98
|
+
# Publishing
|
99
|
+
|
100
|
+
We use the amazing [gem-release](https://github.com/svenfuchs/gem-release) for releases.
|
101
|
+
|
102
|
+
**Installation**
|
103
|
+
|
104
|
+
```
|
105
|
+
gem install gem-release
|
106
|
+
```
|
107
|
+
|
108
|
+
**Deploying a new version**
|
109
|
+
|
110
|
+
```
|
111
|
+
git checkout master // Ensure you're in the master branch
|
112
|
+
gem bump -v minor // Automatically sets the version number, commits
|
113
|
+
git push origin master // Push the version bump commit
|
114
|
+
gem release
|
115
|
+
```
|
95
116
|
|
96
117
|
## Contributing
|
97
118
|
|
data/lib/dashx/client.rb
CHANGED
@@ -26,6 +26,15 @@ module DashX
|
|
26
26
|
}
|
27
27
|
'
|
28
28
|
|
29
|
+
SAVE_CONTACTS_REQUEST = 'mutation SaveContacts($input: SaveContactsInput!) {
|
30
|
+
saveContacts(input: $input) {
|
31
|
+
contacts {
|
32
|
+
id
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
'
|
37
|
+
|
29
38
|
def initialize(config)
|
30
39
|
@config = config
|
31
40
|
|
@@ -45,36 +54,36 @@ module DashX
|
|
45
54
|
end
|
46
55
|
|
47
56
|
self.class.headers(headers)
|
48
|
-
end
|
49
|
-
|
50
|
-
def deliver(urn,
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
make_graphql_request(CREATE_DELIVERY_REQUEST,
|
57
|
+
end
|
58
|
+
|
59
|
+
def deliver(urn, options)
|
60
|
+
contentTypeIdentifier, contentIdentifier = urn.split(/\//, 2)
|
61
|
+
|
62
|
+
options ||= {}
|
63
|
+
|
64
|
+
symbolize_keys! options
|
65
|
+
|
66
|
+
options[:content] ||= {}
|
67
|
+
|
68
|
+
[:to, :cc, :bcc].each do |kind|
|
69
|
+
value = options.delete(kind)
|
70
|
+
|
71
|
+
options[:content][kind] ||= value if value
|
72
|
+
options[:content][kind] = wrap_array(options[:content][kind]) if options[:content][kind]
|
73
|
+
end
|
74
|
+
|
75
|
+
params = {
|
76
|
+
contentTypeIdentifier: contentTypeIdentifier,
|
77
|
+
contentIdentifier: contentIdentifier
|
78
|
+
}.merge(options)
|
79
|
+
|
80
|
+
make_graphql_request(CREATE_DELIVERY_REQUEST, params)
|
72
81
|
end
|
73
82
|
|
74
83
|
def identify(uid, options)
|
75
84
|
symbolize_keys! options
|
76
85
|
|
77
|
-
params = if uid.is_a?
|
86
|
+
params = if uid.is_a?(String) && options != nil
|
78
87
|
{ uid: uid }.merge(options)
|
79
88
|
else
|
80
89
|
{ anonymousUid: SecureRandom.uuid }.merge(uid)
|
@@ -89,23 +98,34 @@ module DashX
|
|
89
98
|
make_graphql_request(TRACK_EVENT_REQUEST, { event: event, uid: uid, data: data })
|
90
99
|
end
|
91
100
|
|
92
|
-
def generate_identity_token(uid)
|
101
|
+
def generate_identity_token(uid, options = {})
|
93
102
|
check_presence!(uid, 'uid')
|
103
|
+
symbolize_keys! options
|
104
|
+
|
105
|
+
kind = options[:kind] || 'regular'
|
106
|
+
plain_text = "v1;#{kind};#{uid}"
|
94
107
|
|
95
108
|
cipher = OpenSSL::Cipher::AES.new(256, :GCM).encrypt
|
96
109
|
cipher.key = @config.private_key
|
97
110
|
nonce = cipher.random_iv
|
98
111
|
cipher.iv = nonce
|
99
|
-
encrypted = cipher.update(
|
112
|
+
encrypted = cipher.update(plain_text) + cipher.final
|
100
113
|
encrypted_token = "#{nonce}#{encrypted}#{cipher.auth_tag}"
|
101
114
|
Base64.urlsafe_encode64(encrypted_token)
|
102
115
|
end
|
103
116
|
|
117
|
+
def save_contacts(uid, contacts = [])
|
118
|
+
contacts.each(&:symbolize_keys!)
|
119
|
+
make_graphql_request(SAVE_CONTACTS_REQUEST, { uid: uid, contacts: contacts })
|
120
|
+
end
|
121
|
+
|
104
122
|
private
|
105
123
|
|
106
124
|
def make_graphql_request(request, params)
|
107
125
|
body = { query: request, variables: { input: params } }.to_json
|
108
|
-
|
126
|
+
response = self.class.post('/graphql', { body: body })
|
127
|
+
raise "Request Failed: #{response}" if !response.success? || response.parsed_response.nil? || !response.parsed_response['errors'].nil?
|
128
|
+
response
|
109
129
|
end
|
110
130
|
|
111
131
|
def symbolize_keys!(hash)
|
@@ -116,6 +136,10 @@ module DashX
|
|
116
136
|
hash.replace(new_hash)
|
117
137
|
end
|
118
138
|
|
139
|
+
def wrap_array(obj)
|
140
|
+
obj.is_a?(Array) ? obj : [obj]
|
141
|
+
end
|
142
|
+
|
119
143
|
def check_presence!(obj, name = obj)
|
120
144
|
raise ArgumentError, "#{name} cannot be blank." if obj.nil? || (obj.is_a?(String) && obj.empty?)
|
121
145
|
end
|
data/lib/dashx/version.rb
CHANGED
data/lib/dashx.rb
CHANGED
@@ -10,7 +10,7 @@ module DashX
|
|
10
10
|
|
11
11
|
@clients[client_name] = DashX::Client.new(config)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def self.deliver(urn, parcel)
|
15
15
|
@clients[:default].deliver(urn, parcel)
|
16
16
|
end
|
@@ -26,4 +26,8 @@ module DashX
|
|
26
26
|
def self.generate_identity_token(uid)
|
27
27
|
@clients[:default].generate_identity_token(uid)
|
28
28
|
end
|
29
|
+
|
30
|
+
def self.save_contacts(uid, contacts)
|
31
|
+
@clients[:default].save_contacts(uid, contacts)
|
32
|
+
end
|
29
33
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DashX
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.16'
|
27
|
-
description:
|
28
|
-
email:
|
27
|
+
description:
|
28
|
+
email:
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
@@ -51,7 +51,7 @@ licenses:
|
|
51
51
|
metadata:
|
52
52
|
homepage_uri: https://github.com/dashxhq/dashx-ruby#readme
|
53
53
|
source_code_uri: https://github.com/dashxhq/dashx-ruby
|
54
|
-
post_install_message:
|
54
|
+
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
70
|
-
signing_key:
|
69
|
+
rubygems_version: 3.0.8
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: DashX SDK for Ruby.
|
73
73
|
test_files: []
|