Current section

4 Versions

Jump to

Compare versions

6 files changed
+20 additions
-15 deletions
  @@ -2,10 +2,11 @@
2 2
3 3 A Typetalk client library for Elixir language.
4 4
5 + API Document: https://hexdocs.pm/typetalk/api-reference.html
6 +
5 7 ## Installation
6 8
7 - If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8 - by adding `typetalk` to your list of dependencies in `mix.exs`:
9 + This package can be installed by adding `typetalk` to your list of dependencies in `mix.exs`:
9 10
10 11 ```elixir
11 12 def deps do
  @@ -35,14 +36,18 @@ scope = "my,topic.read,topic.post"
35 36
36 37 ### Using authorization code
37 38
39 + Take the user to the authorization page.
40 + ```elixir
41 + client_id = System.get_env("TYPETALK_CLIENT_ID")
42 + redirect_url = "https://example.com/oauth_callback"
43 + scope = "my,topic.read,topic.post"
44 + url = Typetalk.AuthorizationCode.authorization_url(client_id, redirect_url, scope)
45 + ```
46 +
47 + Use the published authorization token (`auth_code` in the example below) to get an access token.
38 48 ```elixir
39 49 client_id = System.get_env("TYPETALK_CLIENT_ID")
40 50 client_secret = System.get_env("TYPETALK_CLIENT_SECRET")
41 - scope = "my,topic.read,topic.post"
42 - url = Typetalk.AuthorizationCode.authorization_url(client_id, client_secret, scope)
43 - # Navigate the user to this URL to get an authorization code.
44 -
45 - # auth_code is an authorization code the user has got at Typetalk's authorization page.
46 51 {:ok, access_token} = Typetalk.AuthorizationCode.access_token(client_id, client_secret, auth_code)
47 52 {:ok, spaces} = Typetalk.get_spaces(access_token)
48 53 ```
  @@ -25,4 +25,4 @@
25 25 {<<"name">>,<<"socket">>},
26 26 {<<"optional">>,false},
27 27 {<<"requirement">>,<<"~> 0.3">>}]]}.
28 - {<<"version">>,<<"0.1.0">>}.
28 + {<<"version">>,<<"0.1.1">>}.
  @@ -162,12 +162,12 @@ defmodule Typetalk do
162 162 end
163 163
164 164 defp make_attachment_file_urls(values) do
165 - Enum.zip(values, 0..(length(values)-1))
165 + Enum.with_index(values)
166 166 |> Enum.map(fn {value, idx} -> {:"attachments[#{idx}].fileUrl", value} end)
167 167 end
168 168
169 169 defp make_attachment_file_names(values) do
170 - Enum.zip(values, 0..(length(values)-1))
170 + Enum.with_index(values)
171 171 |> Enum.map(fn {value, idx} -> {:"attachments[#{idx}].fileName", value} end)
172 172 end
173 173
  @@ -520,7 +520,7 @@ defmodule Typetalk do
520 520 """
521 521 @spec create_talk(token, String.t, String.t, [integer]) :: {:ok, map}|{:error, map}
522 522 def create_talk(token, topic_id, name, post_ids) do
523 - data = Enum.zip(post_ids, 0..(length(post_ids) - 1))
523 + data = Enum.with_index(post_ids)
524 524 |> Enum.reduce(%{"talkName" => name}, fn ({post_id, idx}, acc) -> Map.put(acc, "postIds[#{idx}]", post_id) end)
525 525 |> URI.encode_query()
526 526 post(token, "topics/#{topic_id}/talks", data)
  @@ -553,7 +553,7 @@ defmodule Typetalk do
553 553 """
554 554 @spec add_messages_to_talk(token, String.t, String.t, [integer]) :: {:ok, map}|{:error, map}
555 555 def add_messages_to_talk(token, topic_id, talk_id, post_ids) do
556 - data = Enum.zip(post_ids, 0..(length(post_ids) - 1))
556 + data = Enum.with_index(post_ids)
557 557 |> Enum.reduce(%{}, fn ({post_id, idx}, acc) -> Map.put(acc, "postIds[#{idx}]", post_id) end)
558 558 |> URI.encode_query()
559 559 post(token, "topics/#{topic_id}/talks/#{talk_id}/posts", data)
  @@ -19,7 +19,7 @@ defmodule Typetalk.Server do
19 19 # OTP callbacks
20 20 #
21 21
22 - defp handle_call({api, args}, _from, auth) do
22 + def handle_call({api, args}, _from, auth) do
23 23 result = apply(Typetalk, api, [auth | args])
24 24 {:reply, result, auth}
25 25 end
  @@ -19,7 +19,7 @@ defmodule Typetalk.Util do
19 19 end
20 20
21 21 def make_indexed_params(name, values) do
22 - Enum.zip(values, 0..(length(values)-1))
22 + Enum.with_index(values)
23 23 |> Enum.map(fn {value, idx} -> {:"#{name}[#{idx}]", value} end)
24 24 end
25 25 end
Loading more files…