Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 59e8caf505a341024b902fbb083be239d994e815 1 parent b72fcc7
@tpitale tpitale authored
Showing with 406 additions and 1,056 deletions.
  1. +5 −8 lib/garb.rb
  2. +0 −22 lib/garb/account.rb
  3. +0 −25 lib/garb/account_feed_request.rb
  4. +0 −53 lib/garb/authentication_request.rb
  5. +0 −42 lib/garb/data_request.rb
  6. +12 −20 lib/garb/filter_parameters.rb
  7. +0 −20 lib/garb/goal.rb
  8. +1 −1  lib/garb/management/feed.rb
  9. +1 −1  lib/garb/model.rb
  10. +0 −33 lib/garb/profile.rb
  11. +0 −28 lib/garb/report.rb
  12. +55 −0 lib/garb/request/authentication.rb
  13. +44 −0 lib/garb/request/data.rb
  14. +0 −115 lib/garb/resource.rb
  15. +1 −1  lib/garb/session.rb
  16. +1 −0  lib/support.rb
  17. +1 −1  test/test_helper.rb
  18. +0 −42 test/unit/garb/account_feed_request_test.rb
  19. +0 −53 test/unit/garb/account_test.rb
  20. +0 −140 test/unit/garb/authentication_request_test.rb
  21. +0 −114 test/unit/garb/data_request_test.rb
  22. +0 −28 test/unit/garb/destination_test.rb
  23. +19 −36 test/unit/garb/filter_parameters_test.rb
  24. +0 −24 test/unit/garb/goal_test.rb
  25. +1 −1  test/unit/garb/management/feed_test.rb
  26. +1 −1  test/unit/garb/model_test.rb
  27. +0 −77 test/unit/garb/profile_test.rb
  28. +0 −99 test/unit/garb/report_test.rb
  29. +142 −0 test/unit/garb/request/authentication_test.rb
  30. +116 −0 test/unit/garb/request/data_test.rb
  31. +0 −50 test/unit/garb/resource_test.rb
  32. +6 −6 test/unit/garb/session_test.rb
  33. +0 −15 test/unit/garb/step_test.rb
