Permalink
Browse files

cleanup

  • Loading branch information...
1 parent b72fcc7 commit 59e8caf505a341024b902fbb083be239d994e815 @tpitale tpitale committed Jun 30, 2011
View
@@ -13,22 +13,19 @@
end
require 'garb/version'
-require 'garb/authentication_request'
-require 'garb/data_request'
-require 'garb/account_feed_request'
+require 'garb/request/authentication'
+require 'garb/request/data'
+# require 'garb/account_feed_request'
require 'garb/session'
require 'garb/profile_reports'
require 'garb/step'
require 'garb/destination'
-require 'garb/goal'
-require 'garb/profile'
-require 'garb/account'
require 'garb/filter_parameters'
require 'garb/report_parameter'
require 'garb/result_set'
require 'garb/report_response'
-require 'garb/resource'
-require 'garb/report'
+# require 'garb/resource'
+# require 'garb/report'
require 'garb/model'
View
@@ -1,22 +0,0 @@
-module Garb
- class Account
- attr_reader :id, :name, :profiles
-
- def initialize(profiles)
- @id = profiles.first.account_id
- @name = profiles.first.account_name
- @profiles = profiles
- end
-
- def self.all(session = Session)
- ActiveSupport::Deprecation.warn("The use of Garb::Account has been deprecated in favor of 'Garb::Management::Account'")
- profiles = {}
-
- Profile.all(session).each do |profile|
- (profiles[profile.account_id] ||= []) << profile
- end
-
- profiles.map {|k,v| v}.map {|profiles| new(profiles)}
- end
- end
-end
@@ -1,25 +0,0 @@
-module Garb
- class AccountFeedRequest
- URL = "https://www.google.com/analytics/feeds/accounts/default"
-
- def initialize(session = Session)
- @request = DataRequest.new(session, URL)
- end
-
- def response
- @response ||= @request.send_request
- end
-
- def parsed_response
- @parsed_response ||= Crack::XML.parse(response.body)
- end
-
- def entries
- parsed_response ? Array(parsed_response['feed']['entry']).flatten.compact : []
- end
-
- def segments
- parsed_response ? Array(parsed_response['feed']['dxp:segment']).flatten.compact : []
- end
- end
-end
@@ -1,53 +0,0 @@
-module Garb
- class AuthenticationRequest
- class AuthError < StandardError;end
-
- URL = 'https://www.google.com/accounts/ClientLogin'
-
- def initialize(email, password, opts={})
- @email = email
- @password = password
- @account_type = opts.fetch(:account_type, 'HOSTED_OR_GOOGLE')
- end
-
- def parameters
- {
- 'Email' => @email,
- 'Passwd' => @password,
- 'accountType' => @account_type,
- 'service' => 'analytics',
- 'source' => 'vigetLabs-garb-001'
- }
- end
-
- def uri
- URI.parse(URL)
- end
-
- def send_request(ssl_mode)
- http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
- http.use_ssl = true
- http.verify_mode = ssl_mode
-
- if ssl_mode == OpenSSL::SSL::VERIFY_PEER
- http.ca_file = CA_CERT_FILE
- end
-
- http.request(build_request) do |response|
- raise AuthError unless response.is_a?(Net::HTTPOK)
- end
- end
-
- def build_request
- post = Net::HTTP::Post.new(uri.path)
- post.set_form_data(parameters)
- post
- end
-
- def auth_token(opts={})
- ssl_mode = opts[:secure] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
- send_request(ssl_mode).body.match(/^Auth=(.*)$/)[1]
- end
-
- end
-end
View
@@ -1,42 +0,0 @@
-module Garb
- class DataRequest
- class ClientError < StandardError; end
-
- def initialize(session, base_url, parameters={})
- @session = session
- @base_url = base_url
- @parameters = parameters
- end
-
- def query_string
- parameter_list = @parameters.map {|k,v| "#{k}=#{v}" }
- parameter_list.empty? ? '' : "?#{parameter_list.join('&')}"
- end
-
- def uri
- URI.parse(@base_url)
- end
-
- def send_request
- response = if @session.single_user?
- single_user_request
- elsif @session.oauth_user?
- oauth_user_request
- end
-
- raise ClientError, response.body.inspect unless response.kind_of?(Net::HTTPSuccess)
- response
- end
-
- def single_user_request
- http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- http.get("#{uri.path}#{query_string}", {'Authorization' => "GoogleLogin auth=#{@session.auth_token}", 'GData-Version' => '2'})
- end
-
- def oauth_user_request
- @session.access_token.get("#{uri}#{query_string}", {'GData-Version' => '2'})
- end
- end
-end
@@ -1,32 +1,24 @@
module Garb
class FilterParameters
- def self.define_operators(*methods)
- methods.each do |method|
- class_eval <<-CODE
- def #{method}(field, value)
- @filter_hash.merge!({SymbolOperator.new(field, :#{method}) => value})
- end
- CODE
- end
- end
-
- define_operators :eql, :not_eql, :gt, :gte, :lt, :lte, :matches,
- :does_not_match, :contains, :does_not_contain, :substring, :not_substring
+ # def self.define_operators(*methods)
+ # methods.each do |method|
+ # class_eval <<-CODE
+ # def #{method}(field, value)
+ # @filter_hash.merge!({SymbolOperator.new(field, :#{method}) => value})
+ # end
+ # CODE
+ # end
+ # end
+
+ # define_operators :eql, :not_eql, :gt, :gte, :lt, :lte, :matches,
+ # :does_not_match, :contains, :does_not_contain, :substring, :not_substring
attr_accessor :parameters
def initialize
self.parameters = []
end
- def filters(&block)
- @filter_hash = {}
-
- instance_eval &block
-
- self.parameters << @filter_hash
- end
-
def to_params
value = self.parameters.map do |param|
param.map do |k,v|
View
@@ -1,20 +0,0 @@
-module Garb
- class Goal
- attr_reader :name, :number, :value, :destination
-
- def initialize(attributes={})
- return unless attributes.is_a?(Hash)
-
- @name = attributes['name']
- @number = attributes['number'].to_i
- @value = attributes['value'].to_f
- @active = (attributes['active'] == 'true')
-
- @destination = Destination.new(attributes[Garb.to_ga('destination')])
- end
-
- def active?
- @active
- end
- end
-end
@@ -6,7 +6,7 @@ class Feed
attr_reader :request
def initialize(session, path)
- @request = DataRequest.new(session, BASE_URL+path)
+ @request = Request::Data.new(session, BASE_URL+path)
end
def parsed_response
View
@@ -46,7 +46,7 @@ def results(profile, options = {})
private
def send_request_for_data(profile, params)
- request = DataRequest.new(profile.session, URL, params)
+ request = Request::Data.new(profile.session, URL, params)
response = request.send_request
response.body
end
View
@@ -1,33 +0,0 @@
-module Garb
- class Profile
-
- include ProfileReports
-
- attr_reader :session, :table_id, :title, :account_name, :account_id, :web_property_id, :goals
-
- def initialize(entry, session)
- @session = session
- @title = entry['title']
- @table_id = entry['dxp:tableId']
- @goals = (entry[Garb.to_ga('goal')] || []).map {|g| Goal.new(g)}
-
- Garb.parse_properties(entry).each do |k,v|
- instance_variable_set :"@#{k}", v
- end
- end
-
- def id
- Garb.from_ga(@table_id)
- end
-
- def self.all(session = Session)
- ActiveSupport::Deprecation.warn("Garb::Profile.all is deprecated in favor of Garb::Management::Profile.all")
- AccountFeedRequest.new(session).entries.map {|entry| new(entry, session)}
- end
-
- def self.first(id, session = Session)
- ActiveSupport::Deprecation.warn("Garb::Profile.first is deprecated in favor of Garb::Management::WebProperty")
- all(session).detect {|profile| profile.id == id || profile.web_property_id == id }
- end
- end
-end
View
@@ -1,28 +0,0 @@
-module Garb
- class Report
- include Resource
-
- MONTH = 2592000
- URL = "https://www.google.com/analytics/feeds/data"
-
- def initialize(profile, opts={})
- ActiveSupport::Deprecation.warn("The use of Report will be removed in favor of 'extend Garb::Model'")
-
- @profile = profile
-
- @start_date = opts.fetch(:start_date, Time.now - MONTH)
- @end_date = opts.fetch(:end_date, Time.now)
- @limit = opts.fetch(:limit, nil)
- @offset = opts.fetch(:offset, nil)
-
- metrics opts.fetch(:metrics, [])
- dimensions opts.fetch(:dimensions, [])
- sort opts.fetch(:sort, [])
- end
-
- def results
- ReportResponse.new(send_request_for_body).results
- end
-
- end
-end
@@ -0,0 +1,55 @@
+module Garb
+ module Request
+ class Authentication
+ class AuthError < StandardError;end
+
+ URL = 'https://www.google.com/accounts/ClientLogin'
+
+ def initialize(email, password, opts={})
+ @email = email
+ @password = password
+ @account_type = opts.fetch(:account_type, 'HOSTED_OR_GOOGLE')
+ end
+
+ def parameters
+ {
+ 'Email' => @email,
+ 'Passwd' => @password,
+ 'accountType' => @account_type,
+ 'service' => 'analytics',
+ 'source' => 'vigetLabs-garb-001'
+ }
+ end
+
+ def uri
+ URI.parse(URL)
+ end
+
+ def send_request(ssl_mode)
+ http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
+ http.use_ssl = true
+ http.verify_mode = ssl_mode
+
+ if ssl_mode == OpenSSL::SSL::VERIFY_PEER
+ http.ca_file = CA_CERT_FILE
+ end
+
+ http.request(build_request) do |response|
+ raise AuthError unless response.is_a?(Net::HTTPOK)
+ end
+ end
+
+ def build_request
+ post = Net::HTTP::Post.new(uri.path)
+ post.set_form_data(parameters)
+ post
+ end
+
+ def auth_token(opts={})
+ ssl_mode = opts[:secure] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
+ send_request(ssl_mode).body.match(/^Auth=(.*)$/)[1]
+ end
+
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 59e8caf

Please sign in to comment.