Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for the messages remaining api endpoints #6

Merged
merged 1 commit into from
Oct 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/ex_webexteams/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ defmodule ExWebexteams.Api do
@scale Application.get_env(:ex_webexteams, :limit_scale, 10_000)
@limit Application.get_env(:ex_webexteams, :limit_limit, 5)

@doc """
Get the messages from a team room
"""
def view_messages(roomId) do
get("/messages", %{"roomId" => roomId})
end

@doc """
Get a message
"""
def view_message(messageId) do
get("/messages/#{messageId}")
end

@doc """
Send a message to a team room
"""
Expand All @@ -16,6 +30,13 @@ defmodule ExWebexteams.Api do
post("/messages", json)
end

@doc """
Delete a message
"""
def delete_message(messageId) do
delete("/messages/#{messageId}")
end

@doc """
Get a resource (see webex api documentation)

Expand All @@ -30,6 +51,19 @@ defmodule ExWebexteams.Api do
response.body
end

@doc """
Get a resource with parameterized filters (see webex api documentation)

Example `get("/rooms", %{"teamId" => 1})`
"""
def get(path, params) do
path
|> URI.parse()
|> Map.put(:query, URI.encode_query(params))
|> URI.to_string()
|> get()
end

@doc """
Post a resource (see webex api documentation)

Expand All @@ -44,6 +78,20 @@ defmodule ExWebexteams.Api do
response.body
end

@doc """
Delete a resource (see webex api documentation)

Example `delete("/messages/1")`
"""
def delete(path) do
ratelimit()
url = generate_url(path)
headers = generate_headers()
options = []
response = HTTPoison.delete!(url, headers, options)
response.body
end

### Internal
defp ratelimit() do
case ExRated.check_rate(@bucket, @scale, @limit) do
Expand Down