Class: DashX::Client
Constant Summary collapse
- CREATE_DELIVERY_REQUEST =
'mutation CreateDelivery($input: CreateDeliveryInput!) { createDelivery(input: $input) { id } } '- IDENTIFY_ACCOUNT_REQUEST =
'mutation IdentifyAccount($input: IdentifyAccountInput!) { identifyAccount(input: $input) { id } } '- TRACK_EVENT_REQUEST =
'mutation TrackEvent($input: TrackEventInput!) { trackEvent(input: $input) { success } } '- SAVE_CONTACTS_REQUEST =
'mutation SaveContacts($input: SaveContactsInput!) { saveContacts(input: $input) { contacts { id } } } '- FETCH_ITEM_REQUEST =
'query FetchItem($input: FetchItemInput) { fetchItem(input: $input) { id installationId name identifier description createdAt updatedAt pricings { id kind amount originalAmount isRecurring recurringInterval recurringIntervalUnit appleProductIdentifier googleProductIdentifier currencyCode createdAt updatedAt } } } '- FETCH_STORED_PREFERENCES =
'query FetchStoredPreferences($input: FetchStoredPreferencesInput) { fetchStoredPreferences(input: $input) { preferenceData } } '- SAVE_STORED_PREFERENCES =
'mutation SaveStoredPreferences($input: SaveStoredPreferencesInput) { saveStoredPreferences(input: $input) { success } } '
Instance Method Summary collapse
- #deliver(urn, options) ⇒ Object
- #fetch_item(identifier) ⇒ Object
- #fetch_stored_preferences(uid) ⇒ Object
- #identify(uid, options) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #save_contacts(uid, contacts = []) ⇒ Object
- #save_stored_preferences(uid, preferenceData) ⇒ Object
- #track(event, uid, data = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dashx/client.rb', line 79 def initialize(config) @config = config self.class.base_uri(config.base_uri) headers = { 'X-Public-Key' => config.public_key, 'X-Private-Key' => config.private_key, } if !config.target_environment.nil? headers['X-Target-Environment'] = config.target_environment end if !config.target_installation.nil? headers['X-Target-Installation'] = config.target_installation end self.class.headers(headers) end |
Instance Method Details
#deliver(urn, options) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/dashx/client.rb', line 100 def deliver(urn, ) templateSubkind, templateIdentifier = urn.split(/\//, 2) ||= {} symbolize_keys! [:content] ||= {} [:to, :cc, :bcc].each do |kind| value = .delete(kind) [:content][kind] ||= value if value [:content][kind] = wrap_array([:content][kind]) if [:content][kind] end params = { templateSubkind: templateSubkind.upcase, templateIdentifier: templateIdentifier }.merge() make_graphql_request(CREATE_DELIVERY_REQUEST, params) end |
#fetch_item(identifier) ⇒ Object
147 148 149 |
# File 'lib/dashx/client.rb', line 147 def fetch_item(identifier) make_graphql_request(FETCH_ITEM_REQUEST, { identifier: identifier }) end |
#fetch_stored_preferences(uid) ⇒ Object
151 152 153 |
# File 'lib/dashx/client.rb', line 151 def fetch_stored_preferences(uid) make_graphql_request(FETCH_STORED_PREFERENCES, { accountUid: uid }) end |
#identify(uid, options) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/dashx/client.rb', line 124 def identify(uid, ) symbolize_keys! params = if uid.is_a?(String) && != nil { uid: uid }.merge() else { anonymousUid: SecureRandom.uuid }.merge(uid) end make_graphql_request(IDENTIFY_ACCOUNT_REQUEST, params) end |
#save_contacts(uid, contacts = []) ⇒ Object
142 143 144 145 |
# File 'lib/dashx/client.rb', line 142 def save_contacts(uid, contacts = []) contacts.each(&:symbolize_keys!) make_graphql_request(SAVE_CONTACTS_REQUEST, { uid: uid, contacts: contacts }) end |
#save_stored_preferences(uid, preferenceData) ⇒ Object
155 156 157 |
# File 'lib/dashx/client.rb', line 155 def save_stored_preferences(uid, preferenceData) make_graphql_request(SAVE_STORED_PREFERENCES, { accountUid: uid, preferenceData: preferenceData }) end |
#track(event, uid, data = nil) ⇒ Object
136 137 138 139 140 |
# File 'lib/dashx/client.rb', line 136 def track(event, uid, data = nil) symbolize_keys! data unless data.nil? make_graphql_request(TRACK_EVENT_REQUEST, { event: event, accountUid: uid, data: data }) end |