ex_slack v0.2.2 Slack.RpcApi View Source

Module for interfacing the Slack HTTP API.

Examples

iex()> Slack.RpcApi.get("api.test")
{:ok,
 %{"args" => %{"token" => "xoxb-2REDACTED588-tiUCREDACTEDx7sREDACTED"},
   "ok" => true}}

iex()> Slack.RpcApi.post("api.test", [{"some_argument", "some value"}])
{:ok, %{"args" => %{"some_argument" => "some value", "token" => "xoxb-2REDACTED588-tiUCREDACTEDx7sREDACTED"}, "ok" => true}}

iex(3)> Slack.RpcApi.post("api.test", %{"error" => "hey something went wrong"})
{:error, "hey something went wrong"}

Calling Conventions

Calling the API is simple. you need to supply an HTTP method, an API method, and a payload.

  • HTTP method - either get or post.
  • API method - see here for details.
  • Payload - see Payload below.

Payload

The payload should be constructed as either:

  • a list of {"key", "value"}
  • a string key’d map: %{“key” => “value”}

Link to this section Summary

Functions

Make and HTTP GET request. see request/3 for details

Make a HTTP POST request. see request/3 for details

Link to this section Functions

Link to this function get(rpc_method, payload \\ []) View Source

Make and HTTP GET request. see request/3 for details.

Link to this function post(rpc_method, payload) View Source

Make a HTTP POST request. see request/3 for details.

Link to this function request(method, rpc_method, payload) View Source

Make an RPC Request.

Args

  • method - either :get, or :post
  • rpc_method - One of the many Slack RPC methods. see here for details.
  • payload - A map of the payload to be delivered.

Examples

iex()> Slack.RpcApi.request(:get, "api.test", [])
{:ok, %{"args" => %{"token" => "xoxb-2REDACTED588-tiUCREDACTEDx7sREDACTED"},
  "ok" => true}}}

iex()> slack.RpcApi.request(:post, "api.test", [{"error", "uh oh"}])
{:error, "uh oh"}