Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Log size of record for each model to Google SpreadSheet

  • Loading branch information...
commit 878b77077e8c1dc28127bd521d32d82e4a693eb1 1 parent e04e5a6
@mataki authored
View
1  Gemfile
@@ -31,6 +31,7 @@ gem "amazon-ecs"
gem "carrierwave"
gem "fog"
gem "delayed_job"
+gem "google-spreadsheet-ruby"
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
View
5 Gemfile.lock
@@ -60,6 +60,9 @@ GEM
nokogiri (>= 1.4.4)
ruby-hmac
formatador (0.1.3)
+ google-spreadsheet-ruby (0.1.2)
+ nokogiri (>= 1.4.3.1)
+ oauth (>= 0.3.6)
haml (3.0.25)
haml-rails (0.3.4)
actionpack (~> 3.0)
@@ -84,6 +87,7 @@ GEM
net-ssh (2.1.4)
nifty-generators (0.4.5)
nokogiri (1.4.4)
+ oauth (0.4.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
@@ -143,6 +147,7 @@ DEPENDENCIES
carrierwave
delayed_job
fog
+ google-spreadsheet-ruby
haml
haml-rails
jquery-rails
View
2  README
@@ -8,6 +8,8 @@
heroku config:add FACEBOOK_APP_ID=XXXXXXXX FACEBOOK_APP_SECRET=XXXXXXXX
heroku config:add AMAZON_ACCESS_KEY=XXXXXX AMAZON_SECRET_KEY=XXXXXX
+heroku config:add AWS_S3_KEY_ID=XXXXXX AWS_S3_SECRET_KEY=XXXXXX AWS_S3_BUCKET=XXXXXXX
+heroku config:add GOOGLE_CONSUMER_KEY=XXXXXX GOOGLE_CONSUMER_SECRET=XXXXXX GOOGLE_ACCESS_TOKEN=XXXXXXX GOOGLE_ACCESS_SECRET=XXXXXX GOOGLE_LOG_SHEET_KEY=XXXXX
== This app's article
View
53 lib/log_gss.rb
@@ -0,0 +1,53 @@
+require "oauth"
+require "google_spreadsheet"
+
+class LogGss
+
+ def self.update(arr)
+ self.new.update(arr)
+ end
+
+ def insert_row
+ @insert_row ||= worksheet.num_rows + 1
+ end
+
+ def update(arr)
+ arr.unshift(Time.now.to_s(:db))
+ arr.each_with_index do |item, index|
+ worksheet[insert_row, index+1] = item
+ end
+ worksheet.save
+ end
+
+ def worksheet
+ @worksheet ||= sheet.worksheets.first
+ end
+
+ def sheet
+ @sheet ||= session.spreadsheet_by_key ENV["GOOGLE_LOG_SHEET_KEY"]
+ end
+
+ def session
+ @google_session ||= GoogleSpreadsheet.login_with_oauth access_token
+ end
+
+ def consumer
+ return @consumer if @consumer
+ key = ENV["GOOGLE_CONSUMER_KEY"]
+ secret = ENV["GOOGLE_CONSUMER_SECRET"]
+ @consumer = OAuth::Consumer.new key, secret, {
+ :signature_method => 'HMAC-SHA1',
+ :site => 'https://www.google.com',
+ :request_token_path => '/accounts/OAuthGetRequestToken',
+ :authorize_path => '/accounts/OAuthAuthorizeToken',
+ :access_token_path => '/accounts/OAuthGetAccessToken',
+ }
+ end
+
+ def access_token
+ return @access_token if @access_token
+ token = ENV["GOOGLE_ACCESS_TOKEN"]
+ secret = ENV["GOOGLE_ACCESS_SECRET"]
+ @access_token = OAuth::AccessToken.new(consumer, token, secret)
+ end
+end
View
9 lib/tasks/cron.rake
@@ -0,0 +1,9 @@
+require "lib/log_gss"
+
+desc "This task is called by the Heroku cron add-on"
+task :cron => :environment do
+ # log size of record for each model to Google SpreadSheet
+ opt = [User.count,
+ Manga.count]
+ LogGss.update(opt)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.