View
13 lib/garb.rb
@@ -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
22 lib/garb/account.rb
@@ -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
View
25 lib/garb/account_feed_request.rb
@@ -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
View
53 lib/garb/authentication_request.rb
@@ -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
42 lib/garb/data_request.rb
@@ -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
View
32 lib/garb/filter_parameters.rb
@@ -1,17 +1,17 @@
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
@@ -19,14 +19,6 @@ 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
20 lib/garb/goal.rb
@@ -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
View
2  lib/garb/management/feed.rb
@@ -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
2  lib/garb/model.rb
@@ -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
33 lib/garb/profile.rb
@@ -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
28 lib/garb/report.rb
@@ -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
View
55 lib/garb/request/authentication.rb
@@ -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
View
44 lib/garb/request/data.rb
@@ -0,0 +1,44 @@
+module Garb
+ module Request
+ class Data
+ 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
+end
View
115 lib/garb/resource.rb
@@ -1,115 +0,0 @@
-module Garb
- module Resource
- MONTH = 2592000
- URL = "https://www.google.com/analytics/feeds/data"
-
- def self.extended(base)
- # define a method on a module that gets included into profile
- # Exits would make:
- # to enable profile.exits(options_hash, &block)
- # returns Exits.results(self, options_hash, &block)
- # every class defined which extends Resource will add to the module
-
- ActiveSupport::Deprecation.warn("The use of Garb::Resource will be removed in favor of 'extend Garb::Model'")
- ProfileReports.add_report_method(base)
- end
-
- %w(metrics dimensions sort).each do |parameter|
- class_eval <<-CODE
- def #{parameter}(*fields)
- @#{parameter} ||= ReportParameter.new(:#{parameter})
- @#{parameter} << fields
- end
-
- def clear_#{parameter}
- @#{parameter} = ReportParameter.new(:#{parameter})
- end
- CODE
- end
-
- def filters(*hashes, &block)
- @filter_parameters ||= FilterParameters.new
-
- hashes.each do |hash|
- @filter_parameters.parameters << hash
- end
-
- @filter_parameters.filters(&block) if block_given?
- @filter_parameters
- end
-
- def clear_filters
- @filter_parameters = FilterParameters.new
- end
-
- def set_segment_id(id)
- @segment = "gaid::#{id.to_i}"
- end
-
- def segment
- @segment
- end
-
- def set_instance_klass(klass)
- @instance_klass = klass
- end
-
- def instance_klass
- @instance_klass || OpenStruct
- end
-
- def results(profile, opts = {}, &block)
- @profile = profile.is_a?(Profile) ? profile : Profile.first(profile, opts.fetch(:session, Session))
-
- if @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)
-
- instance_eval(&block) if block_given?
-
- ReportResponse.new(send_request_for_body, instance_klass).results
- else
- []
- end
- end
-
- def page_params
- {'max-results' => @limit, 'start-index' => @offset}.reject{|k,v| v.nil?}
- end
-
- def default_params
- {'ids' => @profile.table_id,
- 'start-date' => format_time(@start_date),
- 'end-date' => format_time(@end_date)}
- end
-
- def segment_params
- segment.nil? ? {} : {'segment' => segment}
- end
-
- def params
- [
- metrics.to_params,
- dimensions.to_params,
- sort.to_params,
- filters.to_params,
- page_params,
- segment_params
- ].inject(default_params) do |p, i|
- p.merge(i)
- end
- end
-
- def format_time(t)
- t.strftime('%Y-%m-%d')
- end
-
- def send_request_for_body
- request = DataRequest.new(@profile.session, URL, params)
- response = request.send_request
- response.body
- end
- end
-end
View
2  lib/garb/session.rb
@@ -6,7 +6,7 @@ module Methods
# use only for single user authentication
def login(email, password, opts={})
self.email = email
- auth_request = AuthenticationRequest.new(email, password, opts)
+ auth_request = Request::Authentication.new(email, password, opts)
self.auth_token = auth_request.auth_token(opts)
end
View
1  lib/support.rb
@@ -34,6 +34,7 @@ class Symbol
:substring, :not_substring].each do |operator|
define_method(operator) do
+ ActiveSupport::Deprecation.warn("The use of SymbolOperator(#{operator}, etc.) has been deprecated. Please use named filters.")
SymbolOperator.new(self, operator)
end unless method_defined?(operator)
end
View
2  test/test_helper.rb
@@ -39,7 +39,7 @@ def read_fixture(filename)
end
def assert_data_params(expected)
- assert_received(Garb::DataRequest, :new) {|e| e.with(Garb::Session, Garb::Model::URL, expected)}
+ assert_received(Garb::Request::Data, :new) {|e| e.with(Garb::Session, Garb::Model::URL, expected)}
end
end
View
42 test/unit/garb/account_feed_request_test.rb
@@ -1,42 +0,0 @@
-require 'test_helper'
-
-module Garb
- class AccountFeedRequestTest < MiniTest::Unit::TestCase
- context "An AccountFeedRequest" do
- setup do
- @request = stub
- DataRequest.stubs(:new).returns(@request)
- @feed = AccountFeedRequest.new
- end
-
- should "have a parsed response" do
- Crack::XML.stubs(:parse)
- @feed.stubs(:response).returns(stub(:body => 'response body'))
- @feed.parsed_response
-
- assert_received(Crack::XML, :parse) {|e| e.with('response body')}
- end
-
- should "have entries from the parsed response" do
- @feed.stubs(:parsed_response).returns({'feed' => {'entry' => ['entry1', 'entry2']}})
- assert_equal ['entry1', 'entry2'], @feed.entries
- end
-
- should "have segements from the parsed response" do
- @feed.stubs(:parsed_response).returns({'feed' => {'dxp:segment' => ['segment1', 'segment2']}})
- assert_equal ['segment1', 'segment2'], @feed.segments
- end
-
- should "have an empty array for entries without a response" do
- @feed.stubs(:parsed_response).returns(nil)
- assert_equal [], @feed.entries
- end
-
- should "have a response from the request" do
- @request.stubs(:send_request)
- @feed.response
- assert_received(@request, :send_request)
- end
- end
- end
-end
View
53 test/unit/garb/account_test.rb
@@ -1,53 +0,0 @@
-require 'test_helper'
-
-module Garb
- class AccountTest < MiniTest::Unit::TestCase
- context "The Account class" do
- should "have an array of accounts with all profiles" do
- p1 = stub(:account_id => '1111', :account_name => 'Blog 1')
- p2 = stub(:account_id => '1112', :account_name => 'Blog 2')
-
- Profile.stubs(:all).returns([p1,p2,p1,p2])
- Account.stubs(:new).returns('account1', 'account2')
-
- assert_equal ['account1','account2'], Account.all
- assert_received(Profile, :all)
- assert_received(Account, :new) {|e| e.with([p1,p1])}
- assert_received(Account, :new) {|e| e.with([p2,p2])}
- end
- end
-
- context "An instance of the Account class" do
- setup do
- profile = stub(:account_id => '1111', :account_name => 'Blog 1')
- @profiles = [profile,profile]
- @account = Account.new(@profiles)
- end
-
- context "all" do
- should "use an optional user session" do
- session = Session.new
- Garb::Profile.expects(:all).with(session).returns(@profiles)
-
- accounts = Account.all(session)
- assert_equal 1, accounts.size
- assert_equal @profiles, accounts.first.profiles
- end
- end
-
- context "when creating a new account from an array of profiles" do
- should "take the account id from the first profile" do
- assert_equal @profiles.first.account_id, @account.id
- end
-
- should "take the account name from the first profile" do
- assert_equal @profiles.first.account_name, @account.name
- end
-
- should "store the array of profiles" do
- assert_equal @profiles, @account.profiles
- end
- end
- end
- end
-end
View
140 test/unit/garb/authentication_request_test.rb
@@ -1,140 +0,0 @@
-require 'test_helper'
-
-CA_CERT_FILE = File.join(File.dirname(__FILE__), '..', '/cacert.pem')
-
-module Garb
- class AuthenticationRequestTest < MiniTest::Unit::TestCase
-
- context "An instance of the AuthenticationRequest class" do
-
- setup { @request = AuthenticationRequest.new('email', 'password') }
- teardown do
- Garb.proxy_address = nil
- Garb.proxy_port = nil
- end
-
- should "have a collection of parameters that include the email and password" do
- expected =
- {
- 'Email' => 'user@example.com',
- 'Passwd' => 'fuzzybunnies',
- 'accountType' => 'HOSTED_OR_GOOGLE',
- 'service' => 'analytics',
- 'source' => 'vigetLabs-garb-001'
- }
-
- request = AuthenticationRequest.new('user@example.com', 'fuzzybunnies')
- assert_equal expected, request.parameters
- end
-
- should "have a URI" do
- assert_equal URI.parse('https://www.google.com/accounts/ClientLogin'), @request.uri
- end
-
- should "be able to send a request to the GAAPI service with proper ssl" do
- @request.expects(:build_request).returns('post')
-
- response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
-
- http = mock do |m|
- m.expects(:use_ssl=).with(true)
- m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
- m.expects(:ca_file=).with(CA_CERT_FILE)
- m.expects(:request).with('post').yields(response)
- end
-
- Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
-
- @request.send_request(OpenSSL::SSL::VERIFY_PEER)
- end
-
- should "be able to send a request to the GAAPI service with ignoring ssl" do
- @request.expects(:build_request).returns('post')
-
- response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
-
- http = mock do |m|
- m.expects(:use_ssl=).with(true)
- m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
- m.expects(:request).with('post').yields(response)
- end
-
- Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
-
- @request.send_request(OpenSSL::SSL::VERIFY_NONE)
- end
-
- should "be able to build a request for the GAAPI service" do
- params = "param"
- @request.expects(:parameters).with().returns(params)
-
- post = mock
- post.expects(:set_form_data).with(params)
-
- Net::HTTP::Post.expects(:new).with('/accounts/ClientLogin').returns(post)
-
- @request.build_request
- end
-
- should "be able to retrieve an auth_token from the body" do
- response_data =
- "SID=mysid\n" +
- "LSID=mylsid\n" +
- "Auth=auth_token\n"
-
- @request.expects(:send_request).with(OpenSSL::SSL::VERIFY_NONE).returns(stub(:body => response_data))
-
- assert_equal 'auth_token', @request.auth_token
- end
-
- should "use VERIFY_PEER if auth_token needs to be secure" do
- response_data =
- "SID=mysid\n" +
- "LSID=mylsid\n" +
- "Auth=auth_token\n"
-
- @request.expects(:send_request).with(OpenSSL::SSL::VERIFY_PEER).returns(stub(:body => response_data))
-
- assert_equal 'auth_token', @request.auth_token(:secure => true)
- end
-
- should "raise an exception when requesting an auth_token when the authorization fails" do
- @request.stubs(:build_request)
- response = mock do |m|
- m.expects(:is_a?).with(Net::HTTPOK).returns(false)
- end
-
- http = stub do |s|
- s.stubs(:use_ssl=)
- s.stubs(:verify_mode=)
- s.stubs(:request).yields(response)
- end
-
- Net::HTTP.stubs(:new).with('www.google.com', 443, nil, nil).returns(http)
-
- assert_raises(Garb::AuthenticationRequest::AuthError) do
- @request.send_request(OpenSSL::SSL::VERIFY_NONE)
- end
- end
-
- should "make use of Garb proxy settings in Net::HTTP request" do
- @request.expects(:build_request).returns('post')
-
- response = stub {|s| s.stubs(:is_a?).returns(true) }
-
- http = mock do |m|
- m.stubs(:use_ssl=)
- m.stubs(:verify_mode=)
- m.stubs(:request).yields(response)
- end
-
- Garb.proxy_address = '127.0.0.1'
- Garb.proxy_port = '1234'
-
- Net::HTTP.expects(:new).with('www.google.com', 443, '127.0.0.1', '1234').returns(http)
-
- @request.send_request(nil)
- end
- end
- end
-end
View
114 test/unit/garb/data_request_test.rb
@@ -1,114 +0,0 @@
-require 'test_helper'
-
-module Garb
- class DataRequestTest < MiniTest::Unit::TestCase
-
- context "An instance of the DataRequest class" do
- setup do
- @session = Session.new
- @session.auth_token = 'abcdefg123456'
- end
-
- teardown do
- Garb.proxy_address = nil
- Garb.proxy_port = nil
- end
-
- should "be able to build the query string from parameters" do
- parameters = {'ids' => '12345', 'metrics' => 'country'}
- data_request = DataRequest.new(@session, "", parameters)
-
- query_string = data_request.query_string
-
- assert_match(/^\?/, query_string)
-
- query_string.sub!(/^\?/, '')
-
- assert_equal ["ids=12345", "metrics=country"], query_string.split('&').sort
- end
-
- should "return an empty query string if parameters are empty" do
- data_request = DataRequest.new(@session, "")
- assert_equal "", data_request.query_string
- end
-
- should "be able to build a uri" do
- url = 'http://example.com'
- assert_equal URI.parse(url), DataRequest.new(@session, url).uri
- end
-
- should "be able to send a request for a single user" do
- @session.stubs(:single_user?).returns(true)
- response = mock('Net::HTTPOK') do |m|
- m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
- end
-
- data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
- data_request.stubs(:single_user_request).returns(response)
- data_request.send_request
-
- assert_received(data_request, :single_user_request)
- end
-
- should "be able to send a request for an oauth user" do
- @session.stubs(:single_user?).returns(false)
- @session.stubs(:oauth_user?).returns(true)
- response = mock('Net::HTTPOK') do |m|
- m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
- end
-
- data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
- data_request.stubs(:oauth_user_request).returns(response)
- data_request.send_request
-
- assert_received(data_request, :oauth_user_request)
- end
-
- should "raise if the request is unauthorized" do
- @session.stubs(:single_user?).returns(false)
- @session.stubs(:oauth_user?).returns(true)
- response = mock('Net::HTTPUnauthorized', :body => 'Error')
-
- data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
- data_request.stubs(:oauth_user_request).returns(response)
-
- assert_raises(Garb::DataRequest::ClientError) do
- data_request.send_request
- end
- end
-
- should "be able to request via the ouath access token" do
- access_token = stub(:get => "responseobject")
- @session.stubs(:access_token).returns(access_token)
-
- data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
- assert_equal 'responseobject', data_request.oauth_user_request
-
- assert_received(@session, :access_token)
- assert_received(access_token, :get) {|e| e.with('https://example.com/data?key=value', {'GData-Version' => '2'})}
- end
-
- should "be able to request via http with an auth token" do
- @session.expects(:auth_token).with().returns('toke')
- response = mock
-
- http = mock do |m|
- m.expects(:use_ssl=).with(true)
- m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
- m.expects(:get).with('/data?key=value', {
- 'Authorization' => 'GoogleLogin auth=toke',
- 'GData-Version' => '2'
- }).returns(response)
- end
-
- Garb.proxy_address = "127.0.0.1"
- Garb.proxy_port = "1234"
- Net::HTTP.expects(:new).with('example.com', 443, "127.0.0.1", "1234").returns(http)
-
- data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
- assert_equal response, data_request.single_user_request
- end
- end
-
- end
-end
View
28 test/unit/garb/destination_test.rb
@@ -1,28 +0,0 @@
-require 'test_helper'
-
-module Garb
- class DestinationTest < MiniTest::Unit::TestCase
- context 'A Destination' do
- should "have a match_type and an expression" do
- destination = Destination.new({'matchType' => 'exact', 'expression' => '/contact.html', 'caseSensitive' => 'false'})
- assert_equal 'exact', destination.match_type
- assert_equal '/contact.html', destination.expression
- end
-
- should "know if it's case sensitive" do
- destination = Destination.new({'matchType' => 'exact', 'expression' => '/contact.html', 'caseSensitive' => 'true'})
- assert_equal true, destination.case_sensitive?
- end
-
- should "know if it's not case sensitive" do
- destination = Destination.new({'matchType' => 'exact', 'expression' => '/contact.html', 'caseSensitive' => 'false'})
- assert_equal false, destination.case_sensitive?
- end
-
- should "have steps" do
- destination = Destination.new({'ga:step' => {'name' => 'Contact', 'number' => '1', 'path' => '/'}})
- assert_equal ['Contact'], destination.steps.map(&:name)
- end
- end
- end
-end
View
55 test/unit/garb/filter_parameters_test.rb
@@ -2,62 +2,45 @@
module Garb
class FilterParametersTest < MiniTest::Unit::TestCase
- def self.should_define_operators(*operators)
- operators.each do |operator|
- should "create an operator and add to parameters for the #{operator} method" do
- new_operator = stub
- symbol = :foo
-
- SymbolOperator.expects(:new).with(:bar, operator).returns(new_operator)
- @filter_parameters.filters do
- send(operator.to_sym, :bar, 100)
- end
-
- parameter = {new_operator => 100}
- assert_equal parameter, @filter_parameters.parameters.last
- end
- end
- end
+ # def self.should_define_operators(*operators)
+ # operators.each do |operator|
+ # should "create an operator and add to parameters for the #{operator} method" do
+ # new_operator = stub
+ # symbol = :foo
+ #
+ # SymbolOperator.expects(:new).with(:bar, operator).returns(new_operator)
+ # @filter_parameters.filters do
+ # send(operator.to_sym, :bar, 100)
+ # end
+ #
+ # parameter = {new_operator => 100}
+ # assert_equal parameter, @filter_parameters.parameters.last
+ # end
+ # end
+ # end
context "A FilterParameters" do
setup do
@filter_parameters = FilterParameters.new
end
- should_define_operators :eql, :not_eql, :gt, :gte, :lt, :lte,
- :matches, :does_not_match, :contains, :does_not_contain, :substring, :not_substring
-
- should "instance eval for filters" do
- blk = lambda {"in a block"}
-
- @filter_parameters.expects(:instance_eval)
- @filter_parameters.filters(&blk)
- end
-
context "when converting parameters hash into query string parameters" do
should "parameterize hash operators and join elements with AND" do
- @filter_parameters.filters do
- eql(:city, 'New York City')
- eql(:state, 'New York')
- end
+ @filter_parameters.parameters << {:city.eql => 'New York City', :state.eql => 'New York'}
params = ['ga:city%3D%3DNew+York+City', 'ga:state%3D%3DNew+York']
assert_equal params, @filter_parameters.to_params['filters'].split('%3B').sort
end
should "properly encode operators" do
- @filter_parameters.filters do
- contains(:page_path, 'New York')
- end
+ @filter_parameters.parameters << {:page_path.contains => 'New York'}
params = {'filters' => 'ga:pagePath%3D~New+York'}
assert_equal params, @filter_parameters.to_params
end
should "escape comma, semicolon, and backslash in values" do
- @filter_parameters.filters do
- eql(:url, 'this;that,thing\other')
- end
+ @filter_parameters.parameters << {:url.eql => 'this;that,thing\other'}
params = {'filters' => 'ga:url%3D%3Dthis%5C%3Bthat%5C%2Cthing%5C%5Cother'}
assert_equal params, @filter_parameters.to_params
View
24 test/unit/garb/goal_test.rb
@@ -1,24 +0,0 @@
-require 'test_helper'
-
-module Garb
- class GoalTest < MiniTest::Unit::TestCase
- context "A Goal" do
- should "have a name, number, and value" do
- goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
- assert_equal 'Read Blog', goal.name
- assert_equal 1, goal.number
- assert_equal 10.0, goal.value
- end
-
- should "know if it is active" do
- goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
- assert goal.active?
- end
-
- should "know if it is not active" do
- goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'false'})
- assert_equal false, goal.active?
- end
- end
- end
-end
View
2  test/unit/garb/management/feed_test.rb
@@ -6,7 +6,7 @@ class FeedTest < MiniTest::Unit::TestCase
context "a Feed" do
setup do
@request = stub
- DataRequest.stubs(:new).returns(@request)
+ Request::Data.stubs(:new).returns(@request)
@feed = Feed.new(Garb::Session.new, '/accounts')
end
View
2  test/unit/garb/model_test.rb
@@ -57,7 +57,7 @@ class ModelTest < MiniTest::Unit::TestCase
context "when getting results" do
setup do
@response = stub(:body => "raw report data")
- DataRequest.stubs(:new).returns(stub(:send_request => @response))
+ Request::Data.stubs(:new).returns(stub(:send_request => @response))
ReportResponse.stubs(:new).returns(stub(:results => ['result']))
@test_model.stubs(:metrics).returns(stub(:to_params => {'metrics' => 'ga:visits'}))
View
77 test/unit/garb/profile_test.rb
@@ -1,77 +0,0 @@
-require 'test_helper'
-
-module Garb
- class ProfileTest < MiniTest::Unit::TestCase
-
- context "The Profile class" do
- setup {@session = Session.new}
-
- should "be able to return a list of all profiles" do
- afr = AccountFeedRequest.new
- afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
- AccountFeedRequest.stubs(:new).returns(afr)
-
- assert_equal ['12345', '12346'], Profile.all(@session).map(&:id)
- assert_received(AccountFeedRequest, :new) {|e| e.with(@session)}
- end
-
- should "return the first profile for a given web property id" do
- profile1 = stub(:web_property_id => '12345', :id => 'abcdef')
- profile2 = stub(:web_property_id => '67890', :id => 'ghijkl')
- entries = [profile1, profile2]
-
- Profile.stubs(:all).returns(entries)
-
- assert_equal profile1, Profile.first('12345', @session)
-
- assert_received(Profile, :all) {|e| e.with(@session)}
- end
-
- should "return the first profile for a given table id" do
- profile1 = stub(:id => '12345', :web_property_id => 'abcdef')
- profile2 = stub(:id => '67890', :web_property_id => 'ghijkl')
- entries = [profile1, profile2]
-
- Profile.stubs(:all).returns(entries)
-
- assert_equal profile2, Profile.first('67890', @session)
-
- assert_received(Profile, :all) {|e| e.with(@session)}
- end
- end
-
- context "A Profile" do
- setup do
- afr = AccountFeedRequest.new
- afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
-
- entry = afr.entries.first
- @profile = Profile.new(entry, Session)
- end
-
- should "have a value for :title" do
- assert_equal "Historical", @profile.title
- end
-
- should "have a value for :table_id" do
- assert_equal 'ga:12345', @profile.table_id
- end
-
- should "have a value for :id" do
- assert_equal '12345', @profile.id
- end
-
- should "have a value for :account_id" do
- assert_equal '1111', @profile.account_id
- end
-
- should "have a value for :account_name" do
- assert_equal 'Blog Beta', @profile.account_name
- end
-
- should "have goals" do
- assert_equal 4, @profile.goals.size
- end
- end
- end
-end
View
99 test/unit/garb/report_test.rb
@@ -1,99 +0,0 @@
-require 'test_helper'
-
-module Garb
- # Also tests Garb::Resource, which is the basis for Garb::Report
- class ReportTest < MiniTest::Unit::TestCase
- context "An instance of the Report class" do
- setup do
- @now = Time.now
- Time.stubs(:now).returns(@now)
- @profile = stub(:table_id => 'ga:1234', :session => Session)
- @report = Report.new(@profile)
- end
-
- %w(metrics dimensions sort).each do |param|
- should "have parameters for #{param}" do
- assert @report.send(:"#{param}").is_a?(ReportParameter)
- end
-
- should "clear parameters for #{param}" do
- assert_equal({}, @report.send(:"clear_#{param}").to_params)
- end
- end
-
- should "have filter parameters for filters" do
- assert @report.filters.is_a?(FilterParameters)
- end
-
- should "add new filters to filter parameters" do
- @report.clear_filters
- hash = {:thing.gt => 'val'}
- @report.filters hash
-
- assert_equal hash, @report.filters.parameters.first
- end
-
- should "clear filter parameters for filters" do
- assert_equal({}, @report.clear_filters.to_params)
- end
-
- should "have default parameters" do
- @report.stubs(:format_time).returns('2009-08-01')
- params = {'ids' => 'ga:1234', 'start-date' => '2009-08-01', 'end-date' => '2009-08-01'}
- assert_equal params, @report.default_params
- end
-
- should "allow setting a segment id to the segment params" do
- @report.set_segment_id 121
- assert_equal({'segment' => 'gaid::121'}, @report.segment_params)
- end
-
- should "collect params from metrics, dimensions, filters, sort, and defaults" do
- @report.stubs(:metrics).returns(stub(:to_params => {'metrics' => 6}))
- @report.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 5}))
- @report.stubs(:filters).returns(stub(:to_params => {'filters' => 4}))
- @report.stubs(:sort).returns(stub(:to_params => {'sort' => 3}))
- @report.stubs(:page_params).returns({'page_params' => 2})
- @report.stubs(:default_params).returns({'default_params' => 1})
- @report.stubs(:segment_params).returns({'segment' => 'gaid::10'})
-
- expected_params = {'metrics' => 6,'dimensions' => 5, 'filters' => 4, 'sort' => 3,
- 'page_params' => 2, 'default_params' => 1, 'segment' => 'gaid::10'}
-
- assert_equal expected_params, @report.params
- end
-
- should "format time" do
- assert_equal @now.strftime('%Y-%m-%d'), @report.format_time(@now)
- end
-
- should "send a data request to GA" do
- response = mock {|m| m.expects(:body).returns('response body') }
- request = mock {|m| m.expects(:send_request).returns(response) }
- @report.expects(:params).returns('params')
-
- DataRequest.expects(:new).with(Session, Garb::Report::URL, 'params').returns(request)
- assert_equal 'response body', @report.send_request_for_body
- end
-
- should "fetch and parse results from GA" do
- @report.expects(:send_request_for_body).with().returns('xml')
- ReportResponse.expects(:new).with('xml').returns(mock(:results => ['entry']))
- assert_equal ['entry'], @report.results
- end
- end
-
- context "An instance of the Report class with initial options" do
- setup do
- @profile = stub(:table_id => 'ga:1234')
- @report = Report.new(@profile, :limit => 10, :offset => 20)
- end
-
- should "have page paramaters" do
- params = {'max-results' => 10, 'start-index' => 20}
- assert_equal params, @report.page_params
- end
- end
-
- end
-end
View
142 test/unit/garb/request/authentication_test.rb
@@ -0,0 +1,142 @@
+require 'test_helper'
+
+CA_CERT_FILE = File.join(File.dirname(__FILE__), '..', '/cacert.pem')
+
+module Garb
+ module Request
+ class AuthenticationTest < MiniTest::Unit::TestCase
+
+ context "An instance of the Request::Authentication class" do
+
+ setup { @request = Request::Authentication.new('email', 'password') }
+ teardown do
+ Garb.proxy_address = nil
+ Garb.proxy_port = nil
+ end
+
+ should "have a collection of parameters that include the email and password" do
+ expected =
+ {
+ 'Email' => 'user@example.com',
+ 'Passwd' => 'fuzzybunnies',
+ 'accountType' => 'HOSTED_OR_GOOGLE',
+ 'service' => 'analytics',
+ 'source' => 'vigetLabs-garb-001'
+ }
+
+ request = Request::Authentication.new('user@example.com', 'fuzzybunnies')
+ assert_equal expected, request.parameters
+ end
+
+ should "have a URI" do
+ assert_equal URI.parse('https://www.google.com/accounts/ClientLogin'), @request.uri
+ end
+
+ should "be able to send a request to the GAAPI service with proper ssl" do
+ @request.expects(:build_request).returns('post')
+
+ response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
+
+ http = mock do |m|
+ m.expects(:use_ssl=).with(true)
+ m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
+ m.expects(:ca_file=).with(CA_CERT_FILE)
+ m.expects(:request).with('post').yields(response)
+ end
+
+ Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
+
+ @request.send_request(OpenSSL::SSL::VERIFY_PEER)
+ end
+
+ should "be able to send a request to the GAAPI service with ignoring ssl" do
+ @request.expects(:build_request).returns('post')
+
+ response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
+
+ http = mock do |m|
+ m.expects(:use_ssl=).with(true)
+ m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
+ m.expects(:request).with('post').yields(response)
+ end
+
+ Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
+
+ @request.send_request(OpenSSL::SSL::VERIFY_NONE)
+ end
+
+ should "be able to build a request for the GAAPI service" do
+ params = "param"
+ @request.expects(:parameters).with().returns(params)
+
+ post = mock
+ post.expects(:set_form_data).with(params)
+
+ Net::HTTP::Post.expects(:new).with('/accounts/ClientLogin').returns(post)
+
+ @request.build_request
+ end
+
+ should "be able to retrieve an auth_token from the body" do
+ response_data =
+ "SID=mysid\n" +
+ "LSID=mylsid\n" +
+ "Auth=auth_token\n"
+
+ @request.expects(:send_request).with(OpenSSL::SSL::VERIFY_NONE).returns(stub(:body => response_data))
+
+ assert_equal 'auth_token', @request.auth_token
+ end
+
+ should "use VERIFY_PEER if auth_token needs to be secure" do
+ response_data =
+ "SID=mysid\n" +
+ "LSID=mylsid\n" +
+ "Auth=auth_token\n"
+
+ @request.expects(:send_request).with(OpenSSL::SSL::VERIFY_PEER).returns(stub(:body => response_data))
+
+ assert_equal 'auth_token', @request.auth_token(:secure => true)
+ end
+
+ should "raise an exception when requesting an auth_token when the authorization fails" do
+ @request.stubs(:build_request)
+ response = mock do |m|
+ m.expects(:is_a?).with(Net::HTTPOK).returns(false)
+ end
+
+ http = stub do |s|
+ s.stubs(:use_ssl=)
+ s.stubs(:verify_mode=)
+ s.stubs(:request).yields(response)
+ end
+
+ Net::HTTP.stubs(:new).with('www.google.com', 443, nil, nil).returns(http)
+
+ assert_raises(Garb::Request::Authentication::AuthError) do
+ @request.send_request(OpenSSL::SSL::VERIFY_NONE)
+ end
+ end
+
+ should "make use of Garb proxy settings in Net::HTTP request" do
+ @request.expects(:build_request).returns('post')
+
+ response = stub {|s| s.stubs(:is_a?).returns(true) }
+
+ http = mock do |m|
+ m.stubs(:use_ssl=)
+ m.stubs(:verify_mode=)
+ m.stubs(:request).yields(response)
+ end
+
+ Garb.proxy_address = '127.0.0.1'
+ Garb.proxy_port = '1234'
+
+ Net::HTTP.expects(:new).with('www.google.com', 443, '127.0.0.1', '1234').returns(http)
+
+ @request.send_request(nil)
+ end
+ end
+ end
+ end
+end
View
116 test/unit/garb/request/data_test.rb
@@ -0,0 +1,116 @@
+require 'test_helper'
+
+module Garb
+ module Request
+ class DataTest < MiniTest::Unit::TestCase
+
+ context "An instance of the Request::Data class" do
+ setup do
+ @session = Session.new
+ @session.auth_token = 'abcdefg123456'
+ end
+
+ teardown do
+ Garb.proxy_address = nil
+ Garb.proxy_port = nil
+ end
+
+ should "be able to build the query string from parameters" do
+ parameters = {'ids' => '12345', 'metrics' => 'country'}
+ data_request = Request::Data.new(@session, "", parameters)
+
+ query_string = data_request.query_string
+
+ assert_match(/^\?/, query_string)
+
+ query_string.sub!(/^\?/, '')
+
+ assert_equal ["ids=12345", "metrics=country"], query_string.split('&').sort
+ end
+
+ should "return an empty query string if parameters are empty" do
+ data_request = Request::Data.new(@session, "")
+ assert_equal "", data_request.query_string
+ end
+
+ should "be able to build a uri" do
+ url = 'http://example.com'
+ assert_equal URI.parse(url), Request::Data.new(@session, url).uri
+ end
+
+ should "be able to send a request for a single user" do
+ @session.stubs(:single_user?).returns(true)
+ response = mock('Net::HTTPOK') do |m|
+ m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
+ end
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ data_request.stubs(:single_user_request).returns(response)
+ data_request.send_request
+
+ assert_received(data_request, :single_user_request)
+ end
+
+ should "be able to send a request for an oauth user" do
+ @session.stubs(:single_user?).returns(false)
+ @session.stubs(:oauth_user?).returns(true)
+ response = mock('Net::HTTPOK') do |m|
+ m.expects(:kind_of?).with(Net::HTTPSuccess).returns(true)
+ end
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ data_request.stubs(:oauth_user_request).returns(response)
+ data_request.send_request
+
+ assert_received(data_request, :oauth_user_request)
+ end
+
+ should "raise if the request is unauthorized" do
+ @session.stubs(:single_user?).returns(false)
+ @session.stubs(:oauth_user?).returns(true)
+ response = mock('Net::HTTPUnauthorized', :body => 'Error')
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ data_request.stubs(:oauth_user_request).returns(response)
+
+ assert_raises(Garb::Request::Data::ClientError) do
+ data_request.send_request
+ end
+ end
+
+ should "be able to request via the ouath access token" do
+ access_token = stub(:get => "responseobject")
+ @session.stubs(:access_token).returns(access_token)
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ assert_equal 'responseobject', data_request.oauth_user_request
+
+ assert_received(@session, :access_token)
+ assert_received(access_token, :get) {|e| e.with('https://example.com/data?key=value', {'GData-Version' => '2'})}
+ end
+
+ should "be able to request via http with an auth token" do
+ @session.expects(:auth_token).with().returns('toke')
+ response = mock
+
+ http = mock do |m|
+ m.expects(:use_ssl=).with(true)
+ m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
+ m.expects(:get).with('/data?key=value', {
+ 'Authorization' => 'GoogleLogin auth=toke',
+ 'GData-Version' => '2'
+ }).returns(response)
+ end
+
+ Garb.proxy_address = "127.0.0.1"
+ Garb.proxy_port = "1234"
+ Net::HTTP.expects(:new).with('example.com', 443, "127.0.0.1", "1234").returns(http)
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ assert_equal response, data_request.single_user_request
+ end
+ end
+
+ end
+ end
+end
View
50 test/unit/garb/resource_test.rb
@@ -1,50 +0,0 @@
-require 'test_helper'
-
-# Most of the resource testing is done as a part of ReportTest
-class ResourceTest < MiniTest::Unit::TestCase
-
- context "A class with Garb::Resource mixed in" do
- setup do
- @test_report = Class.new
- @test_report.extend(Garb::Resource)
- end
-
- should "get results from GA" do
- profile = stub(:is_a? => true)
- @test_report.expects(:send_request_for_body).returns('xml')
- Garb::ReportResponse.expects(:new).with('xml', OpenStruct).returns(mock(:results => 'analytics'))
-
- assert_equal 'analytics', @test_report.results(profile)
- end
-
- should "get results from GA using a specific user session" do
- profile = '123'
- session = Garb::Session.new
- @test_report.expects(:send_request_for_body).returns('xml')
- Garb::ReportResponse.expects(:new).with('xml', OpenStruct).returns(mock(:results => 'analytics'))
- Garb::Profile.expects(:first).with(profile, session).returns(mock('Garb::Profile'))
-
- assert_equal 'analytics', @test_report.results(profile, :session => session)
- end
-
- should "permit setting a segment id" do
- @test_report.set_segment_id 1
- assert_equal "gaid::1", @test_report.segment
- end
-
- should "permit setting a klass used for instantiation of results" do
- TestKlass = Class.new(OpenStruct)
- @test_report.set_instance_klass TestKlass
- assert_equal TestKlass, @test_report.instance_klass
- end
-
- should "return an empty result set if profile is invalid" do
- profile = '123'
- @test_report.expects(:send_request_for_body).never
- Garb::ReportResponse.expects(:new).never
-
- Garb::Profile.expects(:first).returns(nil)
- assert_equal [], @test_report.results(profile)
- end
- end
-end
View
12 test/unit/garb/session_test.rb
@@ -7,7 +7,7 @@ class SessionTest < MiniTest::Unit::TestCase
should "be able retrieve an auth_token for a user" do
auth_request = mock {|m| m.expects(:auth_token).with({}).returns('toke') }
- AuthenticationRequest.expects(:new).with('email', 'password', {}).returns(auth_request)
+ Request::Authentication.expects(:new).with('email', 'password', {}).returns(auth_request)
Session.login('email', 'password')
assert_equal 'toke', Session.auth_token
@@ -16,14 +16,14 @@ class SessionTest < MiniTest::Unit::TestCase
should "be able retrieve an auth_token for a user with secure ssl" do
opts = {:secure => true, :account_type => 'GOOGLE'}
auth_request = mock {|m| m.expects(:auth_token).with(opts).returns('toke') }
- AuthenticationRequest.expects(:new).with('email', 'password', opts).returns(auth_request)
+ Request::Authentication.expects(:new).with('email', 'password', opts).returns(auth_request)
Session.login('email', 'password', opts)
assert_equal 'toke', Session.auth_token
end
should "retain the email address for this session" do
- AuthenticationRequest.stubs(:new).returns(stub(:auth_token => 'toke'))
+ Request::Authentication.stubs(:new).returns(stub(:auth_token => 'toke'))
Session.login('email', 'password')
assert_equal 'email', Session.email
@@ -47,7 +47,7 @@ class SessionTest < MiniTest::Unit::TestCase
should "be able retrieve an auth_token for a user" do
auth_request = mock {|m| m.expects(:auth_token).with({}).returns('toke') }
- AuthenticationRequest.expects(:new).with('email', 'password', {}).returns(auth_request)
+ Request::Authentication.expects(:new).with('email', 'password', {}).returns(auth_request)
@session.login('email', 'password')
assert_equal 'toke', @session.auth_token
@@ -56,14 +56,14 @@ class SessionTest < MiniTest::Unit::TestCase
should "be able retrieve an auth_token for a user with secure ssl" do
opts = {:secure => true, :account_type => 'GOOGLE'}
auth_request = mock {|m| m.expects(:auth_token).with(opts).returns('toke') }
- AuthenticationRequest.expects(:new).with('email', 'password', opts).returns(auth_request)
+ Request::Authentication.expects(:new).with('email', 'password', opts).returns(auth_request)
@session.login('email', 'password', opts)
assert_equal 'toke', @session.auth_token
end
should "retain the email address for this session" do
- AuthenticationRequest.stubs(:new).returns(stub(:auth_token => 'toke'))
+ Request::Authentication.stubs(:new).returns(stub(:auth_token => 'toke'))
@session.login('email', 'password')
assert_equal 'email', @session.email
View
15 test/unit/garb/step_test.rb
@@ -1,15 +0,0 @@
-require 'test_helper'
-
-module Garb
- class StepTest < MiniTest::Unit::TestCase
- context "A Step" do
- should "have a name, number, and path" do
- step = Step.new({'name' => 'Contact Form Page', 'number' => '1', 'path' => '/contact.html'})
-
- assert_equal 'Contact Form Page', step.name
- assert_equal 1, step.number
- assert_equal '/contact.html', step.path
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.