kanoko 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e42bf64558cec67348c3f8b2793079179c5012c1
4
- data.tar.gz: 6148e4976c50a71236ffe7c1ab8b5b2860f438e1
3
+ metadata.gz: 174aaa5dc844a02ce0fe1bc7d99aabddffbc8db5
4
+ data.tar.gz: b78fe145753b4104900984eccc76d7259da3922e
5
5
  SHA512:
6
- metadata.gz: 3246a4f831cb4355b0f200e52ef608f5c04a79228a7498c225fbb66efb1aed28dac8a74d5de6fe7ba13bb305848935cfe79c94c4637f8cff994223af2d77d25d
7
- data.tar.gz: ab2dc0dc148d7a1637b5d6d3ca581b067f68c98778c466d2bb94148a99e7290ae2167ae10e3116887a44d3b0a0db8502a77120ec3daac46bf18dd24b9b1661b2
6
+ metadata.gz: 3d980fb390493a82e79718a41054486272b9e0390bf6a963e877c4fbe92aada2fd197d3f74045cd80d5a6352383f94109db67d328c53a8f15f49ffdc5dbbbdc8
7
+ data.tar.gz: ae4bc45b643ae3f19233377b242c497bfa7bd27366f2fcb2ecf3b4319809a20ff24aa21605336271404b2f1b399ef1bfb468a0748258e9b5b720ac4b2800489d
data/README.md CHANGED
@@ -2,3 +2,52 @@ kanoko
2
2
  ===
3
3
 
