Class: GameAnalytics::Worker
- Inherits:
-
Object
- Object
- GameAnalytics::Worker
- Includes:
- Common
- Defined in:
- lib/game_analytics/worker.rb
Instance Method Summary collapse
-
#initialize(q) ⇒ Worker
constructor
A new instance of Worker.
- #process(unit) ⇒ Object
- #run ⇒ Object
Methods included from Common
#client, #disabled, #logger, #options
Constructor Details
#initialize(q) ⇒ Worker
Returns a new instance of Worker.
10 11 12 13 14 |
# File 'lib/game_analytics/worker.rb', line 10 def initialize(q) @queue = q @http = HTTPClient.new @url_base = "http://api.gameanalytics.com/1/#{[:game_key]}" end |
Instance Method Details
#process(unit) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/game_analytics/worker.rb', line 16 def process(unit) klass = unit.is_a?(Array) ? unit.first.class : unit.class category = klass.name.demodulize.downcase json_data = unit.to_json hd = Digest::MD5.hexdigest(json_data + [:secret_key]) url = "#{@url_base}/#{category}" logger.info "GameAnalytics <: #{url} #{json_data} #{hd}" resp = @http.post(url, :body => json_data, :header => { 'Authorization' => hd }) logger.info "GameAnalytics >: #{resp.content} (#{resp.status})" end |
#run ⇒ Object
27 28 29 30 31 32 |
# File 'lib/game_analytics/worker.rb', line 27 def run logger.info "GameAnalytics worker running" loop do process @queue.pop end end |