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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92167d2944237c5e38d7a961e7667ee28b9d0f1c538ccbcf85e74774f0d069d7
4
- data.tar.gz: f60d37b643ca4bc774e07dd2ea0943a40c1f512b8dc567074c3fcb26e024a8e4
3
+ metadata.gz: 06ad40758bc5f6cd2a2112d112e5d5f89116236223d49d4f587e4e5b3e1fec29
4
+ data.tar.gz: 1e69514d594c29381d72bb39fa88601b19c8172344fee5cd09f23f815d2d9fec
5
5
  SHA512:
6
- metadata.gz: ee4d621ad99514c4dd92422ead8c0b516312a484c82442eaf76906a4741c0c382fb84be685d2caeae0273d93a539c83737290eed4d9e48fbf33b8639e0746c77
7
- data.tar.gz: 794c3c582620a41e44aa1fa0014eb267a33173f42de3c066108e0cd3cf5c39bc7062296f4f2626f0423d313783e1062e0184683237823041d206d83ca033af44
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. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
93
93
 
94
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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, 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)
56
-
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)')
67
-
68
- { attachments: [], cc: [], bcc: [] }.merge(urn)
69
- end
70
-
71
- make_graphql_request(CREATE_DELIVERY_REQUEST, options)
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? String && options != nil
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(uid) + cipher.final
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
- request = self.class.post('/graphql', { body: body })
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
@@ -1,3 +1,3 @@
1
1
  module DashX
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
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.1.2
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: 2021-10-06 00:00:00.000000000 Z
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.2.28
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: []