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_CONTACTS_REQUEST =
'query FetchContacts($input: FetchContactsInput!) { fetchContacts(input: $input) { contacts { id accountId name kind value unverifiedValue verifiedAt status tag 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_contacts(uid) ⇒ 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.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dashx/client.rb', line 98 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/dashx/client.rb', line 119 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_contacts(uid) ⇒ Object
166 167 168 |
# File 'lib/dashx/client.rb', line 166 def fetch_contacts(uid) make_graphql_request(FETCH_CONTACTS_REQUEST, { uid: uid }) end |
#fetch_item(identifier) ⇒ Object
170 171 172 |
# File 'lib/dashx/client.rb', line 170 def fetch_item(identifier) make_graphql_request(FETCH_ITEM_REQUEST, { identifier: identifier }) end |
#fetch_stored_preferences(uid) ⇒ Object
174 175 176 |
# File 'lib/dashx/client.rb', line 174 def fetch_stored_preferences(uid) make_graphql_request(FETCH_STORED_PREFERENCES, { accountUid: uid }) end |
#identify(uid, options) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dashx/client.rb', line 143 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
161 162 163 164 |
# File 'lib/dashx/client.rb', line 161 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
178 179 180 |
# File 'lib/dashx/client.rb', line 178 def save_stored_preferences(uid, preferenceData) make_graphql_request(SAVE_STORED_PREFERENCES, { accountUid: uid, preferenceData: preferenceData }) end |
#track(event, uid, data = nil) ⇒ Object
155 156 157 158 159 |
# File 'lib/dashx/client.rb', line 155 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 |