tommi-cmd_tweet 0.1.4

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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2009-08-30
2
+
3
+ * Support for posting new statuses
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/cmd_tweet
7
+ lib/cmd_tweet.rb
8
+ test/test_cmd_tweet.rb
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = cmd_tweet
2
+
3
+ http://tommi.asiala.info/blog/cmd_tweet
4
+
5
+ == DESCRIPTION:
6
+
7
+ Unix style Twitter tool.
8
+
9
+ == FEATURES:
10
+
11
+ * Post status
12
+
13
+ == SYNOPSIS:
14
+
15
+ === Posting new status
16
+
17
+ cmd_tweet "Your new status"
18
+
19
+ echo "Your new status" | cmd_tweet
20
+
21
+ cmd_tweet [enter]
22
+ your new status [enter]
23
+
24
+ == REQUIREMENTS:
25
+
26
+ * Ruby 1.8 or greater
27
+
28
+ == INSTALL:
29
+
30
+ sudo gem install cmd_tweet
31
+
32
+ Create a configuration file to your home directory called .cmd_tweet.cfg with
33
+ configuration values:
34
+ username = your-twitter-username
35
+ password = your-twitter-password
36
+
37
+ Don't forget to execute "chmod go-rwx .cmd_tweet.cfg" disable access from
38
+ everybody else to your configuration file.
39
+
40
+
41
+ == LICENSE:
42
+
43
+ The MIT License
44
+
45
+ Copyright (c) 2009 Tommi Asiala
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/cmd_tweet ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib cmd_tweet]))
5
+
6
+ CmdTweet.new
7
+
data/lib/cmd_tweet.rb ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby
2
+ require 'etc'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ class CmdTweet
7
+ def initialize
8
+ configure
9
+ post(read_status)
10
+ end
11
+
12
+ def configure
13
+ begin
14
+ config = Configuration.new(Etc.getpwuid.dir + File::SEPARATOR + ".cmdTweet.cfg" )
15
+ @username = config.get_mandatory("username")
16
+ @password = config.get_mandatory("password")
17
+ rescue RuntimeError => config_error
18
+ error(config_error)
19
+ end
20
+ end
21
+
22
+ def read_status
23
+ status = ARGV[0]
24
+ if status != nil
25
+ return status
26
+ end
27
+ status = ARGF.gets
28
+ if status != nil
29
+ return status
30
+ end
31
+ error("status not set.")
32
+ end
33
+
34
+ def post(status)
35
+ response = Net::HTTP.post_form(URI.parse("http://#{@username}:#{@password}@twitter.com/statuses/update.json"), {'status'=> status })
36
+ if response.code != "200"
37
+ error("Something wrong with posting. Received HTTP Error code #{response.code}.")
38
+ end
39
+ end
40
+
41
+ def error(text)
42
+ puts "Error: " + text
43
+ Process.exit(-1)
44
+ end
45
+
46
+ end
47
+
48
+ class Configuration
49
+ def initialize(config_file)
50
+ file = nil
51
+ begin
52
+ file = File.open(config_file, "r")
53
+ rescue
54
+ raise "#{config_file} does not exist."
55
+ end
56
+ @config = {}
57
+ file.each_line do |line|
58
+ if (line.lstrip).index('#') == 0
59
+ next
60
+ end
61
+
62
+ if line.include?("=")
63
+ key, value = line.split("=")
64
+ @config = @config.merge({"#{key.lstrip.rstrip}" =>
65
+ "#{value.lstrip.rstrip}"})
66
+ end
67
+ end
68
+ file.close
69
+ end
70
+
71
+ def get_mandatory(key)
72
+ value = @config[key]
73
+ if value == nil
74
+ raise "'#{key}' key not in configuration."
75
+ end
76
+ return value
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,27 @@
1
+ require "test/unit"
2
+ require "cmd_tweet"
3
+
4
+ class TestCmdTweet < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @test_file = 'test_cmd_tweet.cfg'
8
+ File.open(@test_file, 'w') { |f|
9
+ f.write("username = user\n")
10
+ f.write("foo = bar\n")
11
+ f.write("password = pass\n")
12
+ }
13
+ end
14
+
15
+ def test_configuration
16
+ config = Configuration.new(@test_file)
17
+ assert('user', config.get_mandatory("username"))
18
+ assert('pass', config.get_mandatory("password"))
19
+ assert_raise RuntimeError do config.get_mandatory("doesnotexist")
20
+ end
21
+ end
22
+
23
+ def teardown
24
+ File.delete(@test_file)
25
+ end
26
+ end
27
+
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tommi-cmd_tweet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Tommi Asiala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: UNIX style twitter tool
17
+ email: tommi@asiala.info
18
+ executables:
19
+ - cmd_tweet
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - lib/cmd_tweet.rb
26
+ - History.txt
27
+ - Manifest.txt
28
+ - README.rdoc
29
+ has_rdoc: true
30
+ homepage: http://tommi.asiala.info/blog/cmd_tweet
31
+ licenses:
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: UNIX style twitter tool
56
+ test_files:
57
+ - test/test_cmd_tweet.rb