atm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in atm.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jack Murray
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ATM
2
+
3
+ A console for Remember the Milk.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'atm'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install atm
18
+
19
+ ## Usage
20
+
21
+ To list today's tasks, simply type `atm` on the command line:
22
+
23
+ $ atm
24
+ 15:40 Buy milk
25
+ today John's birthday
26
+ This task doesn't have a due date
27
+
28
+ To use the console, `atm c` or `atm console`:
29
+
30
+ $ atm c
31
+ 1.9.3-p194 :001 > Task.all.map { |task| task.name }
32
+ => ["Buy milk", "John's birthday", "This task doesn't have a name"]
33
+ 1.9.3-p194 :002 >
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/atm.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/atm/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jack Murray"]
6
+ gem.email = ["jack@murray.cx"]
7
+ gem.description = %q{Console interface to Remember The Milk}
8
+ gem.summary = %q{Console interface to Remember The Milk}
9
+ gem.homepage = "https://github.com/jackmurray/atm"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "atm"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ATM::VERSION
17
+
18
+ gem.add_dependency('hashie')
19
+ end
data/bin/atm ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'atm'
4
+
5
+ include ATM
6
+
7
+ case ARGV.first
8
+
9
+ when "c", "console"
10
+ ARGV.shift
11
+ require 'irb'
12
+ require 'irb/completion'
13
+ IRB.start
14
+
15
+ when "all"
16
+ ATM::Task.all.each do |task|
17
+ print "#{task.due} #{task.name}\n"
18
+ end
19
+
20
+ when nil, "now", "today"
21
+ tasks = ATM::Task.all
22
+
23
+ range_start = Time.new.beginning_of_day
24
+ range_end = range_start + 1.day
25
+
26
+ tasks.each do |task|
27
+ if not task.due or ( range_start <= task.due and task.due < range_end )
28
+ due = " "*5
29
+ if task.due and task.due != ""
30
+ if task.has_due_time
31
+ due = task.due.localtime.strftime("%H:%M")
32
+ else
33
+ due = "today"
34
+ end
35
+ end
36
+ print "#{due} #{task.name}\n"
37
+ end
38
+ end
39
+
40
+ else
41
+ print "TODO usage\n"
42
+
43
+ end
data/lib/atm/ext.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+
3
+ class Time
4
+ # in whatever timezone it happens to be in
5
+ rake_extension("beginning_of_day") do
6
+ def beginning_of_day
7
+ Time.new year, month, day, 0, 0, 0, utc_offset
8
+ end
9
+ end
10
+ end
11
+
12
+ class Numeric
13
+ # patch so we can do time + 1.day
14
+ rake_extension("day") do
15
+ def day
16
+ self * 60 * 60 * 24
17
+ end
18
+ end
19
+ end
20
+
21
+ class Object
22
+ rake_extension("in_array") do
23
+ def in_array
24
+ if nil? or kind_of? Array
25
+ to_a
26
+ else
27
+ [self]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ class String
34
+ rake_extension("camelcase") do
35
+ def camelcase
36
+ gsub(/_./) do |x|
37
+ x[-1].upcase
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/atm/list.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'atm'
2
+
3
+ module ATM
4
+ class List
5
+ attr_reader :taskseries, :id
6
+
7
+ def List.all
8
+ lists = RTM.tasks.get_list.tasks.list.in_array
9
+ lists.map do |l|
10
+ List.new l
11
+ end
12
+ end
13
+
14
+ def initialize(obj)
15
+ obj = Hashie::Mash.new obj
16
+ @id = obj.id
17
+ @taskseries = obj.taskseries.in_array.map do |t|
18
+ t.list = self
19
+ Taskseries.new t
20
+ end
21
+ end
22
+
23
+ def delete!
24
+ @taskseries.each do |task|
25
+ taskseries.delete!
26
+ end
27
+ RTM.lists.delete :list_id => :id
28
+ end
29
+ end
30
+ end
data/lib/atm/rtm.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'cgi'
2
+ require 'digest/md5'
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'yaml'
6
+ require 'singleton'
7
+ require 'hashie'
8
+
9
+ module ATM
10
+ class Requester
11
+ include Singleton
12
+
13
+ def request(method, args = {})
14
+ sleep 1
15
+ obj = JSON open(url(args.merge :method => method)).read
16
+ obj = Hashie::Mash.new(obj)
17
+ obj.rsp
18
+ end
19
+
20
+ private
21
+
22
+ REST_URL = "https://api.rememberthemilk.com/services/rest/"
23
+
24
+ def initialize
25
+ # same config file as moocow gem.
26
+ @config = YAML::load_file("#{ENV['HOME']}/.rtmapi.yaml")
27
+ @timeline = request("rtm.timelines.create")["timeline"]
28
+ end
29
+
30
+ def signature(request)
31
+ Digest::MD5.hexdigest(@config[:secret] + request.to_a.sort.join)
32
+ end
33
+
34
+ def url(request)
35
+ request[:api_key] = @config[:api_key]
36
+ request[:auth_token] = @config[:token]
37
+ request[:timeline] = @timeline if @timeline
38
+ request[:format] = :json
39
+ request[:api_sig] = signature(request)
40
+
41
+ # concatenate url, ?, and escaped key=value pairs, joined together with &
42
+ params = request.map do |k,v|
43
+ CGI.escape(k.to_s) + ?= + CGI.escape(v.to_s)
44
+ end
45
+
46
+ REST_URL + ?? + params.join(?&)
47
+ end
48
+ end
49
+
50
+ class RTM
51
+ def initialize(java_class)
52
+ @class = java_class.to_s.camelcase
53
+ end
54
+
55
+ def method_missing(symbol, args = {})
56
+ if @class == "tasks" and symbol.to_s == "notes"
57
+ RTM.new "tasks.notes"
58
+ else
59
+ method = symbol.to_s.camelcase
60
+ Requester.instance.request "rtm.#{@class}.#{method}", args
61
+ end
62
+ end
63
+
64
+ def RTM.test
65
+ RTM.new :test
66
+ end
67
+
68
+ def RTM.method_missing(symbol)
69
+ RTM.new symbol
70
+ end
71
+ end
72
+ end
data/lib/atm/task.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'atm'
2
+
3
+ module ATM
4
+ class Task
5
+ attr_reader :due, :has_due_time
6
+
7
+ def Task.all
8
+ Taskseries.all.inject([]) do |array, taskseries|
9
+ array.concat taskseries.tasks
10
+ end
11
+ end
12
+
13
+ def initialize(obj)
14
+ load_values obj
15
+ end
16
+
17
+ def load_values(obj)
18
+ obj = Hashie::Mash.new obj
19
+ @id = obj.id
20
+ @taskseries = obj.taskseries
21
+ if obj.due and obj.due != ""
22
+ @due = Time.parse obj.due
23
+ @has_due_time = (
24
+ obj.has_due_time != "0" and
25
+ obj.has_due_time.downcase != "false"
26
+ )
27
+ end
28
+ end
29
+
30
+ def name
31
+ @taskseries.name
32
+ end
33
+
34
+ def delete!
35
+ RTM.tasks.delete :list_id => @taskseries.list.id,
36
+ :taskseries_id => @taskseries.id,
37
+ :task_id => @id
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,46 @@
1
+ require 'atm'
2
+
3
+ module ATM
4
+ class Taskseries
5
+ attr_reader :id, :name, :list, :tasks
6
+
7
+ def Taskseries.all
8
+ List.all.inject([]) do |array, list|
9
+ array.concat list.taskseries
10
+ end
11
+ end
12
+
13
+ def initialize(obj)
14
+ load_values obj
15
+ end
16
+
17
+ def load_values(obj)
18
+ obj = Hashie::Mash.new obj
19
+ @id = obj.id
20
+ @list = obj.list
21
+ @name = obj.name
22
+ @taskseries_id = obj.id
23
+ @tasks = (obj.task || obj.tasks).in_array.map do |task|
24
+ task.taskseries = self
25
+ Task.new task
26
+ end
27
+ end
28
+
29
+ def save!
30
+ if @id.nil?
31
+ rsp = RTM.tasks.add :name => name, :parse => 1
32
+ load_values rsp.list.taskseries
33
+ else
34
+ throw NotImplementedError
35
+ end
36
+ self
37
+ end
38
+
39
+ def delete!
40
+ tasks.each do |task|
41
+ task.delete!
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module ATM
2
+ VERSION = "0.0.1"
3
+ end
data/lib/atm.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'atm/ext'
2
+ require 'atm/list'
3
+ require 'atm/rtm'
4
+ require 'atm/task'
5
+ require 'atm/taskseries'
6
+ require 'atm/version'
7
+ require 'hashie'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jack Murray
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Console interface to Remember The Milk
31
+ email:
32
+ - jack@murray.cx
33
+ executables:
34
+ - atm
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - atm.gemspec
44
+ - bin/atm
45
+ - lib/atm.rb
46
+ - lib/atm/ext.rb
47
+ - lib/atm/list.rb
48
+ - lib/atm/rtm.rb
49
+ - lib/atm/task.rb
50
+ - lib/atm/taskseries.rb
51
+ - lib/atm/version.rb
52
+ homepage: https://github.com/jackmurray/atm
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Console interface to Remember The Milk
76
+ test_files: []