Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

"bin/collector" replaced by using a gem

  • Loading branch information...
commit 8168bc2dc73c754b76800ea2bfec5951c50e7e13 1 parent a7bb78c
Pawel Badenski authored
6 README.md
View
@@ -7,7 +7,7 @@ Collect the statics specified by the configuration from google analytics
The first thing that must be done when using this collector is to authorise the application with google. First you will need
to [generate an authorisation code](https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/analytics.readonly&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=1054017153726.apps.googleusercontent.com).
-This code then needs to be passed to the `bin/collector` command line script using `--authorisation_code=CODE`
+This code then needs to be passed to the `collector` command line script using `--authorisation_code=CODE`
## Message Format
@@ -26,12 +26,12 @@ This code then needs to be passed to the `bin/collector` command line script usi
## Usage
-This collector is run from the command line with the `bin/collector` script. This command requires an action which
+This collector is run from the command line with the `collector` script. This command requires an action which
can be either `help`, `print` or `broadcast`. It also requires a `--config` option which defines which configuration
class is used. For example the following command will print messages to the terminal using the `WeeklyUniqueVisitors`
configuration.
- $ bundle exec bin/collector --config=WeeklyUniqueVisitors print
+ $ bundle exec collector --config=WeeklyUniqueVisitors print
### Other Options
99 bin/collector
View
@@ -1,99 +0,0 @@
-#!/usr/bin/env ruby
-# Collects the statistics from google analytics.
-# Run: './bin/collector -t TOKEN -c ConfigName print' (the first time)
-# Run: './bin/collector -c ConfigName print' (subsequent times)
-#
-# To obtain authorisation code please visit:
-#
-# https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/analytics.readonly&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=70519367703-3j2pb73bd9kjr800coecnt5jv4ntfeso.apps.googleusercontent.com
-
-require 'bundler/setup'
-Bundler.require
-
-Dir[File.expand_path(File.join(File.dirname(__FILE__), "../lib/**/*.rb"))].each { |f| require f }
-
-include GLI
-
-program_desc "Collect the statics specified by the configuration from google analytics"
-
-version 0.1
-
-desc "Only for the first request you need to pass in the authorisation code"
-default_value nil
-arg_name "authorisation code"
-flag [:a, :authorisation_code]
-
-desc "The name of the configuration module to specify the what data to collect from GA and where to put it."
-arg_name "configuration module"
-default_value ""
-flag [:c, :config]
-
-desc "Days ago"
-arg_name "how many days to go back"
-default_value nil
-flag [:d, :days_ago]
-
-
-def config(global_options)
- config = global_options[:config]
- if GoogleAnalytics::Config::Base.descendants.include?(config)
- config_class = GoogleAnalytics::Config.const_get(config)
- days_ago = global_options[:days_ago].to_i
- if days_ago.zero?
- if config_class.respond_to?(:for)
- [config_class.for(Date.today - 1)]
- else
- [config_class.last_before(Date.today)]
- end
- else
- config_class.all_within(Date.today - days_ago, Date.today)
- end
- else
- logger.error { "Invalid collector configuration or none given. Please choose a configuration from [#{GoogleAnalytics::Config::Base.descendants.join(", ")}]." }
- end
-end
-
-def collector(global_options)
- authentication_code = global_options[:authorisation_code]
- GoogleAnalytics::Collector.new(authentication_code, config(global_options))
-end
-
-
-command :print do |c|
- c.desc "Print out the collected statistics"
- c.action do |global_options, options, args|
- begin
- puts collector(global_options).collect_as_json
- rescue Exception => e
- Airbrake.notify(e)
- raise e
- end
- end
-end
-
-command :search do |c|
- c.desc "Search the collected messages for a given string or strings"
- c.action do |global_options, options, args|
- collector(global_options).collect_as_json.each { |m|
- if args.any? { |arg| m.include?(arg) }
- puts m
- end
- }
- end
-end
-
-
-command :broadcast do |c|
- c.desc "Publish the collected statistics to the queue"
- c.action do |global_options, options, args|
- begin
- collector(global_options).broadcast
- rescue Exception => e
- Airbrake.notify(e)
- raise e
- end
- end
-end
-
-
-exit run(ARGV)
2  config/schedule.rb
View
@@ -3,7 +3,7 @@
:standard => "#{root_path}/log/cron.out.log",
:error => "#{root_path}/log/cron.err.log"
}
-job_type :collector, "cd :path && RACK_ENV=:environment bundle exec bin/collector --config=:config --days_ago=:days_ago :task :output"
+job_type :collector, "cd :path && RACK_ENV=:environment bundle exec collector --config=:config --days_ago=:days_ago :task :output"
every :sunday, :at => '5am' do
2  lib/tasks/collect.rake
View
@@ -22,7 +22,7 @@ namespace :collect do
task key do
rack_env = ENV.fetch('RACK_ENV', 'development')
root_path = File.expand_path(File.dirname(__FILE__) + "/../../")
- sh %{cd #{root_path} && RACK_ENV=#{rack_env} bundle exec bin/collector --config=#{params[:config]} --days_ago=#{params[:days_ago]} broadcast}
+ sh %{cd #{root_path} && RACK_ENV=#{rack_env} bundle exec collector --config=#{params[:config]} --days_ago=#{params[:days_ago]} broadcast}
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.