Class: Twingly::Analytics::Query
- Inherits:
-
Object
- Object
- Twingly::Analytics::Query
- 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
-
#client ⇒ Object
Returns the value of attribute client.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#language ⇒ Object
Returns the value of attribute language.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(client) ⇒ Query
constructor
A new instance of Query.
- #request_parameters ⇒ Object
- #url ⇒ Object
- #url_parameters ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/twingly-analytics/query.rb', line 6 def client @client end |
#end_time ⇒ Object
Returns the value of attribute end_time.
7 8 9 |
# File 'lib/twingly-analytics/query.rb', line 7 def end_time @end_time end |
#language ⇒ Object
Returns the value of attribute language.
6 7 8 |
# File 'lib/twingly-analytics/query.rb', line 6 def language @language end |
#pattern ⇒ Object
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/twingly-analytics/query.rb', line 6 def pattern @pattern end |
#start_time ⇒ Object
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
#execute ⇒ Object
20 21 22 |
# File 'lib/twingly-analytics/query.rb', line 20 def execute Parser.new.parse(get_response.body) end |
#request_parameters ⇒ Object
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 |
#url ⇒ Object
16 17 18 |
# File 'lib/twingly-analytics/query.rb', line 16 def url "#{BASE_URL}#{ANALYTICS_PATH}?#{url_parameters}" end |
#url_parameters ⇒ Object
32 33 34 |
# File 'lib/twingly-analytics/query.rb', line 32 def url_parameters Faraday::Utils.build_query(request_parameters) end |