Skip to content

Commit

Permalink
more consistant API
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehoover committed Dec 13, 2015
1 parent 0afe4fc commit 3c82799
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions lib/unsplash.ex
Expand Up @@ -125,43 +125,43 @@ defmodule Unsplash do
end

@doc ~S"""
GET /photos/:id
POST /photos/:id/like
Args:
* `id` - the photo id
* `opts` - Keyword list of options
Options:
* `w` - Image width in pixels.
* `h` - Image height in pixels.
* `rect` - 4 comma-separated integers representing x, y, width, height of the cropped rectangle.
Requires the `write_likes` scope
"""
def photos(id, opts) when is_binary(id) do
params = build_params([:w, :h, :rect, :per_page, :page], opts)
ResultStream.new("/photos/#{id}?#{params}")
def photos(id, :like) when is_binary(id) do
Api.post!("/photos/#{id}/like", []).body
|> Poison.decode!
end

@doc ~S"""
POST /photos/:id/like
DELETE /photos/:id/like
Args:
* `id` - the photo id
Requires the `write_likes` scope
"""
def photos(:like, id) when is_binary(id) do
Api.post!("/photos/#{id}/like", []).body
|> Poison.decode!
def photos(id, :unlike) when is_binary(id) do
Api.delete!("/photos/#{id}/like").status_code
end

@doc ~S"""
DELETE /photos/:id/like
GET /photos/:id
Args:
* `id` - the photo id
* `opts` - Keyword list of options
Options:
* `w` - Image width in pixels.
* `h` - Image height in pixels.
* `rect` - 4 comma-separated integers representing x, y, width, height of the cropped rectangle.
"""
def photos(:unlike, id) when is_binary(id) do
Api.delete!("/photos/#{id}/like").status_code
def photos(id, opts) when is_binary(id) do
params = build_params([:w, :h, :rect, :per_page, :page], opts)
ResultStream.new("/photos/#{id}?#{params}")
end

@doc ~S"""
Expand Down
8 changes: 4 additions & 4 deletions test/unsplash_test.exs
Expand Up @@ -100,15 +100,15 @@ defmodule UnsplashTest do
end

# Like photos
test "Unsplash.photos(:like, id)" do
test "Unsplash.photos(id, :like)" do
use_cassette "like_photo" do
assert is_list Unsplash.photos(:like, "0XR2s9D3PLI") |> Enum.take(1)
assert is_list Unsplash.photos("0XR2s9D3PLI", :like) |> Enum.take(1)
end
end

test "Unsplash.photos(:unlike, id)" do
test "Unsplash.photos(id, :unlike)" do
use_cassette "unlike_photo" do
assert Unsplash.photos(:unlike, "0XR2s9D3PLI")
assert Unsplash.photos("0XR2s9D3PLI", :unlike)
end
end

Expand Down

0 comments on commit 3c82799

Please sign in to comment.