Add more examples in the docs

master
Milton Mazzarri 2017-04-28 15:17:21 -05:00 committed by Milton Mazzarri
parent d27bc2b72e
commit 1514c96a2e
No known key found for this signature in database
GPG Key ID: CF3DE6E356E17F1E
14 changed files with 202 additions and 0 deletions

View File

@ -62,6 +62,20 @@ defmodule Hunter.Account do
* `conn` - connection credentials
## Examples
iex> conn = Hunter.new([base_url: "https://social.lou.lt", bearer_token: "123456"])
%Hunter.Client{base_url: "https://social.lou.lt", bearer_token: "123456"}
iex> Hunter.Account.verify_credentials(conn)
%Hunter.Account{acct: "milmazz",
avatar: "https://social.lou.lt/avatars/original/missing.png",
created_at: "2017-04-06T17:43:55.325Z",
display_name: "Milton Mazzarri", followers_count: 4,
following_count: 4,
header: "https://social.lou.lt/headers/original/missing.png",
id: 8039, locked: false, note: "", statuses_count: 3,
url: "https://social.lou.lt/@milmazz", username: "milmazz"}
"""
@spec verify_credentials(Hunter.Client.t) :: Hunter.Account.t
def verify_credentials(conn) do

View File

@ -52,6 +52,13 @@ defmodule Hunter.Application do
* `api_base_url` - specifies if you want to register an application on a
different instance. default: `https://mastodon.social`
## Examples
iex> Hunter.Application.create_app("hunter", "urn:ietf:wg:oauth:2.0:oob", ["read", "write", "follow"], nil, [save?: true, api_base_url: "https://example.com"])
%Hunter.Application{client_id: "1234567890",
client_secret: "1234567890",
id: 1234}
"""
@spec create_app(String.t, String.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t | no_return
def create_app(name, redirect_uri \\ "urn:ietf:wg:oauth:2.0:oob", scopes \\ ["read"], website \\ nil, options \\ []) do

View File

@ -33,6 +33,15 @@ defmodule Hunter.Card do
* `conn` - connection credentials
* `id` - status id
## Examples
iex> conn = Hunter.new([base_url: "https://social.lou.lt", bearer_token: "123456"])
%Hunter.Client{base_url: "https://social.lou.lt", bearer_token: "123456"}
iex> Hunter.Card.card_by_status(conn, 118_635)
%Hunter.Card{description: "hunter - A Elixir client for Mastodon, a GNU Social compatible micro-blogging service",
image: "https://social.lou.lt/system/preview_cards/images/000/000/378/original/34700?1491626499",
title: "milmazz/hunter", url: "https://github.com/milmazz/hunter"}
"""
@spec card_by_status(Hunter.Client.t, non_neg_integer) :: Hunter.Card.t
def card_by_status(conn, id) do

View File

@ -32,6 +32,15 @@ defmodule Hunter.Instance do
* `conn` - connection credentials
## Examples
iex> conn = Hunter.new([base_url: "https://social.lou.lt", bearer_token: "123456"])
%Hunter.Client{base_url: "https://social.lou.lt", bearer_token: "123456"}
iex> Hunter.Instance.instance_info(conn)
%Hunter.Instance{description: "Mostly French instance - <a href=\\"/about/more#rules\\">Read full description</a> for rules.",
email: "maxime+mastodon@melinon.fr", title: "Loultstodon",
uri: "social.lou.lt"}
"""
@spec instance_info(Hunter.Client.t) :: Hunter.Instance.t
def instance_info(conn) do

View File

@ -34,6 +34,11 @@ defmodule Hunter.Notification do
* `conn` - connection credentials
## Examples
Hunter.Notification.notifications(conn)
#=> [%Hunter.Notification{account: %{"acct" => "paperswelove@mstdn.io", ...}]
"""
@spec notifications(Hunter.Client.t) :: [Hunter.Notification.t]
def notifications(conn) do
@ -48,6 +53,11 @@ defmodule Hunter.Notification do
* `conn` - connection credentials
* `id` - notification identifier
## Examples
Hunter.Notification.notification(conn, 17_476)
#=> %Hunter.Notification{account: %{"acct" => "paperswelove@mstdn.io", ...}
"""
@spec notification(Hunter.Client.t, non_neg_integer) :: Hunter.Notification.t
def notification(conn, id) do

5
test/fixtures/create_app.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"client_id": "1234567890",
"client_secret": "1234567890",
"id": 1234
}

