Class: SimpleAnalytics::Api
- Inherits:
-
Object
- Object
- SimpleAnalytics::Api
- Defined in:
- lib/simple_analytics.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#body ⇒ Object
readonly
rows
is a 2-dimensional array of strings, each string represents a value in the table. -
#rows ⇒ Object
readonly
rows
is a 2-dimensional array of strings, each string represents a value in the table.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate ⇒ Object
- #fetch(properties) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Api
constructor
A new instance of Api.
Constructor Details
#initialize(username, password, options = {}) ⇒ Api
Returns a new instance of Api.
25 26 27 28 29 |
# File 'lib/simple_analytics.rb', line 25 def initialize(username, password, = {}) @username = username @password = password @options = end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
13 14 15 |
# File 'lib/simple_analytics.rb', line 13 def auth_token @auth_token end |
#body ⇒ Object (readonly)
rows
is a 2-dimensional array of strings, each string represents a value in the table. body
is the data in response body.
17 18 19 |
# File 'lib/simple_analytics.rb', line 17 def body @body end |
#rows ⇒ Object (readonly)
rows
is a 2-dimensional array of strings, each string represents a value in the table. body
is the data in response body.
17 18 19 |
# File 'lib/simple_analytics.rb', line 17 def rows @rows end |
Class Method Details
.authenticate(username, password, options = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/simple_analytics.rb', line 19 def self.authenticate(username, password, = {}) analytics = new(username, password, ) analytics.authenticate analytics end |
Instance Method Details
#authenticate ⇒ Object
31 32 33 34 35 |
# File 'lib/simple_analytics.rb', line 31 def authenticate login_service = ::GoogleClientLogin::GoogleAuth.new() login_service.authenticate(@username, @password, @options[:captcha_response]) @auth_token = login_service.auth end |
#fetch(properties) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/simple_analytics.rb', line 37 def fetch(properties) check_properties(properties) uri = URI.parse(API_URL) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE headers = { 'Authorization' => "GoogleLogin auth=#{@auth_token}", 'GData-Version' => '3' } response = http.get("#{uri.path}?#{query_string(properties)}", headers) raise NotSuccessfulResponseError.new, response.body if response.code_type != Net::HTTPOK @body = JSON.parse(response.body) @rows = @body['rows'] end |