Permalink
Browse files

GH#2 setup for tweeting after successful show load

  • Loading branch information...
1 parent e6c29cf commit 08142fb6099400ed3ce108308ec75a86ba3ad909 @tardate committed Jan 2, 2012
Showing with 56 additions and 0 deletions.
  1. +2 −0 Gemfile
  2. +6 −0 Gemfile.lock
  3. +9 −0 README.rdoc
  4. +4 −0 app/models/show.rb
  5. +28 −0 lib/navd/scraper/control.rb
  6. +1 −0 spec/lib/scraper/control_spec.rb
  7. +6 −0 spec/models/show/show_spec.rb
View
@@ -20,6 +20,8 @@ gem 'meta_search'
gem 'compass'
# browser detection
gem 'browser'
+# twitter api
+gem 'grackle'
group :test, :development do
# rspec for all testing
View
@@ -47,6 +47,10 @@ GEM
factory_girl (~> 2.1.0)
railties (>= 3.0.0)
fssm (0.2.7)
+ grackle (0.1.10)
+ json
+ mime-types
+ oauth
haml (3.1.3)
has_scope (0.5.1)
i18n (0.5.0)
@@ -66,6 +70,7 @@ GEM
arel (~> 2.0.2)
mime-types (1.16)
nokogiri (1.5.0)
+ oauth (0.4.5)
pg (0.11.0)
polyglot (0.3.2)
rack (1.2.4)
@@ -122,6 +127,7 @@ DEPENDENCIES
browser
compass
factory_girl_rails
+ grackle
haml
inherited_resources
meta_search
View
@@ -31,6 +31,15 @@ link:noagenda_dashboard/blob/master/config/locales/en.yml
To provide a tranlsation for a given language, just grab a copy of this file, rename is <language-code>.yml,
translate all the definitions and send it/push it back. Please keep it in UTF-8 character set though.
+== Enabling Twitter Notifications
+
+The site will tweet when new shows are loaded. It requires twitter oauth settings to be set
+with these environment variables:
+* navd_consumer_key
+* consumer_secret
+* navd_token
+* navd_token_secret
+
== Contributing
Yes please! If you have any ideas, or can help with design, development or translation, you are most welcome.
View
@@ -58,4 +58,8 @@ def meme_stat
self.class.meme_stats(self.id)
end
+ # Returns an announcement message formated for posting to twitter
+ def twitter_publish_message
+ "#NoAgenda show ##{number} attack vectors now at http://noagendadashboard.com"
+ end
end
@@ -46,6 +46,7 @@ def load_show(number,reload=false)
:description => show_note[:description]
)
end
+ notify_new_show(show)
return true
else
log "#{number}: show already published - cannot reload"
@@ -57,5 +58,32 @@ def load_show(number,reload=false)
end
end
+ protected
+
+ # Post notification of new show.
+ # Currently posts to twitter.
+ def notify_new_show(show)
+ if config = twitter_oauth_config
+ client = Grackle::Client.new(config)
+ client.statuses.update! :status=>show.twitter_publish_message
+ else
+ log "#{show.try(:number)}: cannot post to twitter - missing config"
+ end
+ rescue => e
+ log "#{show.try(:number)}: failed to post to twitter #{e}"
+ end
+
+ # Returns twitter oauth config. Gets settings from ENV vars.
+ # Returns nil if no config available.
+ def twitter_oauth_config
+ if (consumer_key = ENV['navd_consumer_key']) && (consumer_secret = ENV['navd_consumer_secret']) &&
+ (token = ENV['navd_token']) && (token_secret = ENV['navd_token_secret'])
+ {:auth=>{
+ :type=>:oauth,
+ :consumer_key=>consumer_key, :consumer_secret=>consumer_secret,
+ :token=>token, :token_secret=>token_secret}
+ }
+ end
+ end
end
end
@@ -6,6 +6,7 @@
let(:scraper_control) { Navd::Scraper::Control.new }
before {
scraper_control.stub(:log) # silence the logging messages when testing
+ scraper_control.stub(:notify_new_show) # silence the tweeting of show posts when testing
}
context "init" do
@@ -86,6 +86,12 @@
end
end
+ describe "#twitter_publish_message" do
+ let(:expected) { "#NoAgenda show ##{resource.number} attack vectors now at http://noagendadashboard.com" }
+ subject { resource.twitter_publish_message }
+ it { should eql(expected) }
+ end
+
describe "#destroy" do
let!(:meme) { Factory(:meme) }
let!(:show) { Factory(:show) }

0 comments on commit 08142fb

Please sign in to comment.