Skip to content

Instantly share code, notes, and snippets.

View JosephBrianChambers's full-sized avatar

Joe Chambers JosephBrianChambers

View GitHub Profile
@JosephBrianChambers
JosephBrianChambers / fetch_pool_projection_data.rb
Last active October 22, 2015 23:09
Fetch PoolProjection from token-service
require 'active_support/all'
require 'faraday'
require 'json'
AUTH_USERNAME = ''
AUTH_PASSWORD = ''
def fetch_pp_data(provider_id = 14, token_type = :account, day_epoch = Time.now.beginning_of_day.to_i)
pp_id = [provider_id, token_type, day_epoch].join(':')
url = "https://token-service.bmasked.info/v1/pool_projections/#{pp_id}"
@JosephBrianChambers
JosephBrianChambers / queue_topic_update_account_meta_sync.rb
Last active August 29, 2015 14:22
Queue TopicUpdate AccountMeta sync
# Queue jobs to sync/save AccountMeta records via SocialGraphService for every TopicUpdate.
# This is to prevent high latency on SocialGraphService due to inline provider scraping(takes long time), during API requests
# Note: set SOCIAL_GRAPH_SERVICE_URL
# Note: set X-SSL-Auth
ElasticsearchTopicUpdate.migrate(nil) do |batch|
bulk_args = batch.map { |es_topic_updates| ['TopicUpdate', :sync_account_meta, [es_topic_updates.account_guid]] }
Sidekiq::Client.new(SIDEKIQ_TOPIC_REDIS).push_bulk('class' => MigrationWorker, 'args' => bulk_args)
@JosephBrianChambers
JosephBrianChambers / Example token encryption migration
Last active August 29, 2015 14:17
Token encryption migration using attr_encrypted gem
# Given mongoid Account model
class Account
include Mongoid::Document
field encrypted_token
field token_version
attr_encryptor :token, key: proc { |account| ENV["ACCOUNT_TOKEN_ENCRYPTION_KEY_V#{account.token_version}"] }, encode: true
end