Skip to content

Instantly share code, notes, and snippets.

<script>
(function () {
var analytics = window.analytics
if (!analytics) return
var appInstallButton = document.querySelectorAll('.js-partner-tracking');
analytics.ready(function () {
ga('create', 'UA-REDACTED', 'auto', 'appTracker');
ga('appTracker.send', 'pageview');
def throttle(start_time)
stop_time = Time.zone.now
processing_duration = stop_time - start_time
wait_time = (0.3 - processing_duration).round(1)
Rails.logger.info("THROTTLING: #{wait_time}")
sleep wait_time if wait_time > 0.0
Time.zone.now
end
TRANSACTIONS_QUERY = ShopifyPartnerAPI.client.parse <<-'GRAPHQL'
query($cursor: String) {
transactions(types: [APP_SUBSCRIPTION_SALE], after: $cursor, first: 100) {
edges {
cursor
node {
id,
createdAt,
... on AppSubscriptionSale {
netAmount {
class Transaction < ActiveRecord::Base
include ShopifyPartnerAPI
THROTTLE_MIN_TIME_PER_CALL = 0.3
TRANSACTIONS_QUERY = ShopifyPartnerAPI.client.parse <<-'GRAPHQL'
query($cursor: String) {
transactions(types: [APP_SUBSCRIPTION_SALE], after: $cursor, first: 100) {
edges {
cursor
query ($cursor: String) {
transactions(types: [APP_SUBSCRIPTION_SALE], after: $cursor, first: 100) {
edges {
cursor
node {
id
createdAt
... on AppSubscriptionSale {
netAmount {
amount
query {
transactions(types: [APP_SUBSCRIPTION_SALE]) {
edges {
node {
id
createdAt
... on AppSubscriptionSale {
netAmount {
amount
}
query {
transactions(types: [APP_SUBSCRIPTION_SALE]) {
edges {
node {
id
createdAt
netAmount {
amount
}
app {
query {
transactions(types: [APP_SUBSCRIPTION_SALE]) {
edges {
node {
id
createdAt
... on AppSubscriptionSale {
netAmount {
amount
}
require "graphql/client"
require "http_client"
module ShopifyPartnerAPI
class << self
delegate :parse, :query, to: :client
def client
initialize_client_cache
cached_client = @_client_cache
module ShopifyPartnerAPI
class HTTPClient < GraphQL::Client::HTTP
def initialize
super("https://partners.shopify.com/")
end
def headers(context)
{
"X-Shopify-Access-Token": context.fetch(:access_token)
}