broadcast 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/.travis.yml +7 -0
- data/Gemfile +3 -1
- data/README.markdown +24 -4
- data/Rakefile +12 -3
- data/broadcast.gemspec +2 -1
- data/lib/broadcast/media/facebook.rb +25 -0
- data/lib/broadcast/version.rb +1 -1
- data/spec/lib/broadcast/media/facebook_spec.rb +66 -0
- data/spec/support/config.rb +5 -0
- data/spec/support/examples.rb +7 -0
- metadata +23 -4
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -3,14 +3,16 @@ source "http://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
+
gem 'rake', '0.8.7'
|
6
7
|
gem 'rspec'
|
7
|
-
gem 'rcov'
|
8
8
|
|
9
9
|
platforms :mri_18 do
|
10
|
+
gem 'rcov'
|
10
11
|
gem "ruby-debug"
|
11
12
|
end
|
12
13
|
|
13
14
|
platforms :mri_19 do
|
15
|
+
gem 'rcov'
|
14
16
|
gem "ruby-debug19"
|
15
17
|
end
|
16
18
|
end
|
data/README.markdown
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
Broadcast
|
1
|
+
Broadcast [](http://travis-ci.org/futuresimple/broadcast)
|
2
2
|
=========
|
3
3
|
|
4
4
|
A broadcasting microframework making publishing of messages to different services easy and DRY.
|
5
5
|
|
6
|
+
|
7
|
+
|
6
8
|
Use Cases
|
7
9
|
------------
|
8
10
|
|
@@ -17,11 +19,13 @@ Possible use cases include:
|
|
17
19
|
Installation
|
18
20
|
------------
|
19
21
|
|
20
|
-
|
22
|
+
You can install broadcast via Rubygems by typing:
|
21
23
|
|
22
|
-
|
24
|
+
gem install broadcast
|
23
25
|
|
24
|
-
|
26
|
+
It you use bundler, you can install it by adding the following line to your Gemfile:
|
27
|
+
|
28
|
+
gem 'broadcast'
|
25
29
|
|
26
30
|
and running
|
27
31
|
|
@@ -206,6 +210,22 @@ Broadcast::Medium::Irc employs the shout-bot gem.
|
|
206
210
|
end
|
207
211
|
```
|
208
212
|
|
213
|
+
### Facebook
|
214
|
+
|
215
|
+
Broadcast::Medium::Facebook uses the koala gem. It is designed to publish messages to Facebook pages.
|
216
|
+
It is based on the assumption that the user associated with the access token has publishing access to the page.
|
217
|
+
|
218
|
+
#### Example setup
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
Broadcast.setup do |config|
|
222
|
+
config.facebook { |facebook|
|
223
|
+
facebook.token = 'facebook_access_token',
|
224
|
+
facebook.page = 'Name of the page to publish to'
|
225
|
+
}
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
209
229
|
Copyright
|
210
230
|
---------
|
211
231
|
|
data/Rakefile
CHANGED
@@ -17,7 +17,16 @@ begin
|
|
17
17
|
t.verbose = false
|
18
18
|
end
|
19
19
|
|
20
|
+
task :default => [:spec]
|
21
|
+
|
22
|
+
rescue
|
23
|
+
puts 'Could not load Broadcast RSpec Rake tasks'
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
|
20
28
|
namespace :spec do
|
29
|
+
|
21
30
|
task :cleanup do
|
22
31
|
rm_rf 'coverage.data'
|
23
32
|
end
|
@@ -30,6 +39,6 @@ begin
|
|
30
39
|
|
31
40
|
end
|
32
41
|
|
33
|
-
rescue
|
34
|
-
puts 'Could not load Broadcast RSpec Rake tasks'
|
35
|
-
end
|
42
|
+
rescue
|
43
|
+
puts 'Could not load Broadcast RSpec Rcov Rake tasks'
|
44
|
+
end
|
data/broadcast.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "broadcast"
|
7
7
|
s.version = Broadcast::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Marcin Bunsch"]
|
9
|
+
s.authors = ["Marcin Bunsch", "Antek Piechnik"]
|
10
10
|
s.email = ["marcin@futuresimple.com"]
|
11
11
|
s.homepage = "http://github.com/futuresimple/broadcast"
|
12
12
|
s.summary = %q{A broadcasting microframework making publishing of messages to different services easy}
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'mail'
|
21
21
|
s.add_dependency 'broach'
|
22
22
|
s.add_dependency 'shout-bot'
|
23
|
+
s.add_dependency 'koala'
|
23
24
|
|
24
25
|
s.files = `git ls-files`.split("\n")
|
25
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'koala'
|
2
|
+
|
3
|
+
class Broadcast::Medium::Facebook < Broadcast::Medium::Oauth
|
4
|
+
|
5
|
+
def publish(message)
|
6
|
+
# We do not rescue any Koala exceptions to make them crash the sendout
|
7
|
+
# This should make debugging easier i.e. when fb has privilege issues
|
8
|
+
|
9
|
+
# Connect to facebook and get info about current user
|
10
|
+
graph = Koala::Facebook::GraphAPI.new(options.token)
|
11
|
+
me = graph.get_object('me')
|
12
|
+
# Get the connections to retrieve the appropriate page
|
13
|
+
connections = graph.get_connections(me['id'], 'accounts')
|
14
|
+
raise "No pages available" if connections.size == 0
|
15
|
+
|
16
|
+
# Find the page to post to
|
17
|
+
page = connections.find { |connection| connection['name'] == options.page }
|
18
|
+
raise 'Page not found' if !page
|
19
|
+
|
20
|
+
# Create a new graph so that the page posts to itself
|
21
|
+
page_graph = Koala::Facebook::GraphAPI.new(page['access_token'])
|
22
|
+
page_graph.put_wall_post(message.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/broadcast/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Broadcast::Medium::Facebook do
|
4
|
+
|
5
|
+
describe '.new' do
|
6
|
+
|
7
|
+
it "should create a new instance with options provided in config" do
|
8
|
+
medium = Broadcast::Medium::Facebook.new
|
9
|
+
medium.options.token.should == 'fb_token'
|
10
|
+
medium.options.page.should == 'My Page'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should prioritize options argument over options provided in config" do
|
14
|
+
medium = Broadcast::Medium::Facebook.new(:page => 'Different Page')
|
15
|
+
medium.options.token.should == 'fb_token'
|
16
|
+
medium.options.page.should == 'Different Page'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#publish' do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@medium = Broadcast::Medium::Facebook.new
|
25
|
+
@message = Broadcast::Message::SpecWithChagingContent.new
|
26
|
+
@me = {"name"=>"Your Name", "username"=>"yourname", "timezone"=>0, "gender"=>"male", "id"=>"1", "last_name"=>"Name", "updated_time"=>"2011-06-01T17:29:02+0000", "verified"=>true, "locale"=>"en_US", "hometown"=>{"name"=>"Palo Alto", "id"=>"1"}, "link"=>"http://www.facebook.com/yourname", "first_name"=>"Your"}
|
27
|
+
@connections = [{"name"=>"My Page", "category"=>"Software", "id"=>"123", "access_token"=>"page_access_token"}]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send the message to a Facebook page" do
|
31
|
+
mock_graph = mock
|
32
|
+
mock_page_graph = mock
|
33
|
+
Koala::Facebook::GraphAPI.should_receive(:new).with('fb_token').and_return(mock_graph)
|
34
|
+
Koala::Facebook::GraphAPI.should_receive(:new).with('page_access_token').and_return(mock_page_graph)
|
35
|
+
mock_graph.should_receive(:get_object).with('me').and_return(@me)
|
36
|
+
mock_graph.should_receive(:get_connections).with('1', 'accounts').and_return(@connections)
|
37
|
+
|
38
|
+
mock_page_graph.should_receive(:put_wall_post).with(@message.body)
|
39
|
+
@medium.publish(@message)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise an error when no pages are available" do
|
43
|
+
mock_graph = mock
|
44
|
+
mock_page_graph = mock
|
45
|
+
Koala::Facebook::GraphAPI.should_receive(:new).with('fb_token').and_return(mock_graph)
|
46
|
+
mock_graph.should_receive(:get_object).with('me').and_return(@me)
|
47
|
+
mock_graph.should_receive(:get_connections).with('1', 'accounts').and_return([])
|
48
|
+
|
49
|
+
lambda { @medium.publish(@message) }.should raise_error('No pages available')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should raise an error when no page was not found" do
|
53
|
+
mock_graph = mock
|
54
|
+
mock_page_graph = mock
|
55
|
+
Koala::Facebook::GraphAPI.should_receive(:new).with('fb_token').and_return(mock_graph)
|
56
|
+
mock_graph.should_receive(:get_object).with('me').and_return(@me)
|
57
|
+
|
58
|
+
@connections.first['name'] = 'Different name'
|
59
|
+
mock_graph.should_receive(:get_connections).with('1', 'accounts').and_return(@connections)
|
60
|
+
|
61
|
+
lambda { @medium.publish(@message) }.should raise_error('Page not found')
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/support/config.rb
CHANGED
data/spec/support/examples.rb
CHANGED
@@ -7,5 +7,12 @@ class Broadcast::Message::SpecWithContent < Broadcast::Message
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
class Broadcast::Message::SpecWithChagingContent < Broadcast::Message
|
11
|
+
def body
|
12
|
+
"message | " + Time.now.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
10
17
|
class Broadcast::Medium::Spec < Broadcast::Medium
|
11
18
|
end
|
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broadcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcin Bunsch
|
14
|
+
- Antek Piechnik
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-
|
19
|
+
date: 2011-06-01 00:00:00 Z
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: hashie
|
@@ -101,6 +102,20 @@ dependencies:
|
|
101
102
|
version: "0"
|
102
103
|
prerelease: false
|
103
104
|
requirement: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: koala
|
107
|
+
type: :runtime
|
108
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
prerelease: false
|
118
|
+
requirement: *id007
|
104
119
|
description: A broadcasting microframework making publishing of messages to different services easy
|
105
120
|
email:
|
106
121
|
- marcin@futuresimple.com
|
@@ -112,6 +127,7 @@ extra_rdoc_files: []
|
|
112
127
|
|
113
128
|
files:
|
114
129
|
- .gitignore
|
130
|
+
- .travis.yml
|
115
131
|
- Gemfile
|
116
132
|
- LICENSE
|
117
133
|
- README.markdown
|
@@ -121,6 +137,7 @@ files:
|
|
121
137
|
- lib/broadcast/config.rb
|
122
138
|
- lib/broadcast/media/campfire.rb
|
123
139
|
- lib/broadcast/media/email.rb
|
140
|
+
- lib/broadcast/media/facebook.rb
|
124
141
|
- lib/broadcast/media/irc.rb
|
125
142
|
- lib/broadcast/media/jabber.rb
|
126
143
|
- lib/broadcast/media/log.rb
|
@@ -134,6 +151,7 @@ files:
|
|
134
151
|
- lib/broadcast/version.rb
|
135
152
|
- spec/lib/broadcast/media/campfire_spec.rb
|
136
153
|
- spec/lib/broadcast/media/email_spec.rb
|
154
|
+
- spec/lib/broadcast/media/facebook_spec.rb
|
137
155
|
- spec/lib/broadcast/media/irc_spec.rb
|
138
156
|
- spec/lib/broadcast/media/jabber_spec.rb
|
139
157
|
- spec/lib/broadcast/media/log_spec.rb
|
@@ -182,6 +200,7 @@ summary: A broadcasting microframework making publishing of messages to differen
|
|
182
200
|
test_files:
|
183
201
|
- spec/lib/broadcast/media/campfire_spec.rb
|
184
202
|
- spec/lib/broadcast/media/email_spec.rb
|
203
|
+
- spec/lib/broadcast/media/facebook_spec.rb
|
185
204
|
- spec/lib/broadcast/media/irc_spec.rb
|
186
205
|
- spec/lib/broadcast/media/jabber_spec.rb
|
187
206
|
- spec/lib/broadcast/media/log_spec.rb
|