mushikago-sdk 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -2
- data/lib/mushikago/auth/signature.rb +1 -1
- data/lib/mushikago/http/client.rb +2 -2
- data/lib/mushikago/http/request.rb +3 -3
- data/lib/mushikago/tombo/capture_request.rb +3 -0
- data/lib/mushikago/version.rb +1 -1
- data/spec/mushikago/auth/signature_spec.rb +3 -3
- data/spec/mushikago/http/request_spec.rb +9 -9
- data/spec/mushikago/tombo/capture_request_spec.rb +4 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -5,8 +5,8 @@ Mushikago SDK for Ruby.
|
|
5
5
|
- **Author**: Toru Matsuoka
|
6
6
|
- **Copyright**: 2011
|
7
7
|
- **License**: Apache License, Version 2.0
|
8
|
-
- **Latest Version**: 0.2.
|
9
|
-
- **Release Date**: September
|
8
|
+
- **Latest Version**: 0.2.3
|
9
|
+
- **Release Date**: September 13th 2011
|
10
10
|
|
11
11
|
|
12
12
|
概要
|
@@ -118,6 +118,8 @@ $ export MUSHIKAGO_SECRET_KEY=<シークレットキー>
|
|
118
118
|
変更履歴
|
119
119
|
--------
|
120
120
|
|
121
|
+
- **Sep.13.11**: 0.2.3 release
|
122
|
+
- captureメソッドのuseragentに対応
|
121
123
|
- **Sep.8.11**: 0.2.1 release
|
122
124
|
- ライセンスをApache License, Version 2.0に変更
|
123
125
|
- **Sep.6.11**: 0.1.8 release
|
@@ -22,8 +22,8 @@ module Mushikago
|
|
22
22
|
# @return [Mushikago::Http::Response] response
|
23
23
|
def send_request request
|
24
24
|
# add authorization
|
25
|
-
request
|
26
|
-
request
|
25
|
+
request['api_key'] = api_key
|
26
|
+
request['timestamp'] = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
27
27
|
request.add_signature!(signer)
|
28
28
|
|
29
29
|
# send request
|
@@ -28,13 +28,13 @@ module Mushikago
|
|
28
28
|
|
29
29
|
# @param [String] key パラメータのキー
|
30
30
|
# @param [String] value パラメータの値
|
31
|
-
def
|
31
|
+
def []= key, value
|
32
32
|
params[key] = value
|
33
33
|
end
|
34
34
|
|
35
35
|
# @param [String] key パラメータのキー
|
36
36
|
# @return [String] パラメータの値
|
37
|
-
def
|
37
|
+
def [] key
|
38
38
|
param = params.detect{|p| p[0] == key}
|
39
39
|
param ? param[1] : nil
|
40
40
|
end
|
@@ -97,7 +97,7 @@ module Mushikago
|
|
97
97
|
attr_accessor name
|
98
98
|
define_method("#{name}=") do |value|
|
99
99
|
value = transform ? transform.call(value) : value
|
100
|
-
|
100
|
+
self[name.to_s] = value
|
101
101
|
instance_variable_set("@#{name}".to_sym, value)
|
102
102
|
end
|
103
103
|
end
|
@@ -9,6 +9,7 @@ module Mushikago
|
|
9
9
|
add_param :image_quality do |v| v.to_i.to_s end
|
10
10
|
add_param :thumbnail do |v| (v ? 1 : 0).to_s end
|
11
11
|
add_param :tags do |v| [v].flatten.compact.join(',') end
|
12
|
+
add_param :useragent
|
12
13
|
|
13
14
|
# @param [String] url キャプチャ対象のURL
|
14
15
|
# @param [Hash] options リクエストのオプション
|
@@ -16,6 +17,7 @@ module Mushikago
|
|
16
17
|
# @option options [Integer] :image_quality(80) 画像の品質(0-100)
|
17
18
|
# @option options [Boolean] :thumbnail(0) サムネイル取得フラグ(false:取得しない,true:取得する)
|
18
19
|
# @option options [String,Array] :tags タグ
|
20
|
+
# @option options [String] :useragent ユーザエージェント
|
19
21
|
def initialize url, options={}
|
20
22
|
super(options)
|
21
23
|
self.url = url
|
@@ -23,6 +25,7 @@ module Mushikago
|
|
23
25
|
self.image_quality = options[:image_quality] if options.has_key?(:image_quality)
|
24
26
|
self.thumbnail = options[:thumbnail] if options.has_key?(:thumbnail)
|
25
27
|
self.tags = options[:tags] if options.has_key?(:tags)
|
28
|
+
self.useragent = options[:useragent] if options.has_key?(:useragent)
|
26
29
|
@headers['Content-type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
27
30
|
end
|
28
31
|
|
data/lib/mushikago/version.rb
CHANGED
@@ -10,8 +10,8 @@ describe Mushikago::Auth::Signature do
|
|
10
10
|
@request.http_method = 'GET'
|
11
11
|
@request.host = 'mushikago.org'
|
12
12
|
@request.path = '/1/someapi.json'
|
13
|
-
@request
|
14
|
-
@request
|
13
|
+
@request['api_key'] = 'api_key'
|
14
|
+
@request['timestamp'] = '2011-09-01T00:00:00Z'
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'generates string to sign' do
|
@@ -23,7 +23,7 @@ describe Mushikago::Auth::Signature do
|
|
23
23
|
before do
|
24
24
|
@request.add_signature!(Mushikago::Auth::Signer.new('secret_key'))
|
25
25
|
end
|
26
|
-
subject{ @request
|
26
|
+
subject{ @request['signature'] }
|
27
27
|
it{ should == 'sJSFFQREYbNPd2kJK3kuAR3uSgvcbuWtxGFjan+R3w8=' }
|
28
28
|
end
|
29
29
|
end
|
@@ -12,9 +12,9 @@ describe Mushikago::Http::Request do
|
|
12
12
|
@request.host = 'tombo.ap-northeast-1.mushikago.org'
|
13
13
|
@request.path = '/1/list.json'
|
14
14
|
@request.headers['hoge'] = 'fuga'
|
15
|
-
@request
|
16
|
-
@request
|
17
|
-
@request
|
15
|
+
@request['param1'] = 'p1'
|
16
|
+
@request['param2'] = 'p2'
|
17
|
+
@request['timestamp'] = '2011-09-01T00:00:00Z'
|
18
18
|
end
|
19
19
|
|
20
20
|
subject{ @request }
|
@@ -25,8 +25,8 @@ describe Mushikago::Http::Request do
|
|
25
25
|
it{ should respond_to(:path, :path=) }
|
26
26
|
it{ should respond_to(:headers) }
|
27
27
|
it{ should respond_to(:params) }
|
28
|
-
it{ should respond_to(:
|
29
|
-
it{ should respond_to(:
|
28
|
+
it{ should respond_to(:[]=) }
|
29
|
+
it{ should respond_to(:[]) }
|
30
30
|
|
31
31
|
its(:http_method){ should == 'GET' }
|
32
32
|
its(:host){ should == 'tombo.ap-northeast-1.mushikago.org' }
|
@@ -34,11 +34,11 @@ describe Mushikago::Http::Request do
|
|
34
34
|
its(:path){ should == '/1/list.json' }
|
35
35
|
its(:headers){ should be_a_kind_of(Hash) }
|
36
36
|
it{ subject.headers['hoge'].should == 'fuga' }
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
its(['param1']){ should == 'p1' }
|
38
|
+
its(['param2']){ should == 'p2' }
|
39
|
+
its(['timestamp']){ should == '2011-09-01T00:00:00Z' }
|
40
40
|
|
41
|
-
|
41
|
+
its(:url_encoded_params){ should == 'param1=p1¶m2=p2×tamp=2011-09-01T00%3A00%3A00Z' }
|
42
42
|
|
43
43
|
context 'to http request' do
|
44
44
|
subject{ @request.to_http_request }
|
@@ -12,6 +12,7 @@ describe Mushikago::Tombo::CaptureRequest do
|
|
12
12
|
it{ should respond_to(:image_quality) }
|
13
13
|
it{ should respond_to(:thumbnail) }
|
14
14
|
it{ should respond_to(:tags) }
|
15
|
+
it{ should respond_to(:useragent) }
|
15
16
|
it{ should respond_to(:add_signature!) }
|
16
17
|
|
17
18
|
context 'with options' do
|
@@ -21,6 +22,7 @@ describe Mushikago::Tombo::CaptureRequest do
|
|
21
22
|
:image_quality => '20',
|
22
23
|
:thumbnail => true,
|
23
24
|
:tags => 'hoge,fuga',
|
25
|
+
:useragent => 'sampleua',
|
24
26
|
}
|
25
27
|
@request = Mushikago::Tombo::CaptureRequest.new('http://www.mushikago.org/', options)
|
26
28
|
end
|
@@ -34,9 +36,10 @@ describe Mushikago::Tombo::CaptureRequest do
|
|
34
36
|
its(:image_format){ should == 'png' }
|
35
37
|
its(:image_quality){ should == '20' }
|
36
38
|
its(:thumbnail){ should == '1' }
|
39
|
+
its(:useragent){ should == 'sampleua' }
|
37
40
|
its(:tags){ should == 'hoge,fuga' }
|
38
41
|
it{ subject.headers['Content-type'].should == 'application/x-www-form-urlencoded; charset=utf-8' }
|
39
|
-
its(:url_encoded_params){ should == 'image_format=png&image_quality=20&tags=hoge%2Cfuga&thumbnail=1&url=http%3A%2F%2Fwww.mushikago.org%2F' }
|
42
|
+
its(:url_encoded_params){ should == 'image_format=png&image_quality=20&tags=hoge%2Cfuga&thumbnail=1&url=http%3A%2F%2Fwww.mushikago.org%2F&useragent=sampleua' }
|
40
43
|
end
|
41
44
|
|
42
45
|
context 'tags can be array and thumbnail is false' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mushikago-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Toru Matsuoka
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-13 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|