blindgaenger-glitter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 blindgaenger
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,45 @@
1
+ = glitter
2
+
3
+ The idea is to think about {Twitter}[http://www.twitter.com/] as a
4
+ {Git}[http://git-scm.com/] repository. So you can commit your status and view
5
+ your friends commits in the log. Just for fun to see how far this can go!
6
+
7
+ For more information you should have a look at the
8
+ {glitter project page}[http://blindgaenger.github.com/glitter].
9
+
10
+ == Usage
11
+
12
+ But basically you use it just like Git … but for Twitter :)
13
+
14
+ $ glitter init
15
+ (Instructions to register glitter with your twitter account)
16
+
17
+
18
+ $ glitter log -n 3
19
+ commit 2799873378
20
+ Author: codinghorror <Jeff Atwood>
21
+ Date: Thu Jul 23 15:29:12 +0000 2009
22
+
23
+ reminder: anyone who would like to beta test http://superuser.com , password
24
+ is here http://is.gd/1J0yR
25
+
26
+ commit 2799553049
27
+ Author: TechCrunch <Michael Arrington>
28
+ Date: Thu Jul 23 15:09:52 +0000 2009
29
+
30
+ The Song of the PowerSquid: The Inside Story of the Life of an Invention
31
+ http://tcrn.ch/NuB by Guest Author
32
+
33
+ commit 2799436673
34
+ Author: olabini <Ola Bini>
35
+ Date: Thu Jul 23 15:02:53 +0000 2009
36
+
37
+ SUCCESS. Switching from Jacc to Jay removed another bottleneck. Yecht is now
38
+ about 5% faster than Syck and JvYAMLb.
39
+
40
+ $ glitter commit -m "command line fun with #glitter on #twitter"
41
+ Created commit 2799823473: command line fun with #glitter on #twitter
42
+ 1 files changed, 1 insertions(+), 0 deletions(-)
43
+
44
+ Have fun!
45
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ # see http://www.rubygems.org/read/chapter/20
8
+ gem.name = "glitter"
9
+ gem.summary = %Q{TODO}
10
+ gem.email = "blindgaenger@gmail.com"
11
+ gem.homepage = "http://github.com/blindgaenger/glitter"
12
+ gem.authors = ["blindgaenger"]
13
+ gem.summary = %q{Git-Like Interface for Twitter}
14
+ gem.bindir = "bin"
15
+ gem.executables = ["glitter"]
16
+ gem.extra_rdoc_files << 'glitter.rdoc'
17
+ gem.add_dependency('gli', '>= 0.2.3')
18
+ gem.add_dependency('twitter', '>= 0.6.13')
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION.yml')
49
+ config = YAML.load(File.read('VERSION.yml'))
50
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "glitter #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ rdoc.rdoc_files.include('bin/**/*')
60
+ end
61
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/glitter ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby
2
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'ostruct'
6
+ require 'yaml'
7
+ require 'highline/import'
8
+ require 'ftools'
9
+ require 'gli'
10
+ require 'twitter'
11
+ require 'twitter_app'
12
+
13
+ include GLI
14
+
15
+ CONFIG_FILE = "~/.twitter/glitter.yml"
16
+
17
+ Dir['lib/commands/*.rb'].each {|file| load file}
18
+
19
+ pre do |global_options,command,options,args|
20
+ @config = TwitterConfig.new(CONFIG_FILE)
21
+
22
+ if command.nil?
23
+ commands[:help].execute(global_options,options,args)
24
+ false
25
+ elsif command && command.name == :help
26
+ true # always help
27
+ elsif @config.atoken.nil?
28
+ if command && command.name == :init
29
+ true
30
+ else
31
+ puts "Sorry, but you need to initialize first. Try this:"
32
+ puts "\n"
33
+ puts " $ glitter init"
34
+ puts "\n"
35
+ false
36
+ end
37
+ else
38
+ @twitter = TwitterApp.new(@config)
39
+ true # already init
40
+ end
41
+ end
42
+
43
+ post do |global_options,command,options,args|
44
+ end
45
+
46
+ on_error do |ex|
47
+ warn ex.message
48
+ warn ex.backtrace
49
+ true
50
+ end
51
+
52
+ GLI.run(ARGV)
53
+
data/default.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ :csite: http://twitter.com
3
+ :ctoken: adD9oUTtOKaFynQoUhHZg
4
+ :csecret: o6HE0KUm5ASoFIVeuKvFys1CoUFJHaGXs1cRORs
5
+
6
+
data/glitter.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{glitter}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["blindgaenger"]
9
+ s.date = %q{2009-07-27}
10
+ s.default_executable = %q{glitter}
11
+ s.email = %q{blindgaenger@gmail.com}
12
+ s.executables = ["glitter"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc",
16
+ "glitter.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "bin/glitter",
24
+ "default.yml",
25
+ "glitter.gemspec",
26
+ "glitter.rdoc",
27
+ "lib/commands/commit.rb",
28
+ "lib/commands/init.rb",
29
+ "lib/commands/log.rb",
30
+ "lib/glitter.rb",
31
+ "lib/twitter_app.rb",
32
+ "test/glitter_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.has_rdoc = true
36
+ s.homepage = %q{http://github.com/blindgaenger/glitter}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.1}
40
+ s.summary = %q{Git-Like Interface for Twitter}
41
+ s.test_files = [
42
+ "test/test_helper.rb",
43
+ "test/glitter_test.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 2
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<gli>, [">= 0.2.3"])
52
+ s.add_runtime_dependency(%q<twitter>, [">= 0.6.13"])
53
+ else
54
+ s.add_dependency(%q<gli>, [">= 0.2.3"])
55
+ s.add_dependency(%q<twitter>, [">= 0.6.13"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<gli>, [">= 0.2.3"])
59
+ s.add_dependency(%q<twitter>, [">= 0.6.13"])
60
+ end
61
+ end
data/glitter.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = glitter
2
+
3
+ Generate this with
4
+ glitter rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,15 @@
1
+ desc "Commit your current status"
2
+ command :commit do |c|
3
+
4
+ c.desc "The text of your status update. Statuses over 140 characters will be forceably truncated."
5
+ c.flag :message, :m
6
+
7
+ c.action do |global, options, args|
8
+ unless options.message
9
+ say "Aborting commit due to empty commit message."
10
+ else
11
+ @twitter.update(options.message)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,36 @@
1
+ desc "Registers glitter with your twitter account"
2
+ command [:init] do |c|
3
+
4
+ c.action do |global, options, args|
5
+ #TODO: check for global --force option, not a git parameter but useful
6
+ if @config.atoken
7
+ puts "You already initialized glitter. Find out what else you can do:"
8
+ puts "\n"
9
+ puts " $ glitter help"
10
+ puts "\n"
11
+ else
12
+ authorized = TwitterApp.authorize(@config) {|url, counter|
13
+ if counter == 0
14
+ say "Open this URL in your browser and allow glitter access:"
15
+ say "\n"
16
+ say " #{url}"
17
+ say "\n"
18
+ else
19
+ say "Nope, can't access twitter. Please try the same URL again!"
20
+ end
21
+
22
+ ask "And now enter the PIN twitter gave to you:" do |q|
23
+ # need to use readline, otherwise "The input stream is exhausted."
24
+ q.readline = true
25
+ end
26
+ }
27
+
28
+ if authorized
29
+ say "Great, you can start tweeting!"
30
+ else
31
+ say "Hm, without authorization this tool is useless."
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,35 @@
1
+ desc "Lists the most recent statuses posted of you and your friends."
2
+ command :log do |c|
3
+
4
+ c.desc "Specifies the number of statuses to retrieve. May not be greater than 200."
5
+ c.default_value 20
6
+ c.flag :n, :'max-count'
7
+
8
+ c.action do |globals, options, args|
9
+ def bold(text)
10
+ "<%= color('#{text}', BOLD) %>"
11
+ end
12
+
13
+ def color(text, color)
14
+ "<%= color('#{text}', :#{color.to_s}) %>"
15
+ end
16
+
17
+ def indent(text, length=4)
18
+ ' '*length + wrap(text, length, 80)
19
+ end
20
+
21
+ statuses = @twitter.friends_timeline({:count => options['max-count']})
22
+ statuses.each {|status|
23
+ say <<-EOL
24
+ #{color "commit #{status.id}", :yellow}
25
+ Author: #{status.user.screen_name} <#{status.user.name}>
26
+ Date: #{status.created_at}
27
+
28
+ #{indent(status.text)}
29
+
30
+ EOL
31
+ }
32
+
33
+ end
34
+ end
35
+
data/lib/glitter.rb ADDED
File without changes
@@ -0,0 +1,62 @@
1
+ class TwitterConfig < OpenStruct
2
+ def initialize(config_file)
3
+ @config_file = File.expand_path(config_file)
4
+ filename = File.exist?(@config_file) ? @config_file : 'default.yml'
5
+ super(YAML.load(File.read(filename)))
6
+ end
7
+
8
+ def store
9
+ unless File.exist? @config_file
10
+ File.makedirs File.dirname(@config_file)
11
+ end
12
+ File.open(@config_file, 'w') do |file|
13
+ file.puts YAML.dump(marshal_dump)
14
+ end
15
+ end
16
+ end
17
+
18
+ class TwitterApp < Twitter::Base
19
+
20
+ def self.authorize(config, &block)
21
+ consumer = OAuth::Consumer.new(config.ctoken, config.csecret, { :site=>config.csite })
22
+ request_token = consumer.get_request_token
23
+
24
+ counter = 0
25
+ loop do
26
+ # ask the user to open the url in its browser and allow access
27
+ begin
28
+ oauth_verifier = yield request_token.authorize_url, counter
29
+ rescue Exception => ex
30
+ return false # something went wrong or the callback wants to exit
31
+ end
32
+ counter += 1
33
+
34
+ # now that the request_token is authorized we can get an access token
35
+ begin
36
+ access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
37
+ config.atoken = access_token.token
38
+ config.asecret = access_token.secret
39
+ config.store
40
+ return true # user authorized and it works
41
+ rescue OAuth::Unauthorized => ex
42
+ # ignore and try again
43
+ end
44
+ end
45
+ end
46
+
47
+ def initialize(config)
48
+ oauth = Twitter::OAuth.new(config.ctoken, config.csecret)
49
+ oauth.authorize_from_access(config.atoken, config.asecret)
50
+ super(oauth)
51
+ end
52
+
53
+ def last_status(user_id)
54
+ statuses = self.user_timeline({:id => user_id, :count => 1})
55
+ statuses.first
56
+ end
57
+
58
+ def reply(status, message)
59
+ self.update("@#{status.user.screen_name} #{message}", {:in_reply_to_status_id => status.id})
60
+ end
61
+ end
62
+
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ class GlitterTest < Test::Unit::TestCase
4
+ should "test cases should work" do
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'glitter'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blindgaenger-glitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - blindgaenger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-27 00:00:00 -07:00
13
+ default_executable: glitter
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gli
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: twitter
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.13
34
+ version:
35
+ description:
36
+ email: blindgaenger@gmail.com
37
+ executables:
38
+ - glitter
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ - glitter.rdoc
45
+ files:
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/glitter
51
+ - default.yml
52
+ - glitter.gemspec
53
+ - glitter.rdoc
54
+ - lib/commands/commit.rb
55
+ - lib/commands/init.rb
56
+ - lib/commands/log.rb
57
+ - lib/glitter.rb
58
+ - lib/twitter_app.rb
59
+ - test/glitter_test.rb
60
+ - test/test_helper.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/blindgaenger/glitter
63
+ licenses:
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Git-Like Interface for Twitter
88
+ test_files:
89
+ - test/test_helper.rb
90
+ - test/glitter_test.rb