class WunderMarkdown::Client

Constants

API_ENDPOINT
API_URL

Attributes

conn[RW]
token[RW]

Public Class Methods

new(token = nil) click to toggle source
# File lib/wunder_markdown/client.rb, line 12
def initialize(token = nil)
  @token = token
  @conn = Faraday.new(:url => API_URL)
end

Public Instance Methods

get(url) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/wunder_markdown/client.rb, line 27
def lists
  @lists ||= get('me/lists')
end
login(email, password) click to toggle source
# 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) click to toggle source
# 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