Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds the search code API #32

Merged
merged 4 commits into from
Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/tentacat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ defmodule Tentacat do
end

def get(path, client, params \\ []) do
url = url(client, path)
url = <<url :: binary, build_qs(params) :: binary>>
initial_url = url(client, path)
url = add_params_to_url(initial_url, params)
_request(:get, url, client.auth)
end

Expand All @@ -79,6 +79,10 @@ defmodule Tentacat do
endpoint <> path
end

defp add_params_to_url(url, params) do
<<url :: binary, build_qs(params) :: binary>>
end

@spec build_qs([{atom, binary}]) :: binary
defp build_qs([]), do: ""
defp build_qs(kvs), do: to_string('?' ++ URI.encode_query(kvs))
Expand Down
22 changes: 22 additions & 0 deletions lib/tentacat/search.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Tentacat.Search do
import Tentacat
alias Tentacat.Client
@moduledoc """
The Search API allows the search of pretty much anything on GitHub
"""

@doc """
Search in code files

## Example

Tentacat.Search.code %{q: "code language:elixir repo:edgurgel/tentacat", sort: "url"}
Tentacat.Search.code %{q: "code language:elixir repo:edgurgel/tentacat", sort: "url"}, client

More info at: https://developer.github.com/v3/search/#search-code
"""
# @spec list(binary, Client.t) :: Tentacat.response
def code(params, client \\ %Client{}) do
get "search/code", client, params
end
end