Permalink
Browse files

Merge branch 'master' of https://github.com/vigetlabs/garb

  • Loading branch information...
2 parents d7c5b1c + 9b6fb84 commit 68ddaef1d780fe1c06f5d4e1ee51e69b73f60b82 @stevenwilkin committed Jul 28, 2011
Showing with 586 additions and 1,117 deletions.
  1. +1 −2 .bundle/config
  2. +6 −0 CHANGELOG.md
  3. +3 −2 Gemfile
  4. +3 −4 Gemfile.lock
  5. +10 −5 README.md
  6. +1 −1 Rakefile
  7. +5 −6 garb.gemspec
  8. +49 −33 lib/garb.rb
  9. +0 −22 lib/garb/account.rb
  10. +0 −25 lib/garb/account_feed_request.rb
  11. +0 −53 lib/garb/authentication_request.rb
  12. +0 −42 lib/garb/data_request.rb
  13. +14 −22 lib/garb/filter_parameters.rb
  14. +0 −20 lib/garb/goal.rb
  15. +2 −2 lib/garb/management/feed.rb
  16. +2 −4 lib/garb/model.rb
  17. +0 −33 lib/garb/profile.rb
  18. +0 −28 lib/garb/report.rb
  19. +8 −8 lib/garb/report_response.rb
  20. +57 −0 lib/garb/request/authentication.rb
  21. +55 −0 lib/garb/request/data.rb
  22. +0 −115 lib/garb/resource.rb
  23. +1 −1 lib/garb/session.rb
  24. +1 −1 lib/garb/version.rb
  25. +5 −0 lib/support.rb
  26. +49 −0 lib/support/string.rb
  27. +1 −0 test/fixtures/profile_feed.json
  28. +1 −0 test/fixtures/report_feed.json
  29. +1 −2 test/test_helper.rb
  30. +0 −42 test/unit/garb/account_feed_request_test.rb
  31. +0 −53 test/unit/garb/account_test.rb
  32. +0 −121 test/unit/garb/authentication_request_test.rb
  33. +0 −107 test/unit/garb/data_request_test.rb
  34. +0 −28 test/unit/garb/destination_test.rb
  35. +22 −43 test/unit/garb/filter_parameters_test.rb
  36. +0 −24 test/unit/garb/goal_test.rb
  37. +1 −1 test/unit/garb/management/account_test.rb
  38. +4 −4 test/unit/garb/management/feed_test.rb
  39. +1 −1 test/unit/garb/management/profile_test.rb
  40. +1 −1 test/unit/garb/management/web_property_test.rb
  41. +4 −5 test/unit/garb/model_test.rb
  42. +0 −77 test/unit/garb/profile_test.rb
  43. +8 −8 test/unit/garb/report_response_test.rb
  44. +0 −99 test/unit/garb/report_test.rb
  45. +147 −0 test/unit/garb/request/authentication_test.rb
  46. +116 −0 test/unit/garb/request/data_test.rb
  47. +0 −50 test/unit/garb/resource_test.rb
  48. +6 −6 test/unit/garb/session_test.rb
  49. +0 −15 test/unit/garb/step_test.rb
  50. +1 −1 test/unit/garb_test.rb
