Browse files

Added Tumblr medium, based on hmaddocks idea

  • Loading branch information...
1 parent 07c6382 commit 0958118774e236d77a8d5896841643543855bab7 Marcin Bunsch committed Oct 22, 2011
View
2 Rakefile
@@ -5,6 +5,8 @@ require 'bundler'
Bundler::GemHelper.install_tasks
+import "lib/broadcast/tasks/broadcast.rake"
+
begin
require 'rspec'
View
22 lib/broadcast/media/tumblr.rb
@@ -0,0 +1,22 @@
+# This integration was originally prepared by https://github.com/hmaddocks
+require 'net/http'
+
+class Broadcast::Medium::Tumblr < Broadcast::Medium::Oauth
+
+ self.site = "http://www.tumblr.com"
+
+ def publish(message)
+ @consumer = OAuth::Consumer.new(options.consumer_key,
+ options.consumer_secret,
+ :site => "http://api.tumblr.com")
+
+ params = {
+ "state" => "published",
+ "title" => message.subject,
+ "body" => message.body,
+ }
+
+ token.post "/v2/blog/#{options.hostname}/post", params
+ end
+
+end
View
14 lib/broadcast/tasks/broadcast.rake
@@ -1,7 +1,7 @@
namespace "broadcast" do
-
+
namespace "authorize" do
-
+
desc "Authorize Broadcast with Yammer and get access token information"
task "yammer" do
require 'broadcast'
@@ -13,7 +13,13 @@ namespace "broadcast" do
require 'broadcast'
Broadcast::Medium::Twitter.new.authorize
end
-
+
+ desc "Authorize Broadcast with Tumblr and get access token information"
+ task "tumblr" do
+ require 'broadcast'
+ Broadcast::Medium::Tumblr.new.authorize
+ end
+
end
-
+
end
View
31 spec/lib/broadcast/media/tumblr_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe Broadcast::Medium::Tumblr do
+
+ describe '.site' do
+
+ it "should be set to Tumblr OAuth endpoint" do
+ Broadcast::Medium::Tumblr.site.should == "http://www.tumblr.com"
+ end
+
+ end
+
+ describe '#publish' do
+
+ it "should send a post to twitter with the message body" do
+ message = Broadcast::Message::SpecWithContentAndSubject.new
+ medium = Broadcast::Medium::Tumblr.new
+ token = mock
+ params = {
+ "state" => "published",
+ "title" => "title",
+ "body" => "message",
+ }
+ token.should_receive(:post).with("/v2/blog/spec.tumblr.com/post", params)
+ medium.should_receive(:token).and_return(token)
+ medium.publish(message)
+ end
+
+ end
+
+end
View
10 spec/support/config.rb
@@ -53,4 +53,14 @@
sms.to = '22222222222'
}
+ config.tumblr { |tumblr|
+
+ tumblr.hostname = 'spec.tumblr.com'
+ tumblr.consumer_key = 'consumerkey'
+ tumblr.consumer_secret = 'consumersecret'
+ tumblr.access_token = 'accesstoken'
+ tumblr.access_secret = 'accesssecret'
+
+ }
+
}
View
9 spec/support/examples.rb
@@ -7,6 +7,15 @@ def body
end
end
+class Broadcast::Message::SpecWithContentAndSubject < Broadcast::Message
+ def subject
+ "title"
+ end
+ def body
+ "message"
+ end
+end
+
class Broadcast::Message::SpecWithChagingContent < Broadcast::Message
def body
"message | " + Time.now.to_s

0 comments on commit 0958118

Please sign in to comment.