todoly 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,56 @@
1
- Copyright (c) 2010 nagachika
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.
1
+ RazyK is copyrighted free software by Tomoyuki Chikanaga <nagachika00@gmail.com>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -1,9 +1,9 @@
1
1
  = todoly
2
2
 
3
- Description goes here.
3
+ todoly is REST API client library for Todo.ly (http://todo.ly)
4
4
 
5
5
  == Contributing to todoly
6
-
6
+
7
7
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
8
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
9
  * Fork the project
data/Rakefile CHANGED
@@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "todoly"
16
16
  gem.homepage = "http://github.com/nagachika/ruby-todoly"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{todo.ly REST API Library}
19
- gem.description = %Q{todo.ly REST API Library}
18
+ gem.summary = %Q{Todo.ly REST API Library}
19
+ gem.description = %Q{Todo.ly REST API Library}
20
20
  gem.email = "nagachika00@gmail.com"
21
21
  gem.authors = ["nagachika"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -1,121 +1,36 @@
1
1
 
2
- require "json"
3
- require "rest_client"
4
-
5
- module Todoly
6
-
7
- class TodolyError < StandardError; end
8
-
9
- TODOLY_API_URL = "https://todo.ly/api/"
2
+ require "todoly/rest_interface"
3
+ require "todoly/project"
4
+ require "todoly/filter"
5
+ require "todoly/task"
6
+
7
+ class Todoly
8
+ def initialize(opt={})
9
+ @rest_if = RestInterface.new(opt)
10
+ @projects = nil
11
+ @filters = nil
12
+ @tasks = nil
13
+ end
10
14
 
11
- class Client
12
- def rest_client_with_token(token)
13
- RestClient::Resource.new(@api_url,
14
- :headers => { :Token => token })
15
- end
15
+ def projects
16
+ @projects ||= Project.list(@rest_if)
17
+ end
16
18
 
17
- def rest_client_with_password(user, password)
18
- RestClient::Resource.new(@api_url,
19
- :user => user,
20
- :password => password)
21
- end
19
+ def filters
20
+ @filters ||= Filter.list(@rest_if)
21
+ end
22
22
 
23
- {
24
- :get_token => {
25
- :path => "authentication/token",
26
- :method => :get,
27
- :member => "TokenString",
28
- },
29
- :delete_token => {
30
- :path => "authentication/token",
31
- :method => :delete,
32
- :member => "TokenString",
33
- },
34
- :projects => {
35
- :path => "projects",
36
- :method => :get,
37
- },
38
- :items_of_project => {
39
- :path => "projects/%d/items",
40
- :method => :get,
41
- },
42
- :done_items_of_project => {
43
- :path => "projects/%d/doneitems",
44
- :method => :get,
45
- },
46
- :filters => {
47
- :path => "filters",
48
- :method => :get,
49
- },
50
- :items_of_filter => {
51
- :path => "filters/%d/items",
52
- :method => :get,
53
- },
54
- :items => {
55
- :path => "items",
56
- :method => :get,
57
- },
58
- :item_by_id => {
59
- :path => "items/%d",
60
- :method => :get,
61
- },
62
- :create_item => {
63
- :path => "items",
64
- :method => :post,
65
- },
66
- :delete_item_by_id => {
67
- :path => "items/%d",
68
- :method => :delete,
69
- },
70
- :update_item_by_id => {
71
- :path => "items/%d",
72
- :method => :post,
73
- },
74
- }.each do |meth, data|
75
- class_eval do
76
- define_method(meth) do |*params|
77
- if /_(?:by|of)_/ =~ meth
78
- id, param = params
79
- path = sprintf(data[:path]+".json", id)
80
- else
81
- path = data[:path] + ".json"
82
- param, = params
83
- end
84
- if data[:method] == :post
85
- json = @api[path].send(data[:method], param.to_json)
86
- else
87
- json = @api[path].send(data[:method])
88
- end
89
- obj = JSON.parse(json)
90
- if obj.is_a?(Hash) and obj["ErrorMessage"]
91
- raise TodolyError, obj["ErrorMessage"]
92
- end
93
- if data[:member]
94
- unless obj.include?(data[:member])
95
- raise TodolyError, "expected member #{data[:member]} is not contained"
96
- end
97
- obj = obj[data[:member]]
98
- end
99
- obj
100
- end
101
- end
102
- end
23
+ def tasks
24
+ @tasks ||= Task.list(@rest_if)
25
+ end
103
26
 
104
- def initialize(opt={})
105
- if ENV["https_proxy"]
106
- RestClient.proxy = ENV["https_proxy"]
107
- elsif ENV["http_proxy"]
108
- RestClient.proxy = ENV["http_proxy"]
109
- end
110
- @api_url = opt[:api_url] || TODOLY_API_URL
111
- if opt[:token]
112
- @api = rest_client_with_token(token)
113
- elsif opt[:email] and opt[:password]
114
- @api = rest_client_with_password(opt[:email], opt[:password])
115
- @api = rest_client_with_token(get_token)
116
- else
117
- raise "Please specify :email and :password or :token"
118
- end
27
+ def new_task(str, project = nil)
28
+ obj = {}
29
+ if project
30
+ obj["ProjectId"] = project.id
119
31
  end
32
+ t = Task.create(str, obj)
33
+ @tasks << t if @tasks
34
+ t
120
35
  end
121
36
  end
@@ -0,0 +1,25 @@
1
+
2
+ class Todoly
3
+ class Filter
4
+ def self.list(rest_if)
5
+ rest_if.filters.map do |f|
6
+ self.new(rest_if, f)
7
+ end
8
+ end
9
+
10
+ def initialize(rest_if, obj)
11
+ @rest_if = rest_if
12
+ @raw = obj
13
+ @id = obj["Id"]
14
+ @name = obj["Content"]
15
+ end
16
+
17
+ attr_reader :raw, :id, :name
18
+
19
+ def tasks
20
+ @rest_if.items_of_filter(@id).map do |item|
21
+ Task.new(@rest_if, item)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+
2
+ require "todoly/task"
3
+
4
+ class Todoly
5
+ class Project
6
+
7
+ def self.list(rest_if)
8
+ rest_if.projects.map do |obj|
9
+ self.new(rest_if, obj)
10
+ end
11
+ end
12
+
13
+ def initialize(rest_if, obj)
14
+ @rest_if = rest_if
15
+ @raw = obj
16
+ @id = obj["Id"]
17
+ @name = obj["Content"]
18
+ end
19
+
20
+ attr_reader :raw, :id, :name
21
+
22
+ def tasks
23
+ @rest_if.items_of_project(@id).map do |item|
24
+ Task.new(@rest_if, item)
25
+ end
26
+ end
27
+
28
+ def done_tasks
29
+ @rest_if.done_items_of_project(@id).map do |item|
30
+ Task.new(@rest_if, item)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,122 @@
1
+
2
+ require "json"
3
+ require "rest_client"
4
+
5
+ class Todoly
6
+
7
+ class TodolyError < StandardError; end
8
+
9
+ TODOLY_API_URL = "https://todo.ly/api/"
10
+
11
+ class RestInterface
12
+ def rest_client_with_token(token)
13
+ RestClient::Resource.new(@api_url,
14
+ :headers => { :Token => token })
15
+ end
16
+
17
+ def rest_client_with_password(user, password)
18
+ RestClient::Resource.new(@api_url,
19
+ :user => user,
20
+ :password => password)
21
+ end
22
+
23
+ # REST web API methods
24
+ {
25
+ :get_token => {
26
+ :path => "authentication/token",
27
+ :method => :get,
28
+ :member => "TokenString",
29
+ },
30
+ :delete_token => {
31
+ :path => "authentication/token",
32
+ :method => :delete,
33
+ :member => "TokenString",
34
+ },
35
+ :projects => {
36
+ :path => "projects",
37
+ :method => :get,
38
+ },
39
+ :items_of_project => {
40
+ :path => "projects/%d/items",
41
+ :method => :get,
42
+ },
43
+ :done_items_of_project => {
44
+ :path => "projects/%d/doneitems",
45
+ :method => :get,
46
+ },
47
+ :filters => {
48
+ :path => "filters",
49
+ :method => :get,
50
+ },
51
+ :items_of_filter => {
52
+ :path => "filters/%d/items",
53
+ :method => :get,
54
+ },
55
+ :items => {
56
+ :path => "items",
57
+ :method => :get,
58
+ },
59
+ :item_by_id => {
60
+ :path => "items/%d",
61
+ :method => :get,
62
+ },
63
+ :create_item => {
64
+ :path => "items",
65
+ :method => :post,
66
+ },
67
+ :delete_item_by_id => {
68
+ :path => "items/%d",
69
+ :method => :delete,
70
+ },
71
+ :update_item_by_id => {
72
+ :path => "items/%d",
73
+ :method => :post,
74
+ },
75
+ }.each do |meth, data|
76
+ class_eval do
77
+ define_method(meth) do |*params|
78
+ if /_(?:by|of)_/ =~ meth
79
+ id, param = params
80
+ path = sprintf(data[:path]+".json", id)
81
+ else
82
+ path = data[:path] + ".json"
83
+ param, = params
84
+ end
85
+ if data[:method] == :post
86
+ json = @api[path].send(data[:method], param.to_json)
87
+ else
88
+ json = @api[path].send(data[:method])
89
+ end
90
+ obj = JSON.parse(json)
91
+ if obj.is_a?(Hash) and obj["ErrorMessage"]
92
+ raise TodolyError, obj["ErrorMessage"]
93
+ end
94
+ if data[:member]
95
+ unless obj.include?(data[:member])
96
+ raise TodolyError, "expected member #{data[:member]} is not contained"
97
+ end
98
+ obj = obj[data[:member]]
99
+ end
100
+ obj
101
+ end
102
+ end
103
+ end
104
+
105
+ def initialize(opt={})
106
+ if ENV["https_proxy"]
107
+ RestClient.proxy = ENV["https_proxy"]
108
+ elsif ENV["http_proxy"]
109
+ RestClient.proxy = ENV["http_proxy"]
110
+ end
111
+ @api_url = opt[:api_url] || TODOLY_API_URL
112
+ if opt[:token]
113
+ @api = rest_client_with_token(token)
114
+ elsif opt[:email] and opt[:password]
115
+ @api = rest_client_with_password(opt[:email], opt[:password])
116
+ @api = rest_client_with_token(get_token)
117
+ else
118
+ raise "Please specify :email and :password or :token"
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,52 @@
1
+
2
+ class Todoly
3
+ class Task
4
+ def self.list(rest_if)
5
+ rest_if.items.map do |item|
6
+ self.new(rest_if, item)
7
+ end
8
+ end
9
+
10
+ def self.create(rest_if, name, obj={})
11
+ obj["Content"] = name
12
+ Task.new(rest_if, obj).save
13
+ end
14
+
15
+ def initialize(rest_if, obj)
16
+ @rest_if = rest_if
17
+ set_obj(obj)
18
+ end
19
+
20
+ def set_obj(obj)
21
+ @raw = obj
22
+ @id = obj["Id"]
23
+ @name = obj["Content"]
24
+ end
25
+
26
+ attr_reader :raw, :id, :name
27
+
28
+ def to_s
29
+ @name
30
+ end
31
+
32
+ def name=(new_name)
33
+ @name = @raw["Content"] = new_name
34
+ save
35
+ new_name
36
+ end
37
+
38
+ def check
39
+ @raw["Checked"] = true
40
+ save
41
+ end
42
+
43
+ def save
44
+ if @id
45
+ @rest_if.update_item_by_id(@id, @raw)
46
+ else
47
+ set_obj @rest_if.create_item(@raw)
48
+ end
49
+ self
50
+ end
51
+ end
52
+ end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{todoly}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nagachika"]
12
- s.date = %q{2010-12-15}
13
- s.description = %q{todo.ly REST API Library}
12
+ s.date = %q{2010-12-17}
13
+ s.description = %q{Todo.ly REST API Library}
14
14
  s.email = %q{nagachika00@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -26,6 +26,10 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/todoly.rb",
29
+ "lib/todoly/filter.rb",
30
+ "lib/todoly/project.rb",
31
+ "lib/todoly/rest_interface.rb",
32
+ "lib/todoly/task.rb",
29
33
  "spec/spec_helper.rb",
30
34
  "spec/todoly_spec.rb",
31
35
  "todoly.gemspec"
@@ -34,7 +38,7 @@ Gem::Specification.new do |s|
34
38
  s.licenses = ["MIT"]
35
39
  s.require_paths = ["lib"]
36
40
  s.rubygems_version = %q{1.3.7}
37
- s.summary = %q{todo.ly REST API Library}
41
+ s.summary = %q{Todo.ly REST API Library}
38
42
  s.test_files = [
39
43
  "spec/spec_helper.rb",
40
44
  "spec/todoly_spec.rb"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - nagachika
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-15 00:00:00 +09:00
17
+ date: 2010-12-17 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,7 @@ dependencies:
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: *id005
91
- description: todo.ly REST API Library
91
+ description: Todo.ly REST API Library
92
92
  email: nagachika00@gmail.com
93
93
  executables: []
94
94
 
@@ -107,6 +107,10 @@ files:
107
107
  - Rakefile
108
108
  - VERSION
109
109
  - lib/todoly.rb
110
+ - lib/todoly/filter.rb
111
+ - lib/todoly/project.rb
112
+ - lib/todoly/rest_interface.rb
113
+ - lib/todoly/task.rb
110
114
  - spec/spec_helper.rb
111
115
  - spec/todoly_spec.rb
112
116
  - todoly.gemspec
@@ -124,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
128
  requirements:
125
129
  - - ">="
126
130
  - !ruby/object:Gem::Version
127
- hash: 825769427
131
+ hash: 687932044367518974
128
132
  segments:
129
133
  - 0
130
134
  version: "0"
@@ -142,7 +146,7 @@ rubyforge_project:
142
146
  rubygems_version: 1.3.7
143
147
  signing_key:
144
148
  specification_version: 3
145
- summary: todo.ly REST API Library
149
+ summary: Todo.ly REST API Library
146
150
  test_files:
147
151
  - spec/spec_helper.rb
148
152
  - spec/todoly_spec.rb