rtmilk 0.0.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ #
2
+ # rtm.timelines : Timelines API
3
+ #
4
+ module RTM
5
+ module Timelines
6
+
7
+ class Create < RTM::API
8
+ def parse_result(result)
9
+ super
10
+ result['timeline'].first
11
+ end
12
+
13
+ def initialize(token)
14
+ super 'rtm.timelines.create', token
15
+ end
16
+ end # Create
17
+
18
+ end # Timelines
19
+
20
+ class Timeline
21
+ def initialize(token)
22
+ @timeline = RTM::Timelines::Create.new(token).invoke
23
+ end
24
+
25
+ def to_s
26
+ @timeline
27
+ end
28
+
29
+ def length
30
+ @timeline.length
31
+ end
32
+ end # Timeline
33
+ end # RTM
34
+ # vim:fdm=indent
@@ -0,0 +1,8 @@
1
+ #
2
+ # Error class
3
+ #
4
+
5
+ module RTM
6
+ # RTM API Eror.
7
+ class Error < StandardError; end
8
+ end # RTM
@@ -1,8 +1,8 @@
1
1
  module Rtmilk #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 2
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ task :default => [:test]
2
+
3
+ task :test do
4
+ ruby 'make_config.rb'
5
+ # ruby 'rtm_api_test.rb'
6
+ # ruby 'rtm_test.rb'
7
+ end
@@ -0,0 +1,82 @@
1
+ #
2
+ # tests for RTM::Auth API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMAuthAPITest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ conf = begin
12
+ Marshal.load(open(CONFIG))
13
+ rescue
14
+ puts 'please run make_config.rb first.'
15
+ exit
16
+ end
17
+
18
+ RTM::API.init(conf[:key], conf[:sec], conf)
19
+ @perms = 'delete'
20
+ end
21
+
22
+ def teardown
23
+ end
24
+
25
+ # -----------------------------------------------------------------
26
+ # helper
27
+ #
28
+ def prompt_for_auth(url)
29
+ puts 'authorize this url : ' + url
30
+ puts 'then, push enter here.'
31
+ gets
32
+ end
33
+
34
+ def get_frob
35
+ frob = RTM::Auth::GetFrob.new.invoke
36
+ assert_equal(40, frob.length)
37
+ return frob
38
+ end
39
+
40
+ def get_token(frob)
41
+ res = RTM::Auth::GetToken.new(frob).invoke
42
+ assert_equal(40, res[:token].length)
43
+ assert_equal(@perms, res[:perms])
44
+ return res[:token]
45
+ end
46
+
47
+ def get_token_interactive
48
+ frob = get_frob
49
+ url = RTM::API.get_auth_url(@perms, frob)
50
+ prompt_for_auth(url)
51
+
52
+ get_token(frob)
53
+ end
54
+
55
+
56
+ # -----------------------------------------------------------------
57
+ # tests
58
+ #
59
+ def test_getFrob
60
+ get_frob
61
+ end
62
+
63
+ def test_invalidToken
64
+ assert_raise(RTM::Error) {
65
+ RTM::Auth::GetToken.new('detarame').invoke
66
+ }
67
+ end
68
+
69
+ # this test requires user authentication manually, so disabed normally.
70
+ def not_test_getToken
71
+ get_token_interactive
72
+ end
73
+
74
+ # this test requires user authentication manually, so disabed normally.
75
+ def not_test_checkToken
76
+ token = get_token_interactive
77
+
78
+ auth = RTM::Auth::CheckToken.new(token).invoke
79
+ assert_equal(@perms, auth[:perms])
80
+ end
81
+ end
82
+ # vim:fdm=indent
@@ -0,0 +1,21 @@
1
+ #
2
+ # tests for RTM::Auth API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMErrorTest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_raise
17
+ assert_raise(RTM::Error) { raise RTM::Error, "login failed" }
18
+ end
19
+
20
+ end
21
+ # vim:fdm=indent
@@ -0,0 +1,82 @@
1
+ #
2
+ # tests for RTM::Lists API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMListsAPITest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ conf = begin
12
+ Marshal.load(open(CONFIG))
13
+ rescue
14
+ puts 'please run make_config.rb first.'
15
+ exit
16
+ end
17
+
18
+ RTM::API.init(conf[:key], conf[:sec], conf)
19
+ @perms = 'read'
20
+ @token = conf[:token]
21
+ end
22
+
23
+ def teardown
24
+ end
25
+
26
+ # -----------------------------------------------------------------
27
+ # helper
28
+ #
29
+
30
+ # -----------------------------------------------------------------
31
+ # tests
32
+ #
33
+ def test_getList
34
+ lists = RTM::Lists::GetList.new(@token).invoke
35
+ assert_instance_of(Array, lists)
36
+ lists.each do |list|
37
+ assert_instance_of(Hash, list)
38
+ assert_equal(true, list.has_key?('name'))
39
+ assert_equal(true, list.has_key?('id'))
40
+ assert_equal(true, list.has_key?('deleted'))
41
+ assert_equal(true, list.has_key?('smart'))
42
+ end
43
+ end
44
+
45
+ def not_test_add
46
+ name = 'testAddList'
47
+ added = RTM::Lists::Add.new(@token, name).invoke
48
+ assert_equal(added['name'], name)
49
+
50
+ # TODO: do filter test
51
+ end # add
52
+
53
+ def not_test_delete
54
+ name = 'testAddList'
55
+ added = RTM::Lists::Add.new(@token, name).invoke
56
+ assert_equal(added['name'], name)
57
+
58
+ deleted = RTM::Lists::Delete.new(@token, added['id']).invoke
59
+ assert_equal(added['name'], deleted['name'])
60
+ assert_equal(added['id'], deleted['id'])
61
+ assert_equal('1', deleted['deleted'])
62
+ end # delete
63
+
64
+ def test_setName
65
+ # add
66
+ name = 'testSetName'
67
+ new_name = 'testSetNameNew'
68
+ added = RTM::Lists::Add.new(@token, name).invoke
69
+ assert_equal(added['name'], name)
70
+
71
+ # setName
72
+ named = RTM::Lists::SetName.new(@token, added['id'], new_name).invoke
73
+ assert_equal(new_name, named['name'])
74
+
75
+ # delete
76
+ deleted = RTM::Lists::Delete.new(@token, added['id']).invoke
77
+ assert_equal(named['name'], deleted['name'])
78
+ assert_equal(named['id'], deleted['id'])
79
+ assert_equal('1', deleted['deleted'])
80
+ end
81
+ end
82
+ # vim:fdm=indent
@@ -0,0 +1,75 @@
1
+ #
2
+ # make config.dat to store API_KEY, SHARED_SECRET, TOKENs.
3
+ #
4
+ require File.dirname(__FILE__) + '/test_helper.rb'
5
+
6
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
7
+
8
+ # if file exists, exit
9
+ if FileTest.readable?(CONFIG)
10
+ exit
11
+ end
12
+
13
+ done = false
14
+
15
+ def getToken(perms, frob)
16
+ url = RTM::API.get_auth_url(perms, frob)
17
+ puts "follow this link to acqure token (#{perms}) : " + url
18
+ puts ', then press enter here.'
19
+ gets
20
+
21
+ res = RTM::Auth::GetToken.new(frob).invoke
22
+ return res[:token]
23
+ end
24
+
25
+ fh = open(CONFIG, 'w')
26
+ begin
27
+ hash = {}
28
+ puts 'Enter your API key.'
29
+ hash[:key] = gets.chomp
30
+
31
+ puts 'Enter your shared secret.'
32
+ hash[:sec] = gets.chomp
33
+
34
+ RTM::API.init(hash[:key], hash[:sec])
35
+
36
+ # get a frob
37
+ frob = RTM::Auth::GetFrob.new.invoke
38
+ puts 'acquired frob : ' + frob
39
+
40
+ #
41
+ # choose permission
42
+ #
43
+ puts 'choose permission: [R]ead, [W]rite, or [D]elete .'
44
+ selected = gets.chomp
45
+
46
+ perms = {
47
+ 'r' => 'read',
48
+ 'R' => 'read',
49
+ 'w' => 'write',
50
+ 'W' => 'write',
51
+ 'd' => 'delete',
52
+ 'D' => 'delete' }
53
+
54
+ #
55
+ # get tokens
56
+ #
57
+ token = getToken(perms[selected], frob)
58
+ hash[:token] = token
59
+
60
+ puts 'acquired token is ' + token
61
+
62
+ #
63
+ # save
64
+ #
65
+ Marshal.dump(hash, fh)
66
+ puts 'all done !!!'
67
+ puts "your informations stored to #{CONFIG}."
68
+ done = true
69
+ ensure
70
+ fh.close
71
+
72
+ unless done
73
+ File.unlink(CONFIG)
74
+ end
75
+ end
@@ -0,0 +1,125 @@
1
+ #
2
+ # tests for RTM::Tasks::Notes API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMTasksNotesAPITest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ conf = begin
12
+ Marshal.load(open(CONFIG))
13
+ rescue
14
+ puts 'please run make_config.rb first.'
15
+ exit
16
+ end
17
+
18
+ RTM::API.init(conf[:key], conf[:sec], conf)
19
+ @perms = 'read'
20
+ @token = conf[:token]
21
+ end
22
+
23
+ def teardown
24
+ end
25
+
26
+ # -----------------------------------------------------------------
27
+ # helper
28
+ #
29
+
30
+ # -----------------------------------------------------------------
31
+ # tests
32
+ #
33
+ def not_test_add
34
+ timeline, err = RTM::Timelines::Create.new(@token).invoke
35
+ assert_equal('ok', err)
36
+ assert_equal(7, timeline.length)
37
+
38
+ lists, err = RTM::Lists::GetList.new(@token).invoke
39
+ assert_equal('ok', err)
40
+ assert_instance_of(Array, lists)
41
+ list = lists.first['id']
42
+
43
+ list_a, err, transaction_add = RTM::Tasks::Add.new(
44
+ @token, timeline, list, 'testTaskAdd').invoke
45
+ assert_equal('ok', err)
46
+
47
+ taskseries = list_a['taskseries'].first['id']
48
+ task = list_a['taskseries'].first['task'].first['id']
49
+
50
+ puts 'creating Note with ' +
51
+ 'timeline=' + timeline +
52
+ ', list=' + list +
53
+ ', taskseries=' + taskseries +
54
+ ', task=' + task
55
+ note, err, transaction = RTM::Tasks::Notes::Add.new(
56
+ @token, timeline, list, taskseries, task, 'testNote', 'testNote body.').invoke
57
+ assert_equal('ok', err)
58
+ assert_instance_of(Hash, note)
59
+ assert_not_equal('', note['id'])
60
+ end
61
+
62
+ def not_test_add_delete
63
+ timeline, err = RTM::Timelines::Create.new(@token).invoke
64
+ assert_equal('ok', err)
65
+ assert_equal(7, timeline.length)
66
+
67
+ lists, err = RTM::Lists::GetList.new(@token).invoke
68
+ assert_equal('ok', err)
69
+ assert_instance_of(Array, lists)
70
+ list = lists.first['id']
71
+
72
+ list_a, err, transaction_add = RTM::Tasks::Add.new(
73
+ @token, timeline, list, 'testTaskAdd').invoke
74
+ assert_equal('ok', err)
75
+
76
+ taskseries = list_a['taskseries'].first['id']
77
+ task = list_a['taskseries'].first['task'].first['id']
78
+
79
+ note, err, transaction = RTM::Tasks::Notes::Add.new(
80
+ @token, timeline, list, taskseries, task, 'testNote', 'testNote body.').invoke
81
+ assert_equal('ok', err)
82
+ assert_instance_of(Array, lists)
83
+
84
+ raise Error if note['id'] == ''
85
+
86
+ err = RTM::Tasks::Notes::Delete.new(@token, timeline, note['id']).invoke
87
+ assert_equal('ok', err.first)
88
+
89
+ list_d, err, transaction = RTM::Tasks::Delete.new(
90
+ @token, timeline, lists.first['id'], taskseries, task).invoke
91
+ assert_equal('ok', err)
92
+ assert_equal(list_a['id'], list_d['id'])
93
+ end
94
+
95
+ def test_edit
96
+ timeline = RTM::Timelines::Create.new(@token).invoke
97
+ assert_equal(7, timeline.length)
98
+
99
+ lists = RTM::Lists::GetList.new(@token).invoke
100
+ assert_instance_of(Array, lists)
101
+ list = lists.first['id']
102
+
103
+ list_a, transaction_add = RTM::Tasks::Add.new(
104
+ @token, timeline, list, 'testTaskAdd').invoke
105
+
106
+ taskseries = list_a['taskseries'].first['id']
107
+ task = list_a['taskseries'].first['task'].first['id']
108
+
109
+ note, transaction = RTM::Tasks::Notes::Add.new(
110
+ @token, timeline, list, taskseries, task, 'testNote', 'testNote body.').invoke
111
+
112
+ raise Error if note['id'] == ''
113
+
114
+ editted, transaction = RTM::Tasks::Notes::Edit.new(
115
+ @token, timeline, note['id'], 'testNote editted', 'testNote body edditted.').invoke
116
+ assert_equal(note['id'], editted['id'])
117
+
118
+ RTM::Tasks::Notes::Delete.new(@token, timeline, note['id']).invoke
119
+
120
+ list_d, transaction = RTM::Tasks::Delete.new(
121
+ @token, timeline, lists.first['id'], taskseries, task).invoke
122
+ assert_equal(list_a['id'], list_d['id'])
123
+ end
124
+ end
125
+ # vim:fdm=indent