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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0e09c6b046a20429837db1b03ba46148d4fadfb
4
- data.tar.gz: 3c60354c7d22ff9c05e23d6378d42e7cf639e927
3
+ metadata.gz: 2cbe11b8e47330b37513299758e6b04c2f8c8093
4
+ data.tar.gz: 602db7a2cff0790365c909b0e075d8c7925f53d1
5
5
  SHA512:
6
- metadata.gz: 988e3091a85eb60631ce1a78fa499b6766ac3c943dda7c7ff0e399708e7d9a307bb9fede62ebf118b1b44e81adedba5d48ab396a37f63df3ff708f1f6a853192
7
- data.tar.gz: d732fc1c2fadd0502ee722662a29a3d5c97aaee673c1709f1c90f74f39e60f097831302b78efa8e167043bc329eebe0d6029e05cd4c37590294b23ee4420887e
6
+ metadata.gz: 34bd832e673de9ccde8d05862a1a95db0423def113801e07a097c6b4105e178fd7f12ffa47b50a4f064d343f37d55f1f560651f9b970a5e27bc6eb48488e6e79
7
+ data.tar.gz: 8f243a3d0878c594d8bfbdeaf0de6ecaaf0cd611fe42f0c44c9c44478f9971c58ec9ec47577ff90955475a6df25caaed16e78b054666e1ab69d24a6474357672
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'faraday', '~> 0.9.1'
7
+ gem 'activesupport'
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, {'title' => 'Hello World', 'completed' => true, 'due_date' => '2015-03-25' })
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
 
@@ -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
- list_tasks = self.request :get, 'api/v1/tasks', {:list_id => list_id, :completed => completed}
33
- if !list_tasks.empty?
34
- list_tasks.each do |t|
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["title"])}
139
+ lists = lists.select{|elm| list_names.include?(elm.title)}
118
140
  end
119
- lists.map{|list| list['id']}
141
+ lists.map{|list| list.id}
120
142
  end
121
143
 
122
144
  end
@@ -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
@@ -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
- def update
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']
@@ -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
- def save
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
@@ -1,3 +1,3 @@
1
1
  module Wunderlist
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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.2
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-23 00:00:00.000000000 Z
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