Skip to content

Instantly share code, notes, and snippets.

@cemeng
Last active March 29, 2017 04:23
Show Gist options
  • Save cemeng/11a991264ac7e319c95177a5e342bca1 to your computer and use it in GitHub Desktop.
Save cemeng/11a991264ac7e319c95177a5e342bca1 to your computer and use it in GitHub Desktop.
Writing to Data Store

Connection information from member.data.connection (in account profile)

{
  connection: {
    login: {
      timestamp: '2017-03-29T02:54:26.750Z',
      siteId: 'iMmv-tD9dswv71XMEBeJgQ',
      device: {
        os: 'Macintosh 10.11.6',
        browser: 'Chrome',
        type: 'Desktop'
      },
      url: 'http://localhost:3000/',
      ipAddress: '127.0.0.1'
    }
  }
}

The code that writes it to data store:

def account_updated # webhook for account updated
....
    uids.each do |uid|
      GigyaMember.find(uid, nil).tap do |member|
        store_connection_information(member)
      end
    end
.....
end

def store_connection_information(member)
  connection_information = member.data[:connection]
  return unless connection_information
  ::Gigya::DataStore.store(apiKey: APP_CONFIG['gigya_default_api_key'],
                           data: { connection: connection_information }.to_json,
                           oid: 'auto',
                           type: 'connections',
                           UID: member.uid)
end

I set the type to connections (plural) similar to Rails convention (but can be changed to singular). oid is auto as per recommendation.

To retrieve the data, we'll do it like this:

::Gigya::DataStore.search(query: "SELECT * FROM connections WHERE UID = '#{member.uid}'", apiKey: APP_CONFIG['gigya_default_api_key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment