medium v0.2.0 Medium
Medium is an Elixir library that provides an interface to interact with the Medium API.
Installation
Add Medium to your list of dependencies in
mix.exs
:def deps do [{:medium_client, "~> 0.2.0"}] end
Ensure Medium is started before your application:
def application do [applications: [:medium_client]] end
Authorship and License
Medium is copyright 2016 Roberto Dip (http://roperzh.com) Medium is released under the [MIT License] (https://github.com/roperzh/medium-sdk-elixir/blob/master/LICENSE).
Summary
Functions
Generate an authorization URL
Generate a client which will use a defined token
for future requests
Returns a list of contributors for a given publication
Request for a token
Returns details of the user who has granted permission to the application
Returns a full list of publications that the user is related to in some way
Creates a post on the authenticated user’s profile
This API allows creating a post and associating it with a publication on Medium
Perform a request. See request/2
for available options
Perform a request using client function
Types
option :: {:method, Tesla.Env.method} | {:url, Tesla.Env.url} | {:query, Tesla.Env.query} | {:headers, Tesla.Env.headers} | {:body, Tesla.Env.body} | {:opts, Tesla.Env.opts}
Functions
Generate an authorization URL
Parameters for the url must be provided as a map, with the following required keys:
client_id
, Stringscope
, List of String elementsstate
, Stringresponse_type
, Stringredirect_uri
, String
For more details, please check the official [documentation] (https://github.com/Medium/medium-api-docs#21-browser-based-authentication)
Generate a client which will use a defined token
for future requests
Optionally the client accepts a custom base url to be used for all request this can be useful for future api versions and testing.
Examples
client = Medium.client("my-access-token")
test_client = Medium.client("my-acces-token", "http://localhost")
Returns a list of contributors for a given publication.
Please check the official [documentation] (https://github.com/Medium/medium-api-docs#listing-the-users-publications)
Examples
contributors =
token
|> Medium.client
|> Medium.publications("publication_id")
Perform a DELETE request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.delete("/users")
delete(Tesla.Env.client, Tesla.Env.url) :: Tesla.Env.t
delete(Tesla.Env.url, [option]) :: Tesla.Env.t
Perform a DELETE request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.delete("/users")
iex> ExampleApi.delete("/users", query: [page: 1])
Perform a DELETE request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.delete("/users", query: [page: 1])
Perform a GET request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.get("/users")
get(Tesla.Env.client, Tesla.Env.url) :: Tesla.Env.t
get(Tesla.Env.url, [option]) :: Tesla.Env.t
Perform a GET request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.get("/users")
iex> ExampleApi.get("/users", query: [page: 1])
Perform a GET request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.get("/users", query: [page: 1])
Request for a token
Parameters for the url must be provided as a map, with the following required keys:
code
, String generated with the url provided viaauthorize_url/1
client_id
, Stringclient_secret
, Stringgrant_type
, Stringredirect_uri
, String
For more details, please check the official [documentation] (https://github.com/Medium/medium-api-docs#21-browser-based-authentication)
Perform a HEAD request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.head("/users")
head(Tesla.Env.client, Tesla.Env.url) :: Tesla.Env.t
head(Tesla.Env.url, [option]) :: Tesla.Env.t
Perform a HEAD request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.head("/users")
iex> ExampleApi.head("/users", query: [page: 1])
Perform a HEAD request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.head("/users", query: [page: 1])
Returns details of the user who has granted permission to the application.
Please check the official documentation
Examples
user_info = Medium.client("token") |> Medium.me
user_info.username //=> "roperzh"
user_info.image_url //=> "https://images.medium.com/0*fkfQT7TlUGGyI.png"
Perform a OPTIONS request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.options("/users")
options(Tesla.Env.client, Tesla.Env.url) :: Tesla.Env.t
options(Tesla.Env.url, [option]) :: Tesla.Env.t
Perform a OPTIONS request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.options("/users")
iex> ExampleApi.options("/users", query: [page: 1])
Perform a OPTIONS request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.options("/users", query: [page: 1])
Perform a PATCH request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.patch("/users", %{name: "Jon"})
patch(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body) :: Tesla.Env.t
patch(Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a PATCH request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.patch("/users", %{name: "Jon"})
iex> ExampleApi.patch("/users", %{name: "Jon"}, query: [scope: "admin"])
patch(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a PATCH request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.patch("/users", %{name: "Jon"}, query: [scope: "admin"])
Perform a POST request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.post("/users", %{name: "Jon"})
post(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body) :: Tesla.Env.t
post(Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a POST request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.post("/users", %{name: "Jon"})
iex> ExampleApi.post("/users", %{name: "Jon"}, query: [scope: "admin"])
post(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a POST request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.post("/users", %{name: "Jon"}, query: [scope: "admin"])
Returns a full list of publications that the user is related to in some way.
Please check the official [documentation] (https://github.com/Medium/medium-api-docs#listing-the-users-publications)
Examples
publications = Medium.client("token") |> Medium.publications("user_id")
Creates a post on the authenticated user’s profile.
Please check the official documentation
Examples
resp = Medium.client("token") |> Medium.publish("user_id", publication)
This API allows creating a post and associating it with a publication on Medium.
Please check the official [documentation] (http://github.com/Medium/medium-api-docs#creating-a-post-under-a-publication)
Examples
resp =
token
|> Medium.client
|> Medium.publish_comment("publication_id", publication_data)
Perform a PUT request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.put("/users", %{name: "Jon"})
put(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body) :: Tesla.Env.t
put(Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a PUT request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.put("/users", %{name: "Jon"})
iex> ExampleApi.put("/users", %{name: "Jon"}, query: [scope: "admin"])
put(Tesla.Env.client, Tesla.Env.url, Tesla.Env.body, [option]) :: Tesla.Env.t
Perform a PUT request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.put("/users", %{name: "Jon"}, query: [scope: "admin"])
Perform a request. See request/2
for available options.
Perform a request using client function
Options:
:method
- the request method, one of [:head, :get, :delete, :trace, :options, :post, :put, :patch]:url
- either full url e.g. “http://example.com/some/path” or just “/some/path” if usingTesla.Middleware.BaseUrl
:query
- a keyword list of query params, e.g.[page: 1, per_page: 100]
:headers
- a keyworld list of headers, e.g.[{"content-type", "text/plain"}]
:body
- depends on used middleware:- by default it can be a binary
- if using e.g. JSON encoding middleware it can be a nested map
- if adapter supports it it can be a Stream with any of the above
:opts
- custom, per-request middleware or adapter options
Examples:
iex> ExampleApi.request(method: :get, url: "/users/path")
You can also use shortcut methods like:
iex> ExampleApi.get("/users/1")
or
iex> myclient |> ExampleApi.post("/users", %{name: "Jon"})
Perform a TRACE request.
See request/1
or request/2
for options definition.
Example
iex> ExampleApi.trace("/users")
trace(Tesla.Env.client, Tesla.Env.url) :: Tesla.Env.t
trace(Tesla.Env.url, [option]) :: Tesla.Env.t
Perform a TRACE request.
See request/1
or request/2
for options definition.
Example
iex> myclient |> ExampleApi.trace("/users")
iex> ExampleApi.trace("/users", query: [page: 1])