60
test/fixtures/home_timeline.json vendored Normal file
View File

@ -0,0 +1,60 @@
[
{
"visibility": "public",
"url": "https://mstdn.io/users/paperswelove/updates/9954",
"uri": "tag:mstdn.io,2017-04-10:objectId=171105:objectType=Status",
"tags": [
{
"url": "https://social.lou.lt/tags/paperswelove",
"name": "paperswelove"
},
{
"url": "https://social.lou.lt/tags/compsci",
"name": "compsci"
},
{
"url": "https://social.lou.lt/tags/garbagecollection",
"name": "garbagecollection"
}
],
"spoiler_text": "",
"sensitive": false,
"reblogs_count": 0,
"reblogged": null,
"reblog": null,
"mentions": [],
"media_attachments": [
{
"url": "https://social.lou.lt/system/media_attachments/files/000/010/284/original/b0432b95264e141c.png?1491824449",
"type": "image",
"text_url": null,
"remote_url": "https://mstdn.io/system/media_attachments/files/000/009/562/original/b0432b95264e141c.png",
"preview_url": "https://social.lou.lt/system/media_attachments/files/000/010/284/small/b0432b95264e141c.png?1491824449",
"id": 10284
}
],
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"id": 186397,
"favourites_count": 0,
"favourited": null,
"created_at": "2017-04-10T11:40:45.000Z",
"content": "<p>One Pass Real-Time Generational Mark-Sweep Garbage Collection - Armstrong, Virding</p><p>Link: <a href=\"http://buff.ly/2pdh7iS\" rel=\"nofollow noopener\"><span class=\"invisible\">http://</span><span class=\"\">buff.ly/2pdh7iS</span><span class=\"invisible\"></span></a> </p><p>In this paper we present a simple scheme for reclaiming data for such language classes with a single pass mark-sweep collector. We also show how the simple scheme can be modified so that the collection can be done in an incremental manner (making it suitable for real-time collection).</p><p><a href=\"https://mstdn.io/tags/garbagecollection\" class=\"mention hashtag\">#<span>garbagecollection</span></a> <a href=\"https://mstdn.io/tags/compsci\" class=\"mention hashtag\">#<span>compsci</span></a> <a href=\"https://mstdn.io/tags/paperswelove\" class=\"mention hashtag\">#<span>paperswelove</span></a></p><p> <a href=\"https://mstdn.io/media/u03CNEJZho1pvTR3q6Y\" rel=\"nofollow noopener noopener\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">mstdn.io/media/u03CNEJZho1pvTR</span><span class=\"invisible\">3q6Y</span></a></p>",
"application": null,
"account": {
"username": "paperswelove",
"url": "https://mstdn.io/@paperswelove",
"statuses_count": 8,
"note": "Building Bridges Between Academia and Industry\n\n<a href=\"http://paperswelove.org\" rel=\"nofollow noopener\"><span class=\"invisible\">http://</span><span class=\"\">paperswelove.org</span><span class=\"invisible\"></span></a>\n<a href=\"http://pwlconf.org\" rel=\"nofollow noopener noopener\"><span class=\"invisible\">http://</span><span class=\"\">pwlconf.org</span><span class=\"invisible\"></span></a>",
"locked": false,
"id": 7126,
"header": "https://social.lou.lt/system/accounts/headers/000/007/126/original/missing.png?1491486258",
"following_count": 1,
"followers_count": 1,
"display_name": "Papers We Love",
"created_at": "2017-04-06T13:44:18.281Z",
"avatar": "https://social.lou.lt/system/accounts/avatars/000/007/126/original/60ecc8225809c008.png?1491486258",
"acct": "paperswelove@mstdn.io"
}
}
]

60
test/fixtures/public_timeline.json vendored Normal file
View File

