Class: Twingly::Analytics::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly-analytics/query.rb

Constant Summary collapse

BASE_URL =
'https://api.twingly.com'
ANALYTICS_PATH =
'/analytics/Analytics.ashx'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Query

Returns a new instance of Query.



12
13
14
# File 'lib/twingly-analytics/query.rb', line 12

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/twingly-analytics/query.rb', line 6

def client
  @client
end

#end_timeObject

Returns the value of attribute end_time.



7
8
9
# File 'lib/twingly-analytics/query.rb', line 7

def end_time
  @end_time
end

#languageObject

Returns the value of attribute language.



6
7
8
# File 'lib/twingly-analytics/query.rb', line 6

def language
  @language
end

#patternObject

Returns the value of attribute pattern.



6
7
8
# File 'lib/twingly-analytics/query.rb', line 6

def pattern
  @pattern
end

#start_timeObject

Returns the value of attribute start_time.



7
8
9
# File 'lib/twingly-analytics/query.rb', line 7

def start_time
  @start_time
end

Instance Method Details

#executeObject



20
21
22
# File 'lib/twingly-analytics/query.rb', line 20

def execute
  Parser.new.parse(get_response.body)
end

#request_parametersObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twingly-analytics/query.rb', line 36

def request_parameters
  fail("Missing pattern") unless pattern

  {
    :key => client.api_key,
    :searchpattern => pattern,
    :documentlang => language,
    :ts => start_time,
    :tsTo => end_time,
    :xmloutputversion => 2
  }
end

#urlObject



16
17
18
# File 'lib/twingly-analytics/query.rb', line 16

def url
  "#{BASE_URL}#{ANALYTICS_PATH}?#{url_parameters}"
end

#url_parametersObject



32
33
34
# File 'lib/twingly-analytics/query.rb', line 32

def url_parameters
  Faraday::Utils.build_query(request_parameters)
end