Class: PopularPages::RestClient
- Inherits:
-
Object
- Object
- PopularPages::RestClient
- Defined in:
- lib/popular_pages/rest_client.rb
Instance Method Summary collapse
- #all(from = 7, to = 1) ⇒ Object
-
#initialize ⇒ RestClient
constructor
A new instance of RestClient.
Constructor Details
#initialize ⇒ RestClient
Returns a new instance of RestClient.
7 8 9 10 11 12 |
# File 'lib/popular_pages/rest_client.rb', line 7 def initialize config = PopularPages::Configuration.new ENV['GOOGLE_PRIVATE_KEY'] = config.private_key ENV['GOOGLE_CLIENT_EMAIL'] = config.client_email ENV['GOOGLE_CLIENT_ID'] = config.client_id end |
Instance Method Details
#all(from = 7, to = 1) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/popular_pages/rest_client.rb', line 14 def all(from = 7, to = 1) url="#{ENV['GOOGLE_API_URL']}?ids=ga%3A#{ENV['GOOGLE_APPLICATION_ID']}&"\ "start-date=#{from}daysAgo&end-date=#{to}daysAgo&metrics=ga%3AuniquePageviews&"\ "dimensions=ga%3ApagePath&sort=-ga%3AuniquePageviews&max-results=200&"\ "access_token=#{access_token}" uri = URI(url) res = Net::HTTP.get_response(uri) parse_response(res.body) end |