Class: Tire::ClickLog

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/tire/click_log.rb

Instance Method Summary collapse

Methods included from Utils

escape, #logged, unescape

Constructor Details

#initialize(indices, types, keyword, ids) ⇒ ClickLog

Returns a new instance of ClickLog.



6
7
8
9
10
11
12
# File 'lib/tire/click_log.rb', line 6

def initialize(indices, types, keyword, ids)
  @indices = Array(indices)
  @types   = Array(types).map { |type| Utils.escape(type) }

  @path    = ['/', @indices.join(','), @types.join(','), '_log'].compact.join('/').squeeze('/')
  @payload = MultiJson.encode({:keyword => keyword, :id => ids.split(',')})
end

Instance Method Details

#logObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tire/click_log.rb', line 18

def log
  @response = Configuration.client.post(url, @payload)
  if @response.success?
    MultiJson.decode(@response.body)
  else
    []
  end
ensure
  curl = %Q(curl -X POST #{url} -d '#{@payload}')
  logged('CLICK_LOG', curl)
end

#urlObject



14
15
16
# File 'lib/tire/click_log.rb', line 14

def url
  "#{Configuration.url}#@path"
end