RedditBot
A minimalistic reddit API library.
Features:
- automatic access token refreshing
- no wrapper around any specific API
- extremely small (100 loc)
Installation
Add the following dep in your mix.exs
file:
def deps do
[
{:reddit_bot, "~> 0.1.0"}
]
end
Usage
You need to set the following configuration in your config/config.exs
import Config
config :reddit_bot,
username: System.fetch_env!("REDDIT_USERNAME"),
password: System.fetch_env!("REDDIT_PASSWORD"),
client_id: System.fetch_env!("REDDIT_CLIENT_ID"),
client_secret: System.get_env("REDDIT_CLIENT_SECRET"),
user_agent: "reddit_bot/1.0"
Then you need to add the client to your supervisor tree:
defmodule YourApplication do
use Application
def start(_type, _args) do
children = [
ArchiverBot.Reddit
]
opts = [strategy: :one_for_one, name: YourApplication.Supervisor]
Supervisor.start_link(children, opts)
end
end
Now you can call RedditBot.request
to request any reddit API!
iex> RedditBot.request(:get, "api/v1/me")
%{
"has_subscribed_to_premium" => false,
"can_create_subreddit" => true,
"has_verified_email" => true,
"has_android_subscription" => false,
"pref_clickgadget" => 5,
"has_mod_mail" => false,
"pref_no_profanity" => true,
"is_suspended" => false,
...
}
License
MIT License
Copyright (c) 2019 shouya
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.