Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add options to Search #106

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/tentacat/search.ex
Expand Up @@ -11,13 +11,13 @@ defmodule Tentacat.Search do
## 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
Tentacat.Search.code %{q: "code language:elixir repo:edgurgel/tentacat", sort: "url"}, client, [pagination: :none]

More info at: https://developer.github.com/v3/search/#search-code
"""
@spec code(map, Client.t) :: Tentacat.response
def code(params, client \\ %Client{}) do
get "search/code", client, params
@spec code(map, Client.t, [atom]) :: Tentacat.response
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case Keyword instead of [atom] seems more accurate. Sorry for the super late reply

def code(params, client \\ %Client{}, options \\ []) do
get "search/code", client, params, options
end

@doc """
Expand All @@ -26,13 +26,13 @@ defmodule Tentacat.Search do
## Example

Tentacat.Search.users %{q: "users language:elixir", sort: "followers"}
Tentacat.Search.users %{q: "users language:elixir", sort: "followers"}, client
Tentacat.Search.users %{q: "users language:elixir", sort: "followers"}, client, [pagination: :none]

More info at: https://developer.github.com/v3/search/#search-users
"""
@spec users(map, Client.t) :: Tentacat.response
def users(params, client \\ %Client{}) do
get "search/users", client, params
@spec users(map, Client.t, [atom]) :: Tentacat.response
def users(params, client \\ %Client{}, options \\ []) do
get "search/users", client, params, options
end

@doc """
Expand All @@ -42,11 +42,12 @@ defmodule Tentacat.Search do

Tentacat.Search.repositories %{q: "elixir-lang language:elixir", sort: "stars"}
Tentacat.Search.repositories %{q: "elixir-lang language:elixir", sort: "stars"}, client
Tentacat.Search.repositories %{q: "elixir-lang language:elixir", sort: "stars"}, client, [pagination: :none]

More info at: https://developer.github.com/v3/search/#search-repositories
"""
@spec repositories(map, Client.t) :: Tentacat.response
def repositories(params, client \\ %Client{}) do
get "search/repositories", client, params
@spec repositories(map, Client.t, [atom]) :: Tentacat.response
def repositories(params, client \\ %Client{}, options \\ [] ) do
get "search/repositories", client, params, options
end
end
11 changes: 6 additions & 5 deletions test/search_test.exs
Expand Up @@ -7,6 +7,7 @@ defmodule Tentacat.SearchTest do
doctest Tentacat.Search

@client Tentacat.Client.new
@options [pagination: :none]

setup_all do
HTTPoison.start
Expand All @@ -15,21 +16,21 @@ defmodule Tentacat.SearchTest do
test "code/2" do
use_cassette "search#code" do
params = %{q: "code language:elixir repo:edgurgel/tentacat", sort: "url"}
assert %{"incomplete_results" => false, "items" => _} = code(params, @client)
assert %{"incomplete_results" => false, "items" => _} = code(params, @client, @options)
end
end

test "users/2" do
test "users/3" do
use_cassette "search#users" do
params = %{q: "elixir-lang language:elixir", sort: "followers"}
assert %{"incomplete_results" => false, "items" => _} = users(params, @client)
assert %{"incomplete_results" => false, "items" => _} = users(params, @client, @options)
end
end

test "repositories/2" do
test "repositories/3" do
use_cassette "search#repositories" do
params = %{q: "elixir-lang in:name language:elixir", sort: "stars"}
assert %{"incomplete_results" => false, "items" => _} = repositories(params, @client)
assert %{"incomplete_results" => false, "items" => _} = repositories(params, @client, @options)
end
end
end