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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f829e4a4385be4501b6b656b96803622c4df712d4f1ba987d0d1c8764d7eb97c
4
- data.tar.gz: fb6a8f35137fd897066995ff1f06d2699acf7aeb333ddde0203d2c5fcf6af91c
3
+ metadata.gz: 92167d2944237c5e38d7a961e7667ee28b9d0f1c538ccbcf85e74774f0d069d7
4
+ data.tar.gz: f60d37b643ca4bc774e07dd2ea0943a40c1f512b8dc567074c3fcb26e024a8e4
5
5
  SHA512:
6
- metadata.gz: '0309581f7794596ca59301fb69226c9fc69c7d248888f40b361c768414301a4eb5f6ab69176aa6a63c8b18cc316626c15b432c3609599d8b7e2dfdbce9be24f0'
7
- data.tar.gz: 0a636b809132b7f791a15a6b81ca6ed346be202d0aa974aa41e2329d5bf8689d89dc26ab9a3da28fcfbb46f5819bf0888bbb06f16f240673932d607b399189cb
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/v1'
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
- self.class.headers({
33
+
34
+ headers = {
13
35
  'X-Public-Key' => config.public_key,
14
- 'X-Private-Key' => config.private_key
15
- })
16
- end
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
- def deliver(parcel)
19
- symbolize_keys! parcel
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
- check_presence!(parcel[:to], 'Recipient')
68
+ { attachments: [], cc: [], bcc: [] }.merge(urn)
69
+ end
22
70
 
23
- make_http_request('deliver', parcel)
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
- { anonymous_uid: SecureRandom.uuid }.merge(options)
80
+ { anonymousUid: SecureRandom.uuid }.merge(uid)
33
81
  end
34
82
 
35
- make_http_request('identify', params)
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
- make_http_request('track', { event: event, uid: uid, data: data })
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 make_http_request(uri, body)
59
- self.class.send(:post, "/#{uri}", { body: body })
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
@@ -3,5 +3,7 @@ module DashX
3
3
  attr_accessor :base_uri
4
4
  attr_accessor :public_key
5
5
  attr_accessor :private_key
6
+ attr_accessor :target_installation
7
+ attr_accessor :target_environment
6
8
  end
7
9
  end
data/lib/dashx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DashX
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
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 = {}, options = {})
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.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-05 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty