twitter_alert 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Hamill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = twitter_alert
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Ben Hamill. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "twitter_alert"
8
+ gem.summary = %Q{Send scheduled Direct Messages to all Twitter Followers.}
9
+ gem.description = %Q{Create messages, assign a time, then DM all Followers of a Twitter account with those messages as the assigned time.}
10
+ gem.email = "twitteralert@benhamill.com"
11
+ gem.homepage = "http://github.com/BenHamill/twitter_alert"
12
+ gem.authors = ["Ben Hamill"]
13
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
14
+ gem.add_dependency 'grackle', '>= 0.1.9'
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "twitter_alert #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ require 'grackle'
2
+
3
+ require 'twitter_alert/alert'
4
+ require 'twitter_alert/account'
@@ -0,0 +1,34 @@
1
+ module TwitterAlert
2
+ class Account
3
+ def initialize config
4
+ # Load hash from yaml file in default location?
5
+
6
+ @username = config[:user_name]
7
+ @password = config[:password]
8
+
9
+ @client = Grackle::Client.new(
10
+ :auth => {
11
+ :type => :basic,
12
+ :username => @username,
13
+ :password => @password
14
+ }
15
+ )
16
+ end
17
+
18
+ def announce message
19
+ followers.each do |follower|
20
+ begin
21
+ @client.direct_messages.new! :user_id => follower, :text => message.text
22
+ rescue Grackle::TwitterError => e
23
+ message.add_failed_announcement follower, e.message
24
+ end
25
+ end
26
+
27
+ message.mark_sent
28
+ end
29
+
30
+ def followers
31
+ @client.followers.ids?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module TwitterAlert
2
+ module Alert
3
+ attr_reader :text, :date, :failed_announcements
4
+
5
+ def initialize text, date
6
+ @text = text.to_s
7
+ @date = DateTime.parse(date.to_s)
8
+ @failed_announcements = []
9
+ end
10
+
11
+ def sent?
12
+ @sent
13
+ end
14
+
15
+ def mark_sent
16
+ @sent = @failed_announcements.empty?
17
+ end
18
+
19
+ def add_failed_announcement follower_id, error_text
20
+ @failed_announcements << { :follower_id => follower_id, :error_text => error_text }
21
+ end
22
+ end
23
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ require 'twitter_alert'
6
+
7
+ class Test::Unit::TestCase
8
+ end
9
+
10
+ class AlertTester
11
+ include TwitterAlert::Alert
12
+ end
@@ -0,0 +1,50 @@
1
+ require 'helper'
2
+ require 'fakeweb'
3
+
4
+ class TestAccount < Test::Unit::TestCase
5
+ def setup
6
+ @account = TwitterAlert::Account.new :user_name => 'test_user', :password => 'test_password'
7
+
8
+ FakeWeb.allow_net_connect = false
9
+ FakeWeb.clean_registry
10
+ end
11
+
12
+ def test_followers
13
+ FakeWeb.register_uri :get, 'http://test_user:test_password@twitter.com/followers/ids.json', :body => '[1, 2, 3]'
14
+
15
+ assert_equal([1, 2, 3], @account.followers)
16
+ end
17
+
18
+ def test_announce
19
+ FakeWeb.register_uri :get, 'http://test_user:test_password@twitter.com/followers/ids.json', :body => '[1, 2, 3]'
20
+ FakeWeb.register_uri :post, 'http://test_user:test_password@twitter.com/direct_messages/new.json',
21
+ :status => ['200', 'OK'],
22
+ :body => '{"sender_id":12345678,"recipient_id":87654321,"text":"Test message."}'
23
+
24
+ message = AlertTester.new 'Test message.', DateTime.now
25
+
26
+ assert(@account.announce(message), "Successful announcements should return true.")
27
+ assert(message.sent?, "Message from successful announcement should be marked sent.")
28
+ end
29
+
30
+ def test_announce_failure
31
+ FakeWeb.register_uri :get, 'http://test_user:test_password@twitter.com/followers/ids.json', :body => '[1, 2, 3]'
32
+ FakeWeb.register_uri :post, 'http://test_user:test_password@twitter.com/direct_messages/new.json',
33
+ [{
34
+ :body => '{"sender_id":12345678,"recipient_id":87654321,"text":"Test message."}',
35
+ :status => ['200', 'OK']
36
+ }, {
37
+ :body => '{"request":"/direct_messages/new.json","error":"Not found"}',
38
+ :status => ['404', 'Not found']
39
+ }, {
40
+ :body => '{"sender_id":12345678,"recipient_id":87654321,"text":"Test message."}',
41
+ :status => ['200', 'OK']
42
+ }]
43
+
44
+ message = AlertTester.new 'Test message.', DateTime.now
45
+
46
+ assert(!@account.announce(message), "Failed announcement should return false.")
47
+ assert_equal([{:follower_id => 2, :error_text => 'post http://twitter.com/direct_messages/new.json => 404: {"request":"/direct_messages/new.json","error":"Not found"}'}], message.failed_announcements)
48
+ assert(!message.sent?, "Message from failed announcement should not be marked sent.")
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ class TestAlert < Test::Unit::TestCase
4
+ def setup
5
+ @alert = AlertTester.new 'Test alert.', '01/02/2010'
6
+ end
7
+
8
+ def test_new
9
+ assert_equal('Test alert.', @alert.text)
10
+ assert_equal(DateTime.parse('01/02/2010'), @alert.date)
11
+ end
12
+
13
+ def test_new_alerts_are_marked_unsent
14
+ assert(!@alert.sent?, "New Alerts shouldn't be marked sent.")
15
+ end
16
+
17
+ def test_alerts_can_be_marked_sent
18
+ @alert.mark_sent
19
+ assert(@alert.sent?, "Alerts should be able to be marked sent.")
20
+ end
21
+
22
+ def test_failed_announcements
23
+ @alert.add_failed_announcement 2, 'post http://twitter.com/direct_messages/new.json => 404: {"request":"/direct_messages/new.json","error":"Not found"}'
24
+ assert_equal([{:follower_id => 2, :error_text => 'post http://twitter.com/direct_messages/new.json => 404: {"request":"/direct_messages/new.json","error":"Not found"}'}], @alert.failed_announcements)
25
+ end
26
+
27
+ def test_having_failed_announcements_blocks_being_marked_sent
28
+ @alert.add_failed_announcement 2, 'post http://twitter.com/direct_messages/new.json => 404: {"request":"/direct_messages/new.json","error":"Not found"}'
29
+
30
+ @alert.mark_sent
31
+ assert(!@alert.sent?, "Alerts with failed announcements should not be able to be marked sent.")
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_alert
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Ben Hamill
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-06 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: fakeweb
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 8
31
+ version: 1.2.8
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: grackle
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 1
44
+ - 9
45
+ version: 0.1.9
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Create messages, assign a time, then DM all Followers of a Twitter account with those messages as the assigned time.
49
+ email: twitteralert@benhamill.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/twitter_alert.rb
65
+ - lib/twitter_alert/account.rb
66
+ - lib/twitter_alert/alert.rb
67
+ - test/helper.rb
68
+ - test/test_account.rb
69
+ - test/test_alert.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/BenHamill/twitter_alert
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.6
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Send scheduled Direct Messages to all Twitter Followers.
100
+ test_files:
101
+ - test/helper.rb
102
+ - test/test_account.rb
103
+ - test/test_alert.rb