twdo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 tily
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.md ADDED
@@ -0,0 +1,86 @@
1
+ Twitter のプロフィールでタスク管理する TwDo コマンド
2
+ ====================================================
3
+
4
+ <img src="http://gyazo.com/90e575edec44772e3f842807383a35e1.png" />
5
+
6
+ 使い方
7
+ ------
8
+
9
+ * 初期化する
10
+
11
+ $ twdo init 牛乳買う ビデオ返す 印鑑会社に持ってく
12
+ done.
13
+
14
+ * 一覧を見る
15
+
16
+ $ twdo list
17
+ (0) [ ] 牛乳買う
18
+ (1) [ ] ビデオ返す
19
+ (2) [ ] 印鑑会社に持ってく
20
+
21
+ * 追加する
22
+
23
+ $ twdo add 田中さんに本返す 傘持って帰る
24
+ done.
25
+ $ twdo list
26
+ (0) [ ] 牛乳買う
27
+ (1) [ ] ビデオ返す
28
+ (2) [ ] 印鑑会社に持ってく
29
+ (3) [ ] 田中さんに本返す
30
+ (4) [ ] 傘持って帰る
31
+
32
+ * 削除する
33
+
34
+ $ twdo del 0
35
+ done.
36
+ $ twdo del ビデオ返す
37
+ done.
38
+ $ twdo list
39
+ (0) [ ] 印鑑会社に持ってく
40
+ (1) [ ] 田中さんに本返す
41
+ (2) [ ] 傘持って帰る
42
+
43
+ * 完了にする
44
+
45
+ $ twdo done 0
46
+ done.
47
+ $ twdo done 傘持って帰る
48
+ done.
49
+ $ twdo list
50
+ (0) [*] 印鑑会社に持ってく
51
+ (1) [ ] 田中さんに本返す
52
+ (2) [*] 傘持って帰る
53
+
54
+ * 未完了にする
55
+
56
+ $ twdo undo 0
57
+ done.
58
+ $ twdo undo 傘持って帰る
59
+ done.
60
+ $ twdo list
61
+ (0) [ ] 印鑑会社に持ってく
62
+ (1) [ ] 田中さんに本返す
63
+ (2) [ ] 傘持って帰る
64
+
65
+ * ヘルプを見る
66
+
67
+ $ twdo help
68
+ Usage:
69
+ twdo command [task1, task2 ...]
70
+ Commands:
71
+ twdo init task1 task2 ... init with tasks.
72
+ twdo list list tasks.
73
+ twdo add task1 task2 ... add tasks.
74
+ twdo del task1 task2 ... del tasks.
75
+ twdo done task1 task2 ... mark task as done.
76
+ twdo undo task1 task2 ... mark task as not done.
77
+
78
+ インストール
79
+ -------------
80
+
81
+ rake install
82
+
83
+ Copyright
84
+ ---------
85
+
86
+ Copyright (c) 2010 tily. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "twdo"
8
+ gem.summary = %Q{task management in 119 chars of twitter profile}
9
+ gem.description = %Q{task management in 119 chars of twitter profile}
10
+ gem.email = "tily05@gmail.com"
11
+ gem.homepage = "http://github.com/tily/ruby-twdo"
12
+ gem.authors = ["tily"]
13
+ gem.add_dependency "oauth"
14
+ gem.add_dependency "twitter"
15
+ gem.add_dependency "oauth-cli-twitter"
16
+ gem.add_development_dependency "rspec", ">= 1.2.9"
17
+ gem.executables = ["twdo"]
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'spec/rake/spectask'
26
+ Spec::Rake::SpecTask.new(:spec) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
32
+ spec.libs << 'lib' << 'spec'
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "twdo #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/twdo ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+ require 'twdo'
5
+
6
+ @cmds = {}
7
+ def cmd name, &block
8
+ @cmds[name] = block
9
+ end
10
+
11
+ cmd :list do
12
+ @twd.list.each_with_index do |t, i|
13
+ prefix = t[1] == :done ? '[*]' : '[ ]'
14
+ puts "(#{i}) #{prefix} #{t[0]}"
15
+ end
16
+ end
17
+
18
+ cmd :init do |args|
19
+ @twd.init(args)
20
+ @twd.update!
21
+ puts 'done.'
22
+ end
23
+
24
+ cmd :add do |args|
25
+ args.each {|arg| @twd.add(arg) }
26
+ @twd.update!
27
+ puts 'done.'
28
+ end
29
+
30
+ [:del, :done, :undo].each do |c|
31
+ cmd c do |args|
32
+ args.each do |arg|
33
+ arg = arg =~ /^\d+$/ ? arg.to_i : arg
34
+ @twd.send(c, arg)
35
+ end
36
+ @twd.update!
37
+ puts 'done.'
38
+ end
39
+ end
40
+
41
+ cmd :help do
42
+ puts <<-EOS
43
+ Usage:
44
+ twdo command [task1, task2 ...]
45
+ Commands:
46
+ twdo init task1 task2 ... init with tasks.
47
+ twdo list task1 task2 ... list tasks.
48
+ twdo add task1 task2 ... add tasks.
49
+ twdo del task1 task2 ... del tasks.
50
+ twdo done task1 task2 ... mark task as done.
51
+ twdo undo task1 task2 ... mark task as not done.
52
+ twdo help show this help.
53
+ EOS
54
+ end
55
+
56
+ begin
57
+ @twd = TwDo.new
58
+ @twd.api = TwDo::API.new
59
+
60
+ c = ARGV.shift
61
+ if !c
62
+ @cmds[:help].call
63
+ exit 1
64
+ end
65
+
66
+ if @cmds[c.to_sym]
67
+ @cmds[c.to_sym].call(ARGV)
68
+ else
69
+ raise TwDo::Error, 'command not found.'
70
+ end
71
+ rescue TwDo::Error => e
72
+ puts "Error: #{e}"
73
+ end
data/lib/twdo/api.rb ADDED
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'twitter'
4
+ require 'oauth'
5
+ require 'oauth/cli/twitter'
6
+
7
+ class TwDo
8
+ class API
9
+ include OAuth::CLI::Twitter
10
+
11
+ CONF = ENV['HOME'] + '/.twdo'
12
+ CONSUMER_TOKEN = 'Tok5taGUA8x3VE60w79Q'
13
+ CONSUMER_SECRET = 'qf2UedjS1A9wEqMure0wrq03wWpl4qvAyiCp0dLMd8Q'
14
+
15
+ def initialize(*args)
16
+ @access_token = get_access_token(:file => CONF)
17
+ oauth = ::Twitter::OAuth.new(CONSUMER_TOKEN, CONSUMER_SECRET)
18
+ oauth.authorize_from_access(@access_token.token, @access_token.secret)
19
+ @twitter = ::Twitter::Base.new(oauth)
20
+ end
21
+
22
+ def get
23
+ @twitter.user(@access_token.params[:screen_name]).description
24
+ end
25
+
26
+ def set(val)
27
+ @twitter.update_profile(:description => val)
28
+ end
29
+ end
30
+ end
data/lib/twdo.rb ADDED
@@ -0,0 +1,69 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'twdo/api'
3
+
4
+ class TwDo
5
+ class Error < StandardError; end
6
+
7
+ MAX_CHAR = 119
8
+ MUST = '□'
9
+ DONE = '☑'
10
+ SEPARATOR = '/'
11
+
12
+ attr_accessor :api
13
+
14
+ def list
15
+ return @list if @list
16
+ lines = api.get.split(SEPARATOR)
17
+ @list = lines.map do |l|
18
+ if l =~ /^(#{MUST}|#{DONE})(.*)$/u
19
+ task = [$2]
20
+ task << :done if $1 == DONE
21
+ task
22
+ else
23
+ raise Error, 'invalid format. please init your TwDo list.'
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.operation(name, &block)
29
+ define_method name do |arg|
30
+ task = nil
31
+ if arg.is_a? String
32
+ if !list.assoc(arg)
33
+ raise Error, "task '#{arg}' does not exist."
34
+ end
35
+ task = list.assoc(arg)
36
+ elsif arg.is_a? Integer
37
+ if !list[arg]
38
+ raise Error, "task #{arg} does not exist."
39
+ end
40
+ task = list[arg]
41
+ end
42
+ block.call(task, list)
43
+ end
44
+ end
45
+
46
+ operation(:done) {|t, l| t[1] = :done }
47
+ operation(:undo) {|t, l| t[1] = nil }
48
+ operation(:del ) {|t, l| l.delete(t) }
49
+
50
+ def add(name)
51
+ if list.assoc(name)
52
+ raise Error, 'task already exists.'
53
+ end
54
+ list << [name]
55
+ end
56
+
57
+ def init(names)
58
+ @list = names.map {|n| [n] }
59
+ end
60
+
61
+ def update!
62
+ desc = list.map {|item|
63
+ prefix = item[1] == :done ? DONE : MUST
64
+ prefix + item[0]
65
+ }.join(SEPARATOR)
66
+ raise 'Over max chars.' if desc.split(//u).size > MAX_CHAR
67
+ api.set(desc)
68
+ end
69
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ -fs -color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'twdo'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
data/spec/twdo_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Twdo" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/twdo.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{twdo}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["tily"]
12
+ s.date = %q{2010-10-31}
13
+ s.default_executable = %q{twdo}
14
+ s.description = %q{task management in 119 chars of twitter profile}
15
+ s.email = %q{tily05@gmail.com}
16
+ s.executables = ["twdo"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/twdo",
29
+ "lib/twdo.rb",
30
+ "lib/twdo/api.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "spec/twdo_spec.rb",
34
+ "twdo.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/tily/ruby-twdo}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{task management in 119 chars of twitter profile}
41
+ s.test_files = [
42
+ "spec/twdo_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<oauth>, [">= 0"])
52
+ s.add_runtime_dependency(%q<twitter>, [">= 0"])
53
+ s.add_runtime_dependency(%q<oauth-cli-twitter>, [">= 0"])
54
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
+ else
56
+ s.add_dependency(%q<oauth>, [">= 0"])
57
+ s.add_dependency(%q<twitter>, [">= 0"])
58
+ s.add_dependency(%q<oauth-cli-twitter>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<oauth>, [">= 0"])
63
+ s.add_dependency(%q<twitter>, [">= 0"])
64
+ s.add_dependency(%q<oauth-cli-twitter>, [">= 0"])
65
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twdo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - tily
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-31 00:00:00 +09:00
19
+ default_executable: twdo
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: twitter
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: oauth-cli-twitter
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 13
72
+ segments:
73
+ - 1
74
+ - 2
75
+ - 9
76
+ version: 1.2.9
77
+ type: :development
78
+ version_requirements: *id004
79
+ description: task management in 119 chars of twitter profile
80
+ email: tily05@gmail.com
81
+ executables:
82
+ - twdo
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.md
88
+ files:
89
+ - .document
90
+ - .gitignore
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - VERSION
95
+ - bin/twdo
96
+ - lib/twdo.rb
97
+ - lib/twdo/api.rb
98
+ - spec/spec.opts
99
+ - spec/spec_helper.rb
100
+ - spec/twdo_spec.rb
101
+ - twdo.gemspec
102
+ has_rdoc: true
103
+ homepage: http://github.com/tily/ruby-twdo
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: task management in 119 chars of twitter profile
136
+ test_files:
137
+ - spec/twdo_spec.rb
138
+ - spec/spec_helper.rb