-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskk.coffee
112 lines (95 loc) · 2.64 KB
/
taskk.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Taskk API Javascript library.
# https://api.taskk.it.
# Taskk API V1
####################
# Example Usage:
#
# taskk_api = new TaskkAPI('token')
# ping = taskk_api.ping()
# ping.success (data) -> alert(JSON.stringify(data))
# ping.error (data) -> alert(JSON.stringify(data))
#
####################
class TaskkAPI
domain = "https://api.taskk.it/v1/"
auth = ""
constructor: (@token) ->
# Use token if present.
if @token
this.set_token(@token)
set_token: (token) ->
auth = "?token=" + token
# Check if can authenticate
ping: ->
$.get domain + "auth/ping/" + auth
make_base_auth = (user, password) ->
# Check if can authenticate
login: (login, password) ->
$.ajax
type: "POST"
url: domain + "auth/login/"
contentType:"application/json; charset=utf-8"
dataType:"json"
beforeSend: (xhr) ->
tok = login + ":" + password
hash = btoa(tok)
basic_auth = "Basic " + hash
xhr.setRequestHeader "Authorization", basic_auth
return
# Get all lists
get_lists: ->
$.get domain + "lists/" + auth
# Get all tasks
get_tasks: ->
$.get domain + "tasks/" + auth
# Get specific task (id)
get_task: (id) ->
$.get domain + "tasks/" + id + "/" + auth
# Get specific list (id)
get_list: (id) ->
$.get domain + "lists/" + id + "/" + auth
# create a task (title, estimate, list_id)
create_task: (params) ->
$.ajax(
url: domain + "tasks/" + auth
type: "POST"
data: JSON.stringify({task: params})
contentType:"application/json; charset=utf-8"
dataType:"json"
)
# create a list (title, description, color). Color = Hexidecimal. #FFFFFF
create_list: (params) ->
$.ajax(
url: domain + "lists/" + auth
type: "POST"
data: JSON.stringify({list: params})
contentType:"application/json; charset=utf-8"
dataType:"json"
)
# Update specific task (id, params)
edit_task: (id, params) ->
$.ajax(
url: domain + "tasks/" + id + "/" + auth
type: "PUT"
contentType:"application/json; charset=utf-8"
dataType:"json"
data: JSON.stringify({task: params})
)
# Complete a task
complete_task: (id) ->
$.ajax(
url: domain + "tasks/" + id + "/complete" + auth
type: "PUT"
contentType:"application/json; charset=utf-8"
dataType:"json"
)
# Update specific list (id, params)
edit_list: (id, params) ->
$.ajax(
url: domain + "lists/" + id + "/" + auth
type: "PUT"
contentType:"application/json; charset=utf-8"
dataType:"json"
data: JSON.stringify({list: params})
)
window.TaskkAPI = TaskkAPI