Class: WunderMarkdown::Client
- Inherits:
-
Object
- Object
- WunderMarkdown::Client
- Defined in:
- lib/wunder_markdown/client.rb
Constant Summary collapse
- API_ENDPOINT =
'api.wunderlist.com'
- API_URL =
"https://#{API_ENDPOINT}"
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(token = nil) ⇒ Client
constructor
A new instance of Client.
- #list(list_name) ⇒ Object
- #lists ⇒ Object
- #login(email, password) ⇒ Object
- #tasks(list) ⇒ Object
Constructor Details
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
10 11 12 |
# File 'lib/wunder_markdown/client.rb', line 10 def conn @conn end |
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/wunder_markdown/client.rb', line 10 def token @token end |
Instance Method Details
#get(url) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/wunder_markdown/client.rb', line 45 def get(url) response = conn.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.headers['Authorization'] = token end JSON.parse(response.body) end |
#list(list_name) ⇒ Object
31 32 33 34 |
# File 'lib/wunder_markdown/client.rb', line 31 def list(list_name) json = lists.detect { |l| l['title'] == list_name } List.new(json['id'], json['title']) end |
#lists ⇒ Object
27 28 29 |
# File 'lib/wunder_markdown/client.rb', line 27 def lists @lists ||= get('me/lists') end |
#login(email, password) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/wunder_markdown/client.rb', line 17 def login(email, password) login_response = conn.post do |req| req.url '/login' req.headers['Content-Type'] = 'application/json' req.body = '{ "email": "'+ email +'", "password": "'+ password +'"}' end @token = JSON.parse(login_response.body)['token'] [email, @token] end |
#tasks(list) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/wunder_markdown/client.rb', line 36 def tasks(list) json = get("#{list.id}/tasks") json.map do |task_json| if task_json['completed_at'] == nil Task.new(task_json['id'], task_json['title'], task_json['note'], task_json['parent_id']) end end.compact end |