@ -0,0 +1,60 @@
[
{
"visibility": "public",
"url": "https://mstdn.io/users/paperswelove/updates/9954",
"uri": "tag:mstdn.io,2017-04-10:objectId=171105:objectType=Status",
"tags": [
{
"url": "https://social.lou.lt/tags/paperswelove",
"name": "paperswelove"
},
{
"url": "https://social.lou.lt/tags/compsci",
"name": "compsci"
},
{
"url": "https://social.lou.lt/tags/garbagecollection",
"name": "garbagecollection"
}
],
"spoiler_text": "",
"sensitive": false,
"reblogs_count": 0,
"reblogged": null,
"reblog": null,
"mentions": [],
"media_attachments": [
{
"url": "https://social.lou.lt/system/media_attachments/files/000/010/284/original/b0432b95264e141c.png?1491824449",
"type": "image",
"text_url": null,
"remote_url": "https://mstdn.io/system/media_attachments/files/000/009/562/original/b0432b95264e141c.png",
"preview_url": "https://social.lou.lt/system/media_attachments/files/000/010/284/small/b0432b95264e141c.png?1491824449",
"id": 10284
}
],
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"id": 186397,
"favourites_count": 0,
"favourited": null,
"created_at": "2017-04-10T11:40:45.000Z",
"content": "<p>One Pass Real-Time Generational Mark-Sweep Garbage Collection - Armstrong, Virding</p><p>Link: <a href=\"http://buff.ly/2pdh7iS\" rel=\"nofollow noopener\"><span class=\"invisible\">http://</span><span class=\"\">buff.ly/2pdh7iS</span><span class=\"invisible\"></span></a> </p><p>In this paper we present a simple scheme for reclaiming data for such language classes with a single pass mark-sweep collector. We also show how the simple scheme can be modified so that the collection can be done in an incremental manner (making it suitable for real-time collection).</p><p><a href=\"https://mstdn.io/tags/garbagecollection\" class=\"mention hashtag\">#<span>garbagecollection</span></a> <a href=\"https://mstdn.io/tags/compsci\" class=\"mention hashtag\">#<span>compsci</span></a> <a href=\"https://mstdn.io/tags/paperswelove\" class=\"mention hashtag\">#<span>paperswelove</span></a></p><p> <a href=\"https://mstdn.io/media/u03CNEJZho1pvTR3q6Y\" rel=\"nofollow noopener noopener\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">mstdn.io/media/u03CNEJZho1pvTR</span><span class=\"invisible\">3q6Y</span></a></p>",
"application": null,
"account": {
"username": "paperswelove",
"url": "https://mstdn.io/@paperswelove",
"statuses_count": 8,
"note": "Building Bridges Between Academia and Industry\n\n<a href=\"http://paperswelove.org\" rel=\"nofollow noopener\"><span class=\"invisible\">http://</span><span class=\"\">paperswelove.org</span><span class=\"invisible\"></span></a>\n<a href=\"http://pwlconf.org\" rel=\"nofollow noopener noopener\"><span class=\"invisible\">http://</span><span class=\"\">pwlconf.org</span><span class=\"invisible\"></span></a>",
"locked": false,
"id": 7126,
"header": "https://social.lou.lt/system/accounts/headers/000/007/126/original/missing.png?1491486258",
"following_count": 1,
"followers_count": 1,
"display_name": "Papers We Love",
"created_at": "2017-04-06T13:44:18.281Z",
"avatar": "https://social.lou.lt/system/accounts/avatars/000/007/126/original/60ecc8225809c008.png?1491486258",
"acct": "paperswelove@mstdn.io"
}
}
]

View File

@ -1,5 +1,6 @@
defmodule Hunter.AccountTest do
use ExUnit.Case, async: true
doctest Hunter.Account
alias Hunter.Account

View File

@ -0,0 +1,4 @@
defmodule Hunter.ApplicationTest do
use ExUnit.Case, async: true
doctest Hunter.Application
end

View File

@ -1,5 +1,6 @@
defmodule Hunter.CardTest do
use ExUnit.Case, async: true
doctest Hunter.Card
alias Hunter.Card

View File

@ -1,5 +1,6 @@
defmodule Hunter.InstanceTest do
use ExUnit.Case, async: true
doctest Hunter.Instance
alias Hunter.Instance

View File

@ -1,5 +1,6 @@
defmodule Hunter.NotificationTest do
use ExUnit.Case, async: true
doctest Hunter.Notification
alias Hunter.Notification

View File

@ -0,0 +1,20 @@
defmodule Hunter.StatusTest do
use ExUnit.Case, async: true
doctest Hunter.Status
alias Hunter.Status
setup do
[conn: Hunter.Client.new([base_url: "https://example.com", bearer_token: "123456"])]
end
test "home timeline should return a collection of statuses", %{conn: conn} do
timeline = Status.home_timeline(conn, limit: 1)
assert Enum.count(timeline) == 1
end
test "public time should return a collection of statuses", %{conn: conn} do
timeline = Status.public_timeline(conn, limit: 1, local: true)
assert Enum.count(timeline) == 1
end
end