wunderlist-api 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/lib/wunderlist/api.rb +28 -6
- data/lib/wunderlist/helper.rb +32 -0
- data/lib/wunderlist/list.rb +35 -0
- data/lib/wunderlist/note.rb +1 -13
- data/lib/wunderlist/task.rb +3 -6
- data/lib/wunderlist/task_comment.rb +12 -4
- data/lib/wunderlist/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbe11b8e47330b37513299758e6b04c2f8c8093
|
4
|
+
data.tar.gz: 602db7a2cff0790365c909b0e075d8c7925f53d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34bd832e673de9ccde8d05862a1a95db0423def113801e07a097c6b4105e178fd7f12ffa47b50a4f064d343f37d55f1f560651f9b970a5e27bc6eb48488e6e79
|
7
|
+
data.tar.gz: 8f243a3d0878c594d8bfbdeaf0de6ecaaf0cd611fe42f0c44c9c44478f9971c58ec9ec47577ff90955475a6df25caaed16e78b054666e1ab69d24a6474357672
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ wl = Wunderlist::API.new({
|
|
27
27
|
|
28
28
|
|
29
29
|
# You can create Task
|
30
|
-
task = wl.new_task(LIST_NAME, {
|
30
|
+
task = wl.new_task(LIST_NAME, {:title => 'Hello World', :completed => true, :due_date => '2015-03-25' })
|
31
31
|
task.save
|
32
32
|
|
33
33
|
|
data/lib/wunderlist/api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "wunderlist/version"
|
2
2
|
require "wunderlist/task"
|
3
|
+
require "wunderlist/list"
|
3
4
|
require 'faraday'
|
4
5
|
require 'json'
|
5
6
|
|
@@ -21,17 +22,37 @@ module Wunderlist
|
|
21
22
|
@client_id = options[:client_id]
|
22
23
|
end
|
23
24
|
|
25
|
+
def list(list_name)
|
26
|
+
list_name = [list_name]
|
27
|
+
list_id = get_list_ids(list_name)[0]
|
28
|
+
res_list = self.request :get, "api/v1/lists/#{list_id}"
|
29
|
+
list = Wunderlist::List.new(res_list)
|
30
|
+
list.api = self
|
31
|
+
|
32
|
+
list
|
33
|
+
|
34
|
+
end
|
35
|
+
|
24
36
|
def lists
|
25
|
-
self.request :get, 'api/v1/lists'
|
37
|
+
res_lists = self.request :get, 'api/v1/lists'
|
38
|
+
lists = []
|
39
|
+
res_lists.each do |l|
|
40
|
+
list = Wunderlist::List.new(l)
|
41
|
+
list.api = self
|
42
|
+
lists << list
|
43
|
+
end
|
44
|
+
|
45
|
+
lists
|
46
|
+
|
26
47
|
end
|
27
48
|
|
28
49
|
def tasks(list_names = [], completed = false)
|
29
50
|
list_ids = get_list_ids(list_names)
|
30
51
|
tasks = []
|
31
52
|
list_ids.each do |list_id|
|
32
|
-
|
33
|
-
if !
|
34
|
-
|
53
|
+
res_tasks = self.request :get, 'api/v1/tasks', {:list_id => list_id, :completed => completed}
|
54
|
+
if !res_tasks.empty?
|
55
|
+
res_tasks.each do |t|
|
35
56
|
task = Wunderlist::Task.new(t)
|
36
57
|
task.api = self
|
37
58
|
tasks << task
|
@@ -44,6 +65,7 @@ module Wunderlist
|
|
44
65
|
end
|
45
66
|
|
46
67
|
def new_task(list_name, attrs = {})
|
68
|
+
attrs.stringify_keys
|
47
69
|
list_name = [list_name]
|
48
70
|
list_id = get_list_ids(list_name)[0]
|
49
71
|
attrs['list_id'] = list_id
|
@@ -114,9 +136,9 @@ module Wunderlist
|
|
114
136
|
def get_list_ids(list_names = [])
|
115
137
|
lists = self.lists
|
116
138
|
if !list_names.empty?
|
117
|
-
lists = lists.select{|elm| list_names.include?(elm
|
139
|
+
lists = lists.select{|elm| list_names.include?(elm.title)}
|
118
140
|
end
|
119
|
-
lists.map{|list| list
|
141
|
+
lists.map{|list| list.id}
|
120
142
|
end
|
121
143
|
|
122
144
|
end
|
data/lib/wunderlist/helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Wunderlist
|
2
2
|
module Helper
|
3
3
|
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
4
6
|
def to_hash
|
5
7
|
instance_variables = self.instance_variables
|
6
8
|
instance_variables.delete(':@api')
|
@@ -9,6 +11,36 @@ module Wunderlist
|
|
9
11
|
return hash
|
10
12
|
end
|
11
13
|
|
14
|
+
def update
|
15
|
+
model_name = get_plural_model_name
|
16
|
+
self.api.request :put, "api/v1/#{model_name}/#{self.id}", self.to_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
model_name = get_plural_model_name
|
21
|
+
puts model_name
|
22
|
+
if self.id.nil?
|
23
|
+
res = self.api.request :post, "api/v1/#{model_name}", self.to_hash
|
24
|
+
else
|
25
|
+
res = self.update
|
26
|
+
end
|
27
|
+
set_attrs(res)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get_plural_model_name
|
33
|
+
self.class.to_s.gsub('Wunderlist::','').downcase.pluralize
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Hash
|
40
|
+
|
41
|
+
def stringify_keys
|
42
|
+
self.replace(self.inject({}){|a,(k,v)| a[k.to_s] = v; a})
|
12
43
|
end
|
44
|
+
|
13
45
|
end
|
14
46
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'wunderlist/helper'
|
2
|
+
|
3
|
+
module Wunderlist
|
4
|
+
class List
|
5
|
+
|
6
|
+
include Wunderlist::Helper
|
7
|
+
|
8
|
+
attr_accessor :id, :title, :api, :created_at, :revision
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@api = options['api']
|
12
|
+
@id = options['id']
|
13
|
+
@title = options['title']
|
14
|
+
@created_at = options['created_at']
|
15
|
+
@revision = options['revision']
|
16
|
+
end
|
17
|
+
|
18
|
+
def tasks(completed = false)
|
19
|
+
self.api.tasks([self.title])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def set_attrs(res)
|
25
|
+
self.api = res['api']
|
26
|
+
self.id = res['id']
|
27
|
+
self.task_id = res['task_id']
|
28
|
+
self.content = res['content']
|
29
|
+
self.created_at = res['created_at']
|
30
|
+
self.updated_at = res['updated_at']
|
31
|
+
self.revision = res['revision']
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/wunderlist/note.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'wunderlist/helper'
|
2
|
-
require 'wunderlist/api'
|
3
2
|
|
4
3
|
module Wunderlist
|
5
4
|
class Note
|
@@ -18,18 +17,7 @@ module Wunderlist
|
|
18
17
|
@revision = options['revision']
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
self.api.request :put, "api/v1/notes/#{self.id}", self.to_hash
|
23
|
-
end
|
24
|
-
|
25
|
-
def save
|
26
|
-
if self.id.nil?
|
27
|
-
res = self.api.request :post, "api/v1/notes", self.to_hash
|
28
|
-
else
|
29
|
-
res = self.update
|
30
|
-
end
|
31
|
-
self.set_attrs(res)
|
32
|
-
end
|
20
|
+
private
|
33
21
|
|
34
22
|
def set_attrs(res)
|
35
23
|
self.api = res['api']
|
data/lib/wunderlist/task.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'wunderlist/helper'
|
2
1
|
require 'wunderlist/note'
|
3
2
|
require 'wunderlist/task_comment'
|
3
|
+
require 'wunderlist/helper'
|
4
4
|
|
5
5
|
module Wunderlist
|
6
6
|
class Task
|
@@ -21,11 +21,6 @@ module Wunderlist
|
|
21
21
|
@due_date = options['due_date']
|
22
22
|
@starred = options['starred']
|
23
23
|
end
|
24
|
-
|
25
|
-
def save
|
26
|
-
res = self.api.request :post, 'api/v1/tasks', self.to_hash
|
27
|
-
self.set_attrs(res)
|
28
|
-
end
|
29
24
|
|
30
25
|
def task_comments
|
31
26
|
res = self.api.request :get, 'api/v1/task_comments', {:task_id => self.id}
|
@@ -56,6 +51,8 @@ module Wunderlist
|
|
56
51
|
|
57
52
|
end
|
58
53
|
|
54
|
+
private
|
55
|
+
|
59
56
|
def set_attrs(res)
|
60
57
|
self.id = res['id']
|
61
58
|
self.title = res['title']
|
@@ -5,9 +5,7 @@ module Wunderlist
|
|
5
5
|
|
6
6
|
include Wunderlist::Helper
|
7
7
|
|
8
|
-
attr_accessor :text, :type
|
9
|
-
attr_reader :id, :task_id, :revision, :created_at
|
10
|
-
|
8
|
+
attr_accessor :text, :type, :id, :task_id, :revision, :created_at
|
11
9
|
|
12
10
|
def initialize(options = {})
|
13
11
|
@api = options['api']
|
@@ -19,7 +17,17 @@ module Wunderlist
|
|
19
17
|
@created_at = options['created_at']
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_attrs(res)
|
23
|
+
self.api = res['api']
|
24
|
+
self.id = res['id']
|
25
|
+
self.task_id = res['task_id']
|
26
|
+
self.revision = res['revision']
|
27
|
+
self.text = res['text']
|
28
|
+
self.type = res['type']
|
29
|
+
self.created_at = res['created_at']
|
23
30
|
end
|
31
|
+
|
24
32
|
end
|
25
33
|
end
|
data/lib/wunderlist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wunderlist-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shun3475
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/wunderlist.rb
|
70
70
|
- lib/wunderlist/api.rb
|
71
71
|
- lib/wunderlist/helper.rb
|
72
|
+
- lib/wunderlist/list.rb
|
72
73
|
- lib/wunderlist/note.rb
|
73
74
|
- lib/wunderlist/task.rb
|
74
75
|
- lib/wunderlist/task_comment.rb
|