ruby-wunderlist 0.1.pre

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.
@@ -0,0 +1,146 @@
1
+ # (Inofficial) Wunderlist API Bindings
2
+ # vim: sw=2 ts=2 ai et
3
+ #
4
+ # Copyright (c) 2011 Fritz Grimpen
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require "net/http"
25
+ require "digest/md5"
26
+ require "json"
27
+ require "nokogiri"
28
+ require "date"
29
+
30
+ require "wunderlist/list"
31
+ require "wunderlist/task"
32
+
33
+ module Wunderlist
34
+ class API
35
+ attr_reader :domain, :path, :email, :session
36
+
37
+ def initialize(domain = "www.wunderlist.com", path = "/")
38
+ @domain = domain
39
+ @path = path
40
+ @http = Net::HTTP.new(@domain)
41
+ @logged_in = false
42
+ end
43
+
44
+ def login(email, password)
45
+ get_session if @session == nil
46
+ return true if @logged_in
47
+ @email = email
48
+
49
+ req = prepare_request(Net::HTTP::Post.new "#{@path}/ajax/user")
50
+ req.set_form_data({ "email" => @email, "password" => Digest::MD5.hexdigest(password) })
51
+ res = JSON.parse(@http.request(req).body)
52
+
53
+ @logged_in = true if res["code"] == 200
54
+ @logged_in
55
+ end
56
+
57
+ def flush
58
+ @lists = nil
59
+ end
60
+
61
+ def lists
62
+ @lists = load_lists if @lists == nil
63
+ @lists
64
+ end
65
+
66
+ def tasks(list)
67
+ list_obj = list.is_a?(Wunderlist::List) ? list : lists[list]
68
+ list = list.id if list.is_a? Wunderlist::List
69
+
70
+ request = prepare_request(Net::HTTP::Get.new "#{@path}/ajax/lists/id/#{list}")
71
+ response = @http.request request
72
+ result = []
73
+
74
+ Nokogiri::HTML(JSON.parse(response.body)["data"]).css("li.more").each do |html_task|
75
+ task = Wunderlist::Task.new
76
+ task.id = html_task.attributes["id"].value.to_i
77
+ task.name = html_task.css("span.description").first.content
78
+ task.important = html_task.css("span.fav").empty? ? false : true
79
+ task.done = html_task.attributes["class"].value.split(" ").include?("done")
80
+ html_timestamp = html_task.css("span.timestamp")
81
+ task.date = Time.at(html_timestamp.first.attributes["rel"].
82
+ value.to_i).to_date unless html_timestamp.empty?
83
+ task.api = self
84
+ task.list = list_obj
85
+
86
+ result << task
87
+ end
88
+
89
+ result
90
+ end
91
+
92
+ def save(obj)
93
+ if obj.is_a? Wunderlist::List
94
+ return save_list obj
95
+ elsif obj.is_a? Wunderlist::Task
96
+ return save_task obj
97
+ end
98
+ end
99
+
100
+ def save_list(obj)
101
+ json_data = {}
102
+ json_data["id"] = obj.id
103
+ json_data["name"] = obj.name
104
+
105
+ request = prepare_request(Net::HTTP::Post.new "#{@path}/ajax/lists/update")
106
+ request.set_form_data "list" => json_data.to_json
107
+ response = @http.request request
108
+
109
+ if JSON.parse(response.body)["status"] == "success"
110
+ return true
111
+ end
112
+
113
+ return false
114
+ end
115
+
116
+ protected
117
+ def get_session
118
+ res = @http.request_get("#{@path}/account")
119
+ @session = res["Set-Cookie"].match(/WLSESSID=([0-9a-zA-Z]+)/)[1]
120
+ end
121
+
122
+ def load_lists
123
+ request = prepare_request(Net::HTTP::Get.new "#{@path}/ajax/lists/all")
124
+ response = @http.request request
125
+ result = {}
126
+
127
+ JSON.parse(response.body)["data"].each do |list_elem|
128
+ list = Wunderlist::List.new
129
+ list.id = list_elem[0].to_i
130
+ list.name = list_elem[1]["name"]
131
+ list.inbox = list_elem[1]["inbox"] == "1" ? true : false
132
+ list.shared = list_elem[1]["shared"] == "1" ? true : false
133
+ list.api = self
134
+
135
+ result[list.id] = list
136
+ end
137
+
138
+ result
139
+ end
140
+
141
+ def prepare_request(req)
142
+ req["Cookie"] = "WLSESSID=#{@session}"
143
+ req
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,47 @@
1
+ # (Inofficial) Wunderlist API Bindings
2
+ # vim: sw=2 ts=2 ai et
3
+ #
4
+ # Copyright (c) 2011 Fritz Grimpen
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ module Wunderlist
25
+ class List
26
+ attr_accessor :id, :name, :inbox, :shared, :api
27
+
28
+ def initialize(name = nil, inbox = nil)
29
+ @name = name
30
+ @inbox = inbox
31
+ end
32
+
33
+ def tasks
34
+ @tasks = @api.tasks self if @tasks == nil
35
+ @tasks
36
+ end
37
+
38
+ def save(api = nil)
39
+ @api ||= api
40
+ @api.save_list(self)
41
+ end
42
+
43
+ def flush
44
+ @tasks = nil
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ # (Inofficial) Wunderlist API Bindings
2
+ # vim: sw=2 ts=2 ai et
3
+ #
4
+ # Copyright (c) 2011 Fritz Grimpen
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require "wunderlist/list"
25
+
26
+ class Wunderlist::Task
27
+ attr_accessor :id, :name, :important, :done, :date, :api, :list
28
+
29
+ def initialize(name = nil, date = nil, list = nil, api = nil)
30
+ @name = name
31
+ @date = date
32
+ @api = api
33
+ @list = list
34
+ end
35
+
36
+ def save(api = nil)
37
+ @api ||= api
38
+ @api.save_task self
39
+ end
40
+ end
data/lib/wunderlist.rb ADDED
@@ -0,0 +1,27 @@
1
+ # (Inofficial) Wunderlist API Bindings
2
+ # vim: sw=2 ts=2 ai et
3
+ #
4
+ # Copyright (c) 2011 Fritz Grimpen
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require "wunderlist/api"
25
+
26
+ module Wunderlist
27
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-wunderlist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.pre
5
+ prerelease: 4
6
+ platform: ruby
7
+ authors:
8
+ - Fritz Grimpen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &76529340 !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: *76529340
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &76528980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *76528980
36
+ description:
37
+ email: fritz+wunderlist@grimpen.net
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/wunderlist/list.rb
43
+ - lib/wunderlist/task.rb
44
+ - lib/wunderlist/api.rb
45
+ - lib/wunderlist.rb
46
+ homepage:
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>'
62
+ - !ruby/object:Gem::Version
63
+ version: 1.3.1
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.10
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Wunderlist Bindings for Ruby
70
+ test_files: []