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文件中找到。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的 语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。