Skip to content

Commit

Permalink
Some comments, docs, make ready to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeb committed May 13, 2018
1 parent 1b24a13 commit 287289e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2018 Boris Kotov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 24 additions & 2 deletions lib/thumbox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@ defmodule Thumbox do
@moduledoc """
Documentation for Thumbox.
configure
## Config
```
config :thumbox,
server: "https://thumbor.example.com",
# or just 'app' if thumbor can access it in the network
origin: "my-app.com:4000",
secret: "secret",
types: %{
big: "300x300/smart",
small: "50x50/smart"
}
```
"""
@doc ~S"""
Generates an URL to the thumbor service
Example
```
iex> Thumbox.gen_url(:small, "uploads/image.jpg", server: "http://thumbor:8000", origin: "app.com", secret: "secret", types: %{ small: "100x100" })
"http://thumbor:8000/-fACxLAC_MbZ_JHxm0-tLYrHM2Y=/100x100/app.com/uploads/image.jpg"
```
"""
def gen_url(type, path, opts \\ []) do
{server, origin, secret, types} = get_config(opts)
resource = "#{types[type]}/#{origin}/#{path}"
Expand All @@ -15,7 +37,7 @@ defmodule Thumbox do

@doc """
Signs a string like its done by thumbor
See: http://thumbor.readthedocs.io/en/latest/libraries.html#library-tests-scenarios
see: http://thumbor.readthedocs.io/en/latest/libraries.html#library-tests-scenarios
"""
def sign(key, str) do
:crypto.hmac(:sha, key, str)
Expand Down
15 changes: 14 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ defmodule Thumbox.MixProject do
start_permanent: Mix.env() == :prod,
deps: deps(),
name: "Thumbox",
description: "Thumbor URL generator helper for elixir",
source_url: "https://github.com/webdeb/thumbox",
# The main page in the docs
package: package(),
docs: [main: "Thumbox", extras: ["README.md"]]
]
end

defp package() do
[
# This option is only needed when you don't want to use the OTP application name
name: "thumbox",
# These are the default files included in the package
files: ["lib", "mix.exs", "README*", "LICENSE"],
maintainers: ["Boris Kotov"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/webdeb/thumbox"}
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
Expand Down
1 change: 1 addition & 0 deletions test/thumbox_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ThumboxTest do
use ExUnit.Case, async: true
doctest Thumbox
use ExUnitProperties

property "compare generation of thumbor and thumbox hmac of a simple string" do
Expand Down

0 comments on commit 287289e

Please sign in to comment.