Skip to content
Permalink
Browse files

added mailchimp subscriber count to open stats

  • Loading branch information...
yongfook committed Sep 16, 2019
1 parent 2b51262 commit 7c7686315015a453ea65b5062d0e8b2fff3d71f1
@@ -0,0 +1,13 @@
class Api::V1::MailchimpController < ApplicationController

def subscribers
mailchimp_root = "https://#{ENV['MAILCHIMP_DC']}.api.mailchimp.com/3.0"
@data = Rails.cache.fetch('api:open:mailchimp', {expires_in: 5.minutes, public: true, raw: true}) do
puts "Fetching fresh data"
auth = {:username => "mailchimp docs say any string is ok here", :password => ENV['MAILCHIMP_API_KEY']}
HTTParty.get("#{mailchimp_root}/lists/#{ENV['MAILCHIMP_LIST_ID']}", :basic_auth => auth)
end
render :json => @data['stats']
end

end
@@ -5,6 +5,7 @@
namespace :api do
namespace :v1 do
get 'chartmogul/metrics', to: 'chartmogul#metrics'
get 'mailchimp/subscribers', to: 'mailchimp#subscribers'
end
end
end
@@ -0,0 +1,7 @@
require 'test_helper'

class Api::V1::MailchimpControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit 7c76863

Please sign in to comment.
You can’t perform that action at this time.