4
4
  [![Build Status](https://travis-ci.org/spice-life/kanoko.svg?branch=master)](https://travis-ci.org/spice-life/kanoko)
5
+
6
+ **kanoko** is an active image generate application.
7
+
8
+ # Quick Start
9
+
10
+ ```
11
+ require 'kanoko/application/convert'
12
+
13
+ class MyApp < Kanoko::Application::Convert
14
+ end
15
+
16
+ run MyApp
17
+ ```
18
+
19
+ ```
20
+ $ KANOKO_DIGEST_FUNC=sha1 KANOKO_SECRET_KEY=devkey unicorn --config-file config/unicorn/development.rb
21
+ ```
22
+
23
+ # Arguments
24
+
25
+ **http://{{kanoko.host}}/:hash/:func/:args/:path**
26
+
27
+ - **hash:** params signature (see also **Signature**)
28
+ - **func:** a function name of image processing (e.g. fit)
29
+ - **args:** image processing arguments (e.g. "100x100")
30
+ - **path:** Target image path without scheme (e.g. "host/path/to/image?params\_a=value\_a")
31
+
32
+ # Signature
33
+
34
+ **hash** is changeable.
35
+
36
+ By default, see `Kanoko::Configure#initialize`.
37
+
38
+ On application, It must be set **hash** same way as this.
39
+
40
+ If hash not match, application should be return *400 Bad Request*.
41
+
42
+ This function behavior can change by Kanoko.configure.
43
+
44
+ ```ruby
45
+ Kanoko.configure.hash_proc = ->{
46
+ "some_hash_value_on_url"
47
+ }
48
+ ```
49
+
50
+ # TODO
51
+
52
+ - To be able to change digest_func and secret_key on graceful restart
53
+ - More fast
@@ -3,7 +3,7 @@ require 'kanoko/configure'
3
3
 
4
4
  module Kanoko
5
5
  # example:
6
- # Kanoko.configure.kanoko_host = "http://example.com"
6
+ # Kanoko.configure.digest_func = "sha1"
7
7
  # p Kanoko.configure #=> #<Kanoko::Configure ...>
8
8
  def configure
9
9
  @configure ||= Configure.new
@@ -19,24 +19,14 @@ module Kanoko
19
19
  @configure = value
20
20
  end
21
21
 
22
- def url_for(func, args, src)
23
- if configure.kanoko_host.nil?
24
- fail ConfigureError, "`kanoko_host' must be set"
25
- end
26
- "#{configure.kanoko_host}#{make_path(func, args, src)}"
22
+ def path_for(func, args, src)
23
+ hash = make_hash(func, args, src)
24
+ "/#{hash}/#{[func, args].map{|i| URI.encode_www_form_component(i)}.join('/')}/#{src}"
27
25
  end
28
- module_function :url_for
26
+ module_function :path_for
29
27
 
30
28
  def make_hash(*args)
31
29
  configure.hash_proc.call(*args)
32
30
  end
33
31
  module_function :make_hash
34
-
35
- private
36
-
37
- def make_path(func, args, src)
38
- hash = make_hash(func, args, src)
39
- "/#{hash}/#{[func, args].map{|i| URI.encode_www_form_component(i)}.join('/')}/#{src}"
40
- end
41
- module_function :make_path
42
32
  end
@@ -3,7 +3,7 @@ require 'net/http'
3
3
  require 'tempfile'
4
4
  require 'kanoko'
5
5
 
6
- # This is a experimental implementation.
6
+ # This is an experimental implementation.
7
7
  # You can set configure and other.
8
8
  # This application receve url make by Kanoko.url_for().
9
9
  # You can choice function that image processing.
@@ -6,20 +6,17 @@ module Kanoko
6
6
  class Configure
7
7
  attr_accessor :digest_func, :secret_key, :hash_proc
8
8
 
9
- # kanoko_host expect String
10
9
  # digest_func expect String
11
10
  # secret_key expect String
12
11
  # hash_proc expect Proc
13
12
  #
14
13
  # example:
15
14
  # Kanoko.configure do |c|
16
- # c.kanoko_host = "http://example.com"
17
15
  # c.digest_func = "sha1"
18
16
  # c.secret_key = "secret"
19
17
  # end
20
- # Kanoko.url_for(:resize, "100x100") #=> "http://example.com/.../.../..."
18
+ # Kanoko.path_for(:resize, "100x100") #=> "/hashing_value/resize/100x100"
21
19
  def initialize
22
- @kanoko_host = nil
23
20
  @digest_func = ENV['KANOKO_DIGEST_FUNC']
24
21
  @secret_key = ENV['KANOKO_SECRET_KEY']
25
22
  @hash_proc = ->(*args){
@@ -33,28 +30,5 @@ module Kanoko
33
30
  )
34
31
  }
35
32
  end
36
-
37
- def kanoko_host=(host)
38
- @kanoko_host = normalize_url(host)
39
- end
40
-
41
- def kanoko_host
42
- @kanoko_host
43
- end
44
-
45
- private
46
-
47
- def normalize_url(host)
48
- case host
49
- when %r{\Ahttps?://}
50
- host
51
- when %r{\A[^/]}
52
- "http://#{host}"
53
- when %r{\A//}
54
- "http:#{host}"
55
- else
56
- fail ConfigureError, "invalid kanoko_host `#{host}'"
57
- end
58
- end
59
33
  end
60
34
  end
@@ -1,3 +1,3 @@
1
1
  module Kanoko
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -6,19 +6,6 @@ class TestKanokoConfigure < Minitest::Test
6
6
  @config = Kanoko::Configure.new
7
7
  end
8
8
 
9
- def test_kanoko_host
10
- assert_raises(Kanoko::ConfigureError) { @config.kanoko_host = "/example.com" }
11
-
12
- @config.kanoko_host = "example.com"
13
- assert_equal "http://example.com", @config.kanoko_host
14
-
15
- @config.kanoko_host = "http://example.com"
16
- assert_equal "http://example.com", @config.kanoko_host
17
-
18
- @config.kanoko_host = "https://example.com"
19
- assert_equal "https://example.com", @config.kanoko_host
20
- end
21
-
22
9
  def test_hash_proc_by_default_error
23
10
  @config.digest_func = nil
24
11
  @config.secret_key = nil
@@ -5,7 +5,6 @@ class TestKanoko < Minitest::Test
5
5
  def setup
6
6
  Kanoko.configure.digest_func = "sha1"
7
7
  Kanoko.configure.secret_key = "test"
8
- Kanoko.configure.kanoko_host = "http://example.com"
9
8
  end
10
9
 
11
10
  def change_hash_proc(hash_proc)
@@ -25,10 +24,10 @@ class TestKanoko < Minitest::Test
25
24
  assert_equal "ok", Kanoko.configure.digest_func
26
25
  end
27
26
 
28
- def test_url_for_with_default_hash_proc
27
+ def test_path_for_with_default_hash_proc
29
28
  change_hash_proc(proc{ "aaa" }) do
30
- assert_equal "http://example.com/aaa/test_func/test_args/test_path", Kanoko.url_for(:test_func, "test_args", "test_path")
31
- assert_equal "http://example.com/aaa/test_func/%2F%3F-_%3D%21%40%23%3C%3E%5C//?-_=!@#<>\\", Kanoko.url_for(:test_func, "/?-_=!@#<>\\", "/?-_=!@#<>\\")
29
+ assert_equal "/aaa/test_func/test_args/test_path", Kanoko.path_for(:test_func, "test_args", "test_path")
30
+ assert_equal "/aaa/test_func/%2F%3F-_%3D%21%40%23%3C%3E%5C//?-_=!@#<>\\", Kanoko.path_for(:test_func, "/?-_=!@#<>\\", "/?-_=!@#<>\\")
32
31
  end
33
32
  end
34
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanoko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss