Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
GH#2 setup for tweeting after successful show load
Browse files Browse the repository at this point in the history
  • Loading branch information
tardate committed Jan 2, 2012
1 parent e6c29cf commit 08142fb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -20,6 +20,8 @@ gem 'meta_search'
gem 'compass' gem 'compass'
# browser detection # browser detection
gem 'browser' gem 'browser'
# twitter api
gem 'grackle'


group :test, :development do group :test, :development do
# rspec for all testing # rspec for all testing
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -47,6 +47,10 @@ GEM
factory_girl (~> 2.1.0) factory_girl (~> 2.1.0)
railties (>= 3.0.0) railties (>= 3.0.0)
fssm (0.2.7) fssm (0.2.7)
grackle (0.1.10)
json
mime-types
oauth
haml (3.1.3) haml (3.1.3)
has_scope (0.5.1) has_scope (0.5.1)
i18n (0.5.0) i18n (0.5.0)
Expand All @@ -66,6 +70,7 @@ GEM
arel (~> 2.0.2) arel (~> 2.0.2)
mime-types (1.16) mime-types (1.16)
nokogiri (1.5.0) nokogiri (1.5.0)
oauth (0.4.5)
pg (0.11.0) pg (0.11.0)
polyglot (0.3.2) polyglot (0.3.2)
rack (1.2.4) rack (1.2.4)
Expand Down Expand Up @@ -122,6 +127,7 @@ DEPENDENCIES
browser browser
compass compass
factory_girl_rails factory_girl_rails
grackle
haml haml
inherited_resources inherited_resources
meta_search meta_search
Expand Down
9 changes: 9 additions & 0 deletions README.rdoc
Expand Up @@ -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, 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. 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 == Contributing


Yes please! If you have any ideas, or can help with design, development or translation, you are most welcome. Yes please! If you have any ideas, or can help with design, development or translation, you are most welcome.
Expand Down
4 changes: 4 additions & 0 deletions app/models/show.rb
Expand Up @@ -58,4 +58,8 @@ def meme_stat
self.class.meme_stats(self.id) self.class.meme_stats(self.id)
end 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 end
28 changes: 28 additions & 0 deletions lib/navd/scraper/control.rb
Expand Up @@ -46,6 +46,7 @@ def load_show(number,reload=false)
:description => show_note[:description] :description => show_note[:description]
) )
end end
notify_new_show(show)
return true return true
else else
log "#{number}: show already published - cannot reload" log "#{number}: show already published - cannot reload"
Expand All @@ -57,5 +58,32 @@ def load_show(number,reload=false)
end end
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
end end
1 change: 1 addition & 0 deletions spec/lib/scraper/control_spec.rb
Expand Up @@ -6,6 +6,7 @@
let(:scraper_control) { Navd::Scraper::Control.new } let(:scraper_control) { Navd::Scraper::Control.new }
before { before {
scraper_control.stub(:log) # silence the logging messages when testing 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 context "init" do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/show/show_spec.rb
Expand Up @@ -86,6 +86,12 @@
end end
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 describe "#destroy" do
let!(:meme) { Factory(:meme) } let!(:meme) { Factory(:meme) }
let!(:show) { Factory(:show) } let!(:show) { Factory(:show) }
Expand Down

0 comments on commit 08142fb

Please sign in to comment.