wunderlist-api 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e1da6d56e6a2b7a2e2ca66caf2495d8e059fb95
4
+ data.tar.gz: 358af9890f09d8c158df0e35cc7342684cebbd4d
5
+ SHA512:
6
+ metadata.gz: 3beba88ae6f289d0871754a4ec5ca0390df50878f978509e0328148c791c84dd9249edf77952339476af0b054dc0f3634dc6525ba9f2ea2c5e59317580479699
7
+ data.tar.gz: e9207c4a235b0c740f98899f6b8e25258dc409530844f6e44c5c822213620a830ccdca5a1dd1eed4d00a6bb7f80f5af78464814aeaf014dcefb24efcf5561daa
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wunderlist-api.gemspec
4
+ gemspec
5
+
6
+ gem 'faraday', '~> 0.9.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 shun3475
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Wunderlist::Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wunderlist-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wunderlist-api
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ # You must create API CLIENT at first.
23
+ wl = Wunderlist::API.new({
24
+ :access_token => <your access token>,
25
+ :client_id => <your client id>
26
+ })
27
+
28
+ # You can create Task
29
+ wl.create_task(LIST_NAME, {'title' => 'Hello World', 'completed' => true, 'due_date' => '2015-03-25' })
30
+
31
+ # You can get Wunderlist::Task Object
32
+ task = wl.tasks([LIST_NAME])[0]
33
+ => #<Wunderlist::Task:0x00000000000>
34
+
35
+ # You can create and update note.
36
+ task.notes.each do |note|
37
+ note.content = "Hello World"
38
+ note.update
39
+ end
40
+
41
+ => #<Wunderlist::Note:0x00000000000>
42
+
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/<my-github-username>/wunderlist-api/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+ # wunderlist-api
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/wunderlist.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "wunderlist/version"
2
+ require "wunderlist/api"
3
+
4
+ module Wunderlist
5
+ end
@@ -0,0 +1,124 @@
1
+ require "wunderlist/version"
2
+ require "wunderlist/task"
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Wunderlist
7
+ class API
8
+
9
+ attr_reader :access_token
10
+ attr_reader :client_id
11
+
12
+ API_URL = "https://a.wunderlist.com"
13
+
14
+ def initialize(options = {})
15
+ @conn = Faraday::Connection.new(:url => API_URL) do |builder|
16
+ builder.use Faraday::Request::UrlEncoded
17
+ builder.use Faraday::Response::Logger
18
+ builder.use Faraday::Adapter::NetHttp
19
+ end
20
+ @access_token = options[:access_token]
21
+ @client_id = options[:client_id]
22
+ end
23
+
24
+ def lists
25
+ self.request :get, 'api/v1/lists'
26
+ end
27
+
28
+ def tasks(list_names = [], completed = false)
29
+ list_ids = get_list_ids(list_names)
30
+ tasks = []
31
+ 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|
35
+ task = Wunderlist::Task.new(t)
36
+ task.api = self
37
+ tasks << task
38
+ end
39
+ end
40
+ end
41
+
42
+ tasks
43
+
44
+ end
45
+
46
+ def create_task(list_name, attrs = {})
47
+ list_name = [list_name]
48
+ list_id = get_list_ids(list_name)[0]
49
+ attrs['list_id'] = list_id
50
+ attrs['api'] = self
51
+ @task = Wunderlist::Task.new(attrs)
52
+ @task.save
53
+ end
54
+
55
+ def request(method, url, options = {})
56
+ case method
57
+ when :get then self.get(url, options)
58
+ when :post then self.post(url, options)
59
+ when :put then self.put(url, options)
60
+ end
61
+ end
62
+
63
+ def get(url, options = {})
64
+
65
+ response = @conn.get do |req|
66
+ req.url url
67
+ if options
68
+ options.each do |k, v|
69
+ req.params[k] = v
70
+ end
71
+ end
72
+ req.headers = {
73
+ 'X-Access-Token' => self.access_token,
74
+ 'X-Client-ID' => self.client_id
75
+ }
76
+ end
77
+
78
+ JSON.parse(response.body)
79
+
80
+ end
81
+
82
+ def post(url, options = {})
83
+
84
+ response = @conn.post do |req|
85
+ req.url url
86
+ req.body = options.to_json
87
+ req.headers = {
88
+ 'X-Access-Token' => self.access_token,
89
+ 'X-Client-ID' => self.client_id,
90
+ 'Content-Type' => 'text/json',
91
+ 'Content-Encoding' => 'UTF-8'
92
+ }
93
+ end
94
+
95
+ JSON.parse(response.body)
96
+ end
97
+
98
+ def put(url, options = {})
99
+
100
+ response = @conn.put do |req|
101
+ req.url url
102
+ req.body = options.to_json
103
+ req.headers = {
104
+ 'X-Access-Token' => self.access_token,
105
+ 'X-Client-ID' => self.client_id,
106
+ 'Content-Type' => 'text/json',
107
+ 'Content-Encoding' => 'UTF-8'
108
+ }
109
+ end
110
+
111
+ JSON.parse(response.body)
112
+ end
113
+
114
+
115
+ def get_list_ids(list_names = [])
116
+ lists = self.lists
117
+ if !list_names.empty?
118
+ lists = lists.select{|elm| list_names.include?(elm["title"])}
119
+ end
120
+ lists.map{|list| list['id']}
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,14 @@
1
+ module Wunderlist
2
+ module Helper
3
+
4
+ def to_hash
5
+ instance_variables = self.instance_variables
6
+ instance_variables.delete(':@api')
7
+ hash = {}
8
+ instance_variables.each {|var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
9
+ return hash
10
+ end
11
+
12
+ end
13
+ end
14
+
@@ -0,0 +1,35 @@
1
+ require 'wunderlist/helper'
2
+ require 'wunderlist/api'
3
+
4
+ module Wunderlist
5
+ class Note
6
+
7
+ include Wunderlist::Helper
8
+
9
+ attr_accessor :content, :api
10
+ attr_reader :id, :task_id, :created_at, :updated_at, :revision
11
+
12
+ def initialize(options = {})
13
+ @api = options['api']
14
+ @id = options['id']
15
+ @task_id = options['task_id']
16
+ @content = options['content']
17
+ @created_at = options['created_at']
18
+ @updated_at = options['updated_at']
19
+ @revision = options['revision']
20
+ end
21
+
22
+ def update
23
+ if self.id.nil?
24
+ self.create
25
+ else
26
+ self.api.request :put, "api/v1/notes/#{self.id}", self.to_hash
27
+ end
28
+ end
29
+
30
+ def create
31
+ puts self.api.request :post, "api/v1/notes", self.to_hash
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,65 @@
1
+ require 'wunderlist/helper'
2
+ require 'wunderlist/note'
3
+ require 'wunderlist/task_comment'
4
+
5
+ module Wunderlist
6
+ class Task
7
+
8
+ include Wunderlist::Helper
9
+
10
+ attr_accessor :api, :title, :assignee_id, :completed, :recurrence_type, :recurrence_count, :due_date, :starred
11
+ attr_reader :id, :list_id
12
+
13
+ def initialize(options = {})
14
+ @api = options['api']
15
+ @id = options['id']
16
+ @list_id = options['list_id']
17
+ @title = options['title']
18
+ @assignee_id = options['assignee_id']
19
+ @completed = options['completed']
20
+ @recurrence_type = options['recurrence_type']
21
+ @recurrence_count = options['recurrence_count']
22
+ @due_date = options['due_date']
23
+ @starred = options['starred']
24
+ end
25
+
26
+ def save
27
+ self.api.request :post, 'api/v1/tasks', self.to_hash
28
+ end
29
+
30
+ def task_comments
31
+ res = self.api.request :get, 'api/v1/task_comments', {:task_id => self.id}
32
+ task_comments = []
33
+
34
+ res.each do |t_c|
35
+ task_comment = Wunderlist::TaskComment.new(t_c)
36
+ task_comment.api = self.api
37
+ task_comments << task_comment
38
+ end
39
+
40
+ task_comments
41
+
42
+ end
43
+
44
+ def notes
45
+ res = self.api.request :get, 'api/v1/notes', {:task_id => self.id}
46
+ notes = []
47
+
48
+ res.each do |note|
49
+ note = Wunderlist::Note.new(note)
50
+ note.api = self.api
51
+ notes << note
52
+ end
53
+
54
+ if notes.empty?
55
+ note = Wunderlist::Note.new('task_id' => self.id)
56
+ note.api = self.api
57
+ notes << note
58
+ end
59
+
60
+ notes
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,25 @@
1
+ require 'wunderlist/helper'
2
+
3
+ module Wunderlist
4
+ class TaskComment
5
+
6
+ include Wunderlist::Helper
7
+
8
+ attr_accessor :text, :type
9
+ attr_reader :id, :task_id, :revision, :created_at
10
+
11
+
12
+ def initialize(options = {})
13
+ @api = options['api']
14
+ @id = options['id']
15
+ @task_id = options['task_id']
16
+ @revision = options['revision']
17
+ @text = options['text']
18
+ @type = options['type']
19
+ @created_at = options['created_at']
20
+ end
21
+
22
+ def save
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Wunderlist
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'wunderlist/api'
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wunderlist::Api do
4
+ it 'should have a version number' do
5
+ Wunderlist::Api::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should eq(true)
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wunderlist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wunderlist-api"
8
+ spec.version = Wunderlist::VERSION
9
+ spec.authors = ["shun3475"]
10
+ spec.email = ["imokenpi3475@gmail.com"]
11
+ spec.summary = %q{WunderList Ruby API Client.}
12
+ spec.description = %q{You can manage Your Wunderlist Data with Ruby}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wunderlist-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shun3475
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: You can manage Your Wunderlist Data with Ruby
56
+ email:
57
+ - imokenpi3475@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/wunderlist.rb
70
+ - lib/wunderlist/api.rb
71
+ - lib/wunderlist/helper.rb
72
+ - lib/wunderlist/note.rb
73
+ - lib/wunderlist/task.rb
74
+ - lib/wunderlist/task_comment.rb
75
+ - lib/wunderlist/version.rb
76
+ - spec/spec_helper.rb
77
+ - spec/wunderlist/api_spec.rb
78
+ - wunderlist-api.gemspec
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: WunderList Ruby API Client.
103
+ test_files:
104
+ - spec/spec_helper.rb
105
+ - spec/wunderlist/api_spec.rb