module StatHat::Json::SyncApi

Constants

EZ_URI
EZ_URL

Public Instance Methods

build_post_data(stats) click to toggle source
# File lib/stathat/json/sync_api.rb, line 49
def build_post_data(stats)
  stats = [stats].flatten
  MultiJson.dump({ ezkey: ez_key, data: stats })
end
connection() click to toggle source
# File lib/stathat/json/sync_api.rb, line 21
def connection
  @connection ||= initialize_connection
end
ez_key() click to toggle source
# File lib/stathat/json/sync_api.rb, line 13
def ez_key
  @@ez_key ||= ENV['STATHAT_EZKEY']
end
ez_key=(val) click to toggle source
# File lib/stathat/json/sync_api.rb, line 17
def ez_key=(val)
  @@ez_key = val
end
initialize_connection() click to toggle source
# File lib/stathat/json/sync_api.rb, line 25
def initialize_connection
  Faraday.new EZ_URL do |conn|
    conn.adapter :net_http_persistent
  end
end
post_count(stat, count=1, t=nil) click to toggle source
# File lib/stathat/json/sync_api.rb, line 41
def post_count(stat, count=1, t=nil)
  post_stats(stat: stat, count: count, t: t)
end
post_stats(stats) click to toggle source
# File lib/stathat/json/sync_api.rb, line 31
def post_stats(stats)
  response = connection.post do |req|
    req.url(EZ_URI)
    req.headers['Content-Type'] = 'application/json'
    req.body                    = build_post_data(stats)
  end

  StatHat::Json::Response.new response
end
post_value(stat, value, t=nil) click to toggle source
# File lib/stathat/json/sync_api.rb, line 45
def post_value(stat, value, t=nil)
  post_stats(stat: stat, value: value, t: t)
end