View
@@ -1,2 +1 @@
----
-BUNDLE_DISABLE_SHARED_GEMS: "1"
+--- {}
View
@@ -1,3 +1,9 @@
+Version 0.9.2
+
+ * Removed all deprecated features: Garb::Report, Garb::Resource, Garb::Profile, and Garb::Account
+ * Moved the differing types of requests into a module, will refactor to share more code
+ * Fixed OR'ing in :filters option for results
+
Version 0.9.0
* New Garb::Model is solid. Garb::Resource and Garb::Report are deprecated.
View
@@ -1,15 +1,16 @@
source :rubygems
source "http://gems.github.com"
+gem 'rake', '~> 0.8.7'
+
gem 'i18n'
-gem 'activesupport'
-gem 'crack'
group :test do
gem 'shoulda'
gem 'simplecov'
gem 'minitest', :require => false
gem 'jferris-mocha', :require => false
+ gem 'yajl-ruby'
end
group :demo do
View
@@ -2,8 +2,6 @@ GEM
remote: http://rubygems.org/
remote: http://gems.github.com/
specs:
- activesupport (3.0.3)
- crack (0.1.8)
i18n (0.4.2)
jferris-mocha (0.9.8.20100526112143)
rake
@@ -14,16 +12,17 @@ GEM
simplecov (0.3.7)
simplecov-html (>= 0.3.7)
simplecov-html (0.3.9)
+ yajl-ruby (0.8.2)
PLATFORMS
ruby
DEPENDENCIES
- activesupport
- crack
i18n
jferris-mocha
minitest
oauth
+ rake (~> 0.8.7)
shoulda
simplecov
+ yajl-ruby
View
@@ -6,6 +6,9 @@ Garb
Important Changes
=================
+ It has now been nearly 6 months, I have removed the deprecated features listed below in master.
+ I will release 0.9.2 shortly, with these features removed.
+
With The release of version 0.9.0 I have officially deprecated Garb::Report, Garb::Resource,
Garb::Profile, and Garb::Account. Garb::Report and Garb::Resource should be replaced by Garb::Model.
Garb::Profile and Garb::Account are supplanted by their Garb::Management::* counterparts.
@@ -38,15 +41,15 @@ OAuth Access Token
> Garb::Session.access_token = access_token # assign from oauth gem
Accounts, WebProperties, Profiles, and Goals
---------
+--------------------------------------------
> Garb::Management::Account.all
> Garb::Management::WebProperty.all
> Garb::Management::Profile.all
> Garb::Management::Goal.all
Profiles for a UA- Number (a WebProperty)
---------
+-----------------------------------------
> profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == 'UA-XXXXXXX-X'}
@@ -150,12 +153,13 @@ Requirements for Testing
------------------------
* shoulda
- * jferris-mocha
+ * mocha
+ * bourne
Install
-------
- gem install garb
+ gem install garb OR with bundler: gem 'garb' and `bundle install`
Contributors
------------
@@ -165,13 +169,14 @@ Contributors
* Patrick Reagan
* Justin Marney
* Nick Plante
+ * James Cook
License
-------
(The MIT License)
- Copyright (c) 2010 Viget Labs
+ Copyright (c) 2011 Viget Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
s.authors = ['Tony Pitale']
s.email = 'tony.pitale@viget.com'
s.homepage = 'http://github.com/vigetlabs/garb'
- s.files = %w(README.md Rakefile) + Dir.glob("lib/**/*")
+ s.files = %w(README.md CHANGELOG.md Rakefile) + Dir.glob("lib/**/*")
s.test_files = Dir.glob("test/**/*")
s.add_dependency("crack", [">= 0.1.6"])
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -3,42 +3,44 @@
require 'cgi'
require 'ostruct'
-require 'crack'
-begin
- require 'active_support/inflector'
- require 'active_support/deprecation'
+begin
+ require 'yajl/json_gem' # JSON.parse
rescue LoadError
- require 'active_support'
+ require 'json'
end
-require 'garb/version'
-require 'garb/authentication_request'
-require 'garb/data_request'
-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/model'
-
-# management
-require 'garb/management/feed'
-require 'garb/management/segment'
-require 'garb/management/account'
-require 'garb/management/web_property'
-require 'garb/management/profile'
-require 'garb/management/goal'
+module Garb
+ autoload :Destination, 'garb/destination'
+ autoload :FilterParameters, 'garb/filter_parameters'
+ autoload :Model, 'garb/model'
+ autoload :ProfileReports, 'garb/profile_reports'
+ autoload :ReportParameter, 'garb/report_parameter'
+ autoload :ReportResponse, 'garb/report_response'
+ autoload :ResultSet, 'garb/result_set'
+ autoload :Session, 'garb/session'
+ autoload :Step, 'garb/step'
+ autoload :Version, 'garb/version'
+
+ module Management
+ autoload :Account, 'garb/management/account'
+ autoload :Feed, 'garb/management/feed'
+ autoload :Goal, 'garb/management/goal'
+ autoload :Profile, 'garb/management/profile'
+ autoload :Segment, 'garb/management/segment'
+ autoload :WebProperty, 'garb/management/web_property'
+ end
+
+ module Request
+ autoload :Authentication, "garb/request/authentication"
+ autoload :Data, 'garb/request/data'
+ end
+end
+
+# require 'garb/account_feed_request'
+# require 'garb/resource'
+# require 'garb/report'
+
require 'support'
@@ -47,6 +49,15 @@ module Garb
extend self
+ class << self
+ attr_accessor :proxy_address, :proxy_port, :proxy_user, :proxy_password
+ attr_writer :read_timeout
+ end
+
+ def read_timeout
+ @read_timeout || 60
+ end
+
def to_google_analytics(thing)
return thing.to_google_analytics if thing.respond_to?(:to_google_analytics)
@@ -60,10 +71,15 @@ def from_google_analytics(thing)
alias :from_ga :from_google_analytics
def parse_properties(entry)
- Hash[entry['dxp:property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
+ Hash[entry['dxp$property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
end
def parse_link(entry, rel)
entry['link'].detect {|link| link["rel"] == rel}['href']
end
+
+ # new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil)
+
+ # opts => open_timeout, read_timeout, ssl_timeout
+ # probably just support open_timeout
end
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)
- 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)
- 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
Oops, something went wrong.

0 comments on commit 68ddaef

Please sign in to comment.