twat 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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem "twitter"
4
+ gem "oauth"
data/README ADDED
@@ -0,0 +1,16 @@
1
+ = Twatterator
2
+
3
+ this is the tweety thing I used for the Singularity Summit
4
+
5
+ I plan to extend it into (yet another) basic cli tweet app that supports
6
+ multiple accounts so that I can harass the world relentlessly (basically use a
7
+ twitter feed to replace my code/cheat/ files)
8
+
9
+ Also as an excuse to learn more ruby in my spare time
10
+
11
+ == Release status
12
+
13
+ This is massively pre-alpha. I plan to do my best to leave it in a
14
+ consistent-ish state so that I can use it for day to day use, but the config
15
+ format is liable to change at short notice. If things suddenly fail, that's
16
+ probably a good place to look.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'twat'
4
+
5
+ inst = Twat::Twat.new
6
+ inst.run
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("../", __FILE__)
4
+ require 'twitter'
5
+ require 'yaml'
6
+ require 'optparse'
7
+ require 'oauth'
8
+
9
+ %w[config exceptions argparse actions].each do |filename|
10
+ require "twat/#{filename}"
11
+ end
12
+
13
+ module Twat
14
+ VERSION_MAJOR = 0
15
+ VERSION_MINOR = 1
16
+ VERSION_PATCH = 0
17
+
18
+ VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
19
+ class Twat
20
+ def run
21
+ begin
22
+ action = Actions.new
23
+ opts = ArgParse.new
24
+ action.send(opts.options[:action], opts)
25
+ rescue Usage
26
+ opts.usage
27
+ rescue NoSuchAccount
28
+ puts "No such account"
29
+ opts.usage
30
+ rescue NoMethodError
31
+ puts "No such command"
32
+ opts.usage
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,50 @@
1
+ module Twat
2
+ OAUTH_TOKENS = [ :oauth_token, :oauth_token_secret ]
3
+ CONSUMER_TOKENS = [ :consumer_key, :consumer_secret ]
4
+ class Actions
5
+
6
+ def tweet(opts)
7
+ # This is all broken, we should know what options we have before this happend
8
+ conf = cf[opts[:account]]
9
+
10
+ Twitter.configure do |twit|
11
+ conf.each do |key, value|
12
+ twit.send("#{key}=", value)
13
+ end
14
+ Config.consumer_info.each do |key, value|
15
+ twit.send("#{key}=", value)
16
+ end
17
+ end
18
+
19
+ Twitter.update(opts.msg)
20
+ #puts opts.msg
21
+ end
22
+
23
+ def add(opts)
24
+ v = Config.consumer_info.map do |key, value|
25
+ value
26
+ end
27
+ # FIXME probably allow something other than
28
+ # twitter
29
+ oauth = OAuth::Consumer.new( v[0], v[1],
30
+ { site: "http://twitter.com" })
31
+ token_request = oauth.get_request_token()
32
+ puts "Please authenticate the application at #{token_request.authorize_url}, then enter pin"
33
+ pin = gets.chomp
34
+ access_token = token_request.get_access_token(oauth_verifier: pin)
35
+ cf[opts[:account]] = {
36
+ oauth_token: access_token.token,
37
+ oauth_token_secret: access_token.secret
38
+ }
39
+ cf.save!
40
+ end
41
+
42
+
43
+ private
44
+
45
+ def cf
46
+ @cf ||= Config.new
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,56 @@
1
+ module Twat
2
+ REQUIRED = [:account]
3
+ MSG_REQUIRED = [:tweet]
4
+
5
+ class ArgParse
6
+
7
+ def usage(additional=nil)
8
+ puts additional if additional
9
+ puts @optparser
10
+ exit
11
+ end
12
+
13
+ def getopts
14
+ options = Hash.new
15
+ @optparser = OptionParser.new do |opts|
16
+ options[:action] = :tweet
17
+ opts.banner = "Usage: #{$0} -a ACCOUNT <tweet>"
18
+ opts.on('-n', '--account ACCOUNT', 'Tweet from ACCOUNT') do |acct|
19
+ options[:account] = acct.to_sym
20
+ end
21
+ opts.on('-a', '--add ACCOUNT', 'Configure and authorise ACCOUNT') do |acct|
22
+ options[:account] = acct.to_sym
23
+ options[:action] = :add
24
+ end
25
+ #opts.on( '-a' '--add ACCOUNT' ) do |acct|
26
+ #end
27
+ opts.on('-h', '--help', 'Display this screen') do
28
+ puts opts
29
+ exit
30
+ end
31
+ end
32
+ @optparser.parse!
33
+ REQUIRED.each do |req|
34
+ usage unless options[req]
35
+ end
36
+ if MSG_REQUIRED.include?(options[:action])
37
+ options[:msg] = msg
38
+ end
39
+ options
40
+ end
41
+
42
+ def msg
43
+ usage unless ARGV.length > 0
44
+ ARGV.join(" ")
45
+ end
46
+
47
+ def [](key)
48
+ options[key]
49
+ end
50
+
51
+ def options
52
+ @configthingfucken ||= getopts
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ require 'ostruct'
2
+
3
+ module Twat
4
+ class Config #< OpenStruct
5
+
6
+ def config_path
7
+ @config_path ||= ENV['TWAT_CONFIG'] || "#{ENV['HOME']}/.twatrc"
8
+ end
9
+
10
+ def config
11
+ @config ||= YAML.load_file(config_path)
12
+ end
13
+
14
+ def save!
15
+ File.open(config_path, 'w') do |conf|
16
+ conf.puts(@config.to_yaml)
17
+ end
18
+ end
19
+
20
+ def [](key)
21
+ raise NoSuchAccount unless config.include?(key)
22
+ config[key]
23
+ end
24
+
25
+ def []=(key, value)
26
+ config[key] = value
27
+ end
28
+
29
+ def self.consumer_info
30
+ {
31
+ consumer_key: "jtI2q3Z4NIJAehBG4ntPIQ",
32
+ consumer_secret: "H6vQOGGn9qVJJa9lWyTd2s8ZZRXG4kh3SMfvZ2uxOXE"
33
+ }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module Twat
2
+ class NoSuchAccount < Exception; end
3
+ class Usage < Exception; end
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rich Healey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: twitter
16
+ requirement: &15376060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *15376060
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ requirement: &15373000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *15373000
36
+ description: Command line tool for tweeting and whatnot
37
+ email:
38
+ - richo@psych0tik.net
39
+ executables:
40
+ - twat
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .rvmrc
45
+ - Gemfile
46
+ - README
47
+ - bin/twat
48
+ - lib/twat.rb
49
+ - lib/twat/actions.rb
50
+ - lib/twat/argparse.rb
51
+ - lib/twat/config.rb
52
+ - lib/twat/exceptions.rb
53
+ homepage: http://github.com/richoH/twat
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Command line tool for tweeting and whatnot
77
+ test_files: []