GitHub API的简单Elixir封装。
Tentacool + Cat = Tentacat
文档可以在这里找到
首先,将Tentacat添加到你的mix.exs
依赖中:
def deps do [ {:tentacat, "~> 2.0"} ] end
获取依赖并在elixir控制台中运行:
mix deps.get iex -S mix
你会看到类似这样的内容:
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] Interactive Elixir (0.13.3) - press Ctrl+C to exit (type h() ENTER for help) iex(1)>
现在你可以运行示例了!
每个对GitHub的调用都需要一个客户端,但如果你想使用未经身份验证的请求,我们会为你提供一个未经身份验证的客户端。请记住,GitHub对经过身份验证和未经身份验证的请求有不同的速率限制。
使用客户端 获取用户信息:
iex> client = Tentacat.Client.new %Tentacat.Client{auth: nil, endpoint: "https://api.github.com/"} iex> Tentacat.Users.find client, "edgurgel" {200, %{"avatar_url" => "https://avatars0.githubusercontent.com/u/30873?v=4", "bio" => "无法得出有意义的结论的数据不足", "blog" => "http://gurgel.me", "company" => nil, "created_at" => "2008-10-24T17:05:04Z", "email" => nil, "events_url" => "https://api.github.com/users/edgurgel/events{/privacy}", "followers" => 220, "followers_url" => "https://api.github.com/users/edgurgel/followers", "following" => 75, "following_url" => "https://api.github.com/users/edgurgel/following{/other_user}", "gists_url" => "https://api.github.com/users/edgurgel/gists{/gist_id}", "gravatar_id" => "", "hireable" => nil, "html_url" => "https://github.com/edgurgel", "id" => 30873, "location" => "惠灵顿, 新西兰", "login" => "edgurgel", "name" => "Eduardo Gurgel", "organizations_url" => "https://api.github.com/users/edgurgel/orgs", "public_gists" => 13, "public_repos" => 59, "received_events_url" => "https://api.github.com/users/edgurgel/received_events", "repos_url" => "https://api.github.com/users/edgurgel/repos", "site_admin" => false, "starred_url" => "https://api.github.com/users/edgurgel/starred{/owner}{/repo}", "subscriptions_url" => "https://api.github.com/users/edgurgel/subscriptions", "type" => "User", "updated_at" => "2018-02-05T23:24:42Z", "url" => "https://api.github.com/users/edgurgel"}, %HTTPoison.Response{body: %{"avatar_url" => "https://avatars0.githubusercontent.com/u/30873?v=4", "bio" => "无法得出有意义的结论的数据不足", "blog" => "http://gurgel.me", "company" => nil, "created_at" => "2008-10-24T17:05:04Z", "email" => nil, "events_url" => "https://api.github.com/users/edgurgel/events{/privacy}", "followers" => 220, "followers_url" => "https://api.github.com/users/edgurgel/followers", "following" => 75, "following_url" => "https://api.github.com/users/edgurgel/following{/other_user}", "gists_url" => "https://api.github.com/users/edgurgel/gists{/gist_id}", "gravatar_id" => "", "hireable" => nil, "html_url" => "https://github.com/edgurgel", "id" => 30873, "location" => "惠灵顿, 新西兰", "login" => "edgurgel", "name" => "Eduardo Gurgel", "organizations_url" => "https://api.github.com/users/edgurgel/orgs", "public_gists" => 13, "public_repos" => 59, "received_events_url" => "https://api.github.com/users/edgurgel/received_events", "repos_url" => "https://api.github.com/users/edgurgel/repos", "site_admin" => false, "starred_url" => "https://api.github.com/users/edgurgel/starred{/owner}{/repo}", "subscriptions_url" => "https://api.github.com/users/edgurgel/subscriptions", "type" => "User", "updated_at" => "2018-02-05T23:24:42Z", "url" => "https://api.github.com/users/edgurgel"}, headers: [{"Date", "Mon, 05 Feb 2018 23:25:36 GMT"}, {"Content-Type", "application/json; charset=utf-8"}, {"Content-Length", "1187"}, {"Server", "GitHub.com"}, {"Status", "200 OK"}, {"X-RateLimit-Limit", "60"}, {"X-RateLimit-Remaining", "59"}, {"X-RateLimit-Reset", "1517876736"}, {"Cache-Control", "public, max-age=60, s-maxage=60"}, {"Vary", "Accept"}, {"ETag", "\"ec2653a252e614a96afacfaeb88d0c39\""}, {"Last-Modified", "Mon, 05 Feb 2018 23:24:42 GMT"}, {"X-GitHub-Media-Type", "github.v3; format=json"}, {"Access-Control-Expose-Headers", "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"}, {"Access-Control-Allow-Origin", "*"}, {"Content-Security-Policy", "default-src 'none'"}, {"Strict-Transport-Security", "max-age=31536000; includeSubdomains; preload"}, {"X-Content-Type-Options", "nosniff"}, {"X-Frame-Options", "deny"}, {"X-XSS-Protection", "1; mode=block"}, {"X-Runtime-rack", "0.030182"}, {"Vary", "Accept-Encoding"}, {"X-GitHub-Request-Id", "054D:2BC4A:82C2C:A4560:5A78E7EF"}], request_url: "https://api.github.com/users/edgurgel", status_code: 200}}
不使用定义的客户端获取用户信息:
iex> {200, data, _response} = Tentacat.Users.find("edgurgel") iex> get_in(data, ["name"]) "Eduardo Gurgel"
获取已认证用户的信息:
iex> client = Tentacat.Client.new(%{user: "user", password: "password"}) %Tentacat.Client{auth: %{user: "user", password: "password"}, endpoint: "https://api.github.com/"} iex> Tentacat.Users.me(client)
iex> client = Tentacat.Client.new(%{access_token: "928392873982932"}) %Tentacat.Client{auth: %{access_token: "928392873982932"}, endpoint: "https://api.github.com/"} iex> Tentacat.Users.me(client)
访问其他端点:
iex> client = Tentacat.Client.new(%{access_token: "928392873982932"}, "https://ghe.example.com/api/v3/") %Tentacat.Client{auth: %{access_token: "928392873982932"}, endpoint: "https://ghe.example.com/api/v3/"} iex> Tentacat.Users.me(client)
由于Github Reviews API仍处于预发布状态, 您需要在配置中设置一个额外的头部。
config :tentacat, :extra_headers, [{"Accept", "application/vnd.github.black-cat-preview+json"}]
您可以通过以下方式向用于解码JSON的库传递反序列化选项:
# 使用原子键 config :tentacat, :deserialization_options, [keys: :atoms]
请参阅: https://hexdocs.pm/jason/Jason.html#decode/2-options 了解可用选项。
首先fork这个仓库。
然后运行以下命令获取依赖并运行测试:
MIX_ENV=test mix do deps.get, test
如果你正在使用Intellij并调试测试套件,请确保在Elixir Mix Eunit配置中设置'INTELLIJ_ELIXIR_DEBUG_BLACKLIST=hackney'
。如果你没有这样做,模拟的hackney模块将从磁盘重新加载,测试将会表现异常。
非常感谢您提交拉取请求。
版权所有 (c) 2013 Eduardo Gurgel Pinho
根据MIT许可证发布,可以在仓库中的LICENSE.md文件中找到。
最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。
像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。
AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作