-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.ex
57 lines (45 loc) · 1.77 KB
/
sample.ex
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
defmodule ExrtmSample do
def operate_tasks(permission) do
tasks = Exrtm.Task.get_list()
IO.puts "\n----operate_tasks----"
IO.puts "<Tasks>"
IO.puts Enum.join(Enum.map(tasks, fn(x) -> x.name end), ", ")
if permission == "delete" do
task = Exrtm.Task.add("xxx")
Exrtm.Task.delete(task)
IO.puts "<Task>"
IO.inspect task
end
end
def operate_lists do
lists = Exrtm.List.get_list()
inbox = Exrtm.List.get_by_name("Inbox")
IO.puts "\n----operate_lists----"
IO.puts "<Lists>"
IO.puts Enum.join(Enum.map(lists, fn(x) -> x.name end), ", ")
IO.puts "<Inbox>"
IO.inspect inbox
end
end
key = :os.getenv("RTM_API_KEY") # your api_key of remember the milk
secret = :os.getenv("RTM_SHARED_SECRET") # your shared secret of remember the milk
# specify '-t' to use pre-acquired token (stored in RTM_TOKEN environment variable), instead of frob.
{option, _argv, _} = OptionParser.parse(System.argv, aliases: [t: :token, p: :permission])
use_token = option[:token] != nil
perm = Enum.find(["read", "write", "delete"], "read", fn(x) -> x == option[:permission] end)
IO.puts "[option] use_token = #{use_token}, perm = #{perm}"
if use_token do
token = :os.getenv("RTM_TOKEN") # use pre-stored token to authenticate
user = Exrtm.Auth.init_api(key, secret, token)
else
user = Exrtm.Auth.init_api(key, secret)
frob = Exrtm.Auth.get_frob(user)
IO.puts "Access to the following url using browser to authenticate this script, and then press enter to proceed."
IO.puts Exrtm.Auth.get_auth_url(user, perm, frob)
IO.gets ""
token = Exrtm.Auth.get_token(user, frob)
_user = Exrtm.Auth.init_api(key, secret, token)
IO.puts "token = #{token}"
end
ExrtmSample.operate_lists
ExrtmSample.operate_tasks(perm)