leeno 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +11 -0
- data/LICENSE +22 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/leeno.gemspec +21 -0
- data/lib/leeno.rb +13 -0
- data/lib/leeno/api/base.rb +78 -0
- data/lib/leeno/api/canvas.rb +27 -0
- data/lib/leeno/api/history.rb +39 -0
- data/lib/leeno/extention/array.rb +9 -0
- data/lib/leeno/model/base.rb +28 -0
- data/lib/leeno/model/canvas.rb +24 -0
- data/lib/leeno/model/history.rb +35 -0
- data/lib/leeno/version.rb +3 -0
- data/spec/api/canvas_spec.rb +46 -0
- data/spec/api/history_spec.rb +96 -0
- data/spec/extention/array.rb +13 -0
- data/spec/model/canvas_spec.rb +52 -0
- data/spec/model/history_spec.rb +118 -0
- data/spec/spec_helper.rb +47 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 soplana
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Leeno
|
2
|
+
|
3
|
+
ラクガキサービスLeeno( http://leeno.jp/ )のAPIを利用する為のgemです
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ git clone git@github.com:soplana/leeno.git
|
9
|
+
$ cd Leeno
|
10
|
+
$ gem build leeno.gemspec
|
11
|
+
$ rake install
|
12
|
+
$ irb
|
13
|
+
|
14
|
+
irb(main):001:0> require "leeno"
|
15
|
+
=> true
|
16
|
+
irb(main):003:0> Leeno::Api::History.find("1cz", 1).to_json
|
17
|
+
=> {:canvas_id=>"1cz", :history_id=>1 ... :update_date=>"2012-05-08T15:52:39+09:00"}}
|
18
|
+
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Canvasを取得する
|
23
|
+
---
|
24
|
+
# Canvas#find success
|
25
|
+
> Leeno::Api::Canvas.find("1cz")
|
26
|
+
=> #<Leeno::Model::Canvas:0x00000 ... >
|
27
|
+
# Canvas#find not found
|
28
|
+
> Leeno::Api::Canvas.find(0)
|
29
|
+
=> nil
|
30
|
+
|
31
|
+
# Canvas#find! success
|
32
|
+
> Leeno::Api::Canvas.find("1cz")
|
33
|
+
=> #<Leeno::Model::Canvas:0x00000 ... >
|
34
|
+
# Canvas#find! not found
|
35
|
+
> Leeno::Api::Canvas.find(0)
|
36
|
+
Leeno::DocumentNotFound: Leeno::Model::Canvas: Data Not Found
|
37
|
+
|
38
|
+
### Historyを取得する
|
39
|
+
---
|
40
|
+
> Leeno::Api::History.find("1cz", 1)
|
41
|
+
=> #<Leeno::Model::History:0x00000 ... >
|
42
|
+
|
43
|
+
### Canvasに紐づくHistoryを全て取得する
|
44
|
+
---
|
45
|
+
> Leeno::Api::Canvas.find("1cz").histories
|
46
|
+
=> [#<Leeno::Model::History:0x00000 ... >
|
47
|
+
|
48
|
+
# History#find_histories success
|
49
|
+
> Leeno::Api::History.find_histories("1cz")
|
50
|
+
=> [#<Leeno::Model::History:0x00000 ... >
|
51
|
+
# History#find_histories not found
|
52
|
+
> Leeno::Api::History.find_histories(0)
|
53
|
+
=> []
|
54
|
+
|
55
|
+
# History#find_histories! success
|
56
|
+
> Leeno::Api::History.find_histories!("1cz")
|
57
|
+
=> [#<Leeno::Model::History:0x00000 ... >
|
58
|
+
# History#find_histories! not found
|
59
|
+
> Leeno::Api::History.find_histories!(0)
|
60
|
+
Leeno::DocumentNotFound: Leeno::Model::History: Data Not Found
|
61
|
+
|
62
|
+
### HistoryのParent(編集元History)を取得する
|
63
|
+
---
|
64
|
+
> Leeno::Api::History.find("1cz", 2).parent
|
65
|
+
=> #<Leeno::Model::History:0x00000 ... >
|
66
|
+
|
67
|
+
### HistoryのChildren(派生History)を取得する
|
68
|
+
---
|
69
|
+
> Leeno::Api::History.find("1cz", 2).children
|
70
|
+
=> [#<Leeno::Model::History:0x0000 ... >]
|
71
|
+
|
72
|
+
### json形式に変換する
|
73
|
+
---
|
74
|
+
> Leeno::Api::Canvas.find("1cz").to_json
|
75
|
+
=> {:canvas_id=>"1cz", ... :update_date=>"2012-05-08T15:52:39+09:00"}
|
76
|
+
|
77
|
+
> Leeno::Api::Canvas.find("1cz").histories.to_json
|
78
|
+
=> [{:canvas_id=>"1cz", ... :update_date=>"2012-05-08T15:52:39+09:00"}]
|
data/Rakefile
ADDED
data/leeno.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/leeno/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["soplana"]
|
6
|
+
gem.email = ["sonosheet.jp@gmail.com"]
|
7
|
+
gem.description = %q{LeenoAPI client for Ruby}
|
8
|
+
gem.summary = %q{LeenoAPI client for Ruby}
|
9
|
+
gem.homepage = "https://github.com/soplana/leeno"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "leeno"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Leeno::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "faraday", "~>0.8.0"
|
19
|
+
gem.add_dependency "faraday_middleware", "~>0.8.7"
|
20
|
+
|
21
|
+
end
|
data/lib/leeno.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "leeno/version"
|
2
|
+
require 'leeno/extention/array'
|
3
|
+
require 'leeno/api/base'
|
4
|
+
require 'leeno/api/canvas'
|
5
|
+
require 'leeno/api/history'
|
6
|
+
require 'leeno/model/base'
|
7
|
+
require 'leeno/model/canvas'
|
8
|
+
require 'leeno/model/history'
|
9
|
+
|
10
|
+
module Leeno
|
11
|
+
class LeenoError < RuntimeError; end
|
12
|
+
class DocumentNotFound < LeenoError; end
|
13
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Leeno::Api
|
5
|
+
class Base
|
6
|
+
include Leeno
|
7
|
+
DOMAIN = 'http://leeno.jp'
|
8
|
+
|
9
|
+
@@conn = Faraday.new(:url => DOMAIN) do |builder|
|
10
|
+
builder.request :url_encoded
|
11
|
+
builder.adapter :net_http
|
12
|
+
builder.response :json
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
class << self
|
17
|
+
def url; raise; end
|
18
|
+
def default_options; raise; end
|
19
|
+
|
20
|
+
def model_class
|
21
|
+
eval(self.to_s.gsub(/Api/, "Model"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_options! options
|
25
|
+
@@options = default_options.merge(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def search_show options, throws=false
|
29
|
+
set_options!(options)
|
30
|
+
throws ? request_show! : request_show
|
31
|
+
end
|
32
|
+
|
33
|
+
def search_index options, throws=false
|
34
|
+
set_options!(options)
|
35
|
+
throws ? request_index! : request_index
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_show
|
39
|
+
result = get(url[:show])
|
40
|
+
result.nil? ? nil : model_class.new(result)
|
41
|
+
end
|
42
|
+
|
43
|
+
def request_index
|
44
|
+
results = get(url[:index])
|
45
|
+
return Leeno::Array.new if results.nil?
|
46
|
+
Leeno::Array.new results.map{|result| model_class.new(result)}
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_show!
|
50
|
+
model_class.new get(url[:show], true)
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_index!
|
54
|
+
results = get(url[:index], true)
|
55
|
+
Leeno::Array.new results.map{|result| model_class.new(result)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def get url, throws=false
|
59
|
+
data = @@conn.get(url, @@options).body
|
60
|
+
return ( throws ? result_set!(data) : result_set(data) )
|
61
|
+
end
|
62
|
+
|
63
|
+
def result_set! data
|
64
|
+
return data['result'] if success?(data)
|
65
|
+
raise Leeno::DocumentNotFound.new("#{model_class}: #{data['message']}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def result_set data
|
69
|
+
return data['result'] if success?(data)
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def success? data
|
74
|
+
data['status'] == 'ok'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Leeno::Api::Canvas < Leeno::Api::Base
|
2
|
+
class << self
|
3
|
+
def find id, options={}
|
4
|
+
return nil if id.nil?
|
5
|
+
search_show({canvas_id: id.to_s}.merge(options))
|
6
|
+
end
|
7
|
+
|
8
|
+
def find! id, options={}
|
9
|
+
raise(Leeno::DocumentNotFound.new("#{model_class}: id NilClass")) if id.nil?
|
10
|
+
search_show({canvas_id: id.to_s}.merge(options), true)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def url
|
15
|
+
return {
|
16
|
+
show: "/api/canvas.json",
|
17
|
+
index: "/api/canvases.json"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_options
|
22
|
+
return {
|
23
|
+
tag: true
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Leeno::Api::History < Leeno::Api::Base
|
2
|
+
class << self
|
3
|
+
def find c_id, h_id, options={}
|
4
|
+
return nil if (c_id.nil? || h_id.nil?)
|
5
|
+
search_show({canvas_id: c_id.to_s, history_id: h_id.to_s}.merge(options))
|
6
|
+
end
|
7
|
+
|
8
|
+
def find! c_id, h_id, options={}
|
9
|
+
raise(Leeno::DocumentNotFound.new("#{model_class}: canvas_id or history_id NilClass")) if (c_id.nil? || h_id.nil?)
|
10
|
+
search_show({canvas_id: c_id.to_s, history_id: h_id.to_s}.merge(options), true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_histories id, options={}
|
14
|
+
return Leeno::Array.new if id.nil?
|
15
|
+
search_index({canvas_id: id.to_s}.merge(options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_histories! id, options={}
|
19
|
+
raise(Leeno::DocumentNotFound.new("#{model_class}: id NilClass")) if id.nil?
|
20
|
+
search_index({canvas_id: id.to_s}.merge(options), true)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def url
|
25
|
+
return {
|
26
|
+
show: "/api/history.json",
|
27
|
+
index: "/api/histories.json"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_options
|
32
|
+
return {
|
33
|
+
canvas: true,
|
34
|
+
parent: true,
|
35
|
+
children: true
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Leeno::Model
|
2
|
+
class Base
|
3
|
+
def initialize data
|
4
|
+
self.class::FIELDS.each do |field|
|
5
|
+
value = (field.to_s =~ /_date$/ ? Time.new(data[field.to_s]) : data[field.to_s])
|
6
|
+
self.__send__("#{field}=", value)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def exclude_options!
|
11
|
+
@exclude_options = true
|
12
|
+
return self
|
13
|
+
end
|
14
|
+
|
15
|
+
def include_options!
|
16
|
+
@exclude_options = false
|
17
|
+
return self
|
18
|
+
end
|
19
|
+
|
20
|
+
def exclude_options?
|
21
|
+
return !!@exclude_options
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json
|
25
|
+
self.class::FIELDS.inject({}){|hash, field| hash[field] = self.__send__("#{field}");hash }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
include Leeno
|
2
|
+
|
3
|
+
class Leeno::Model::Canvas < Model::Base
|
4
|
+
FIELDS = [
|
5
|
+
:canvas_id,
|
6
|
+
:title,
|
7
|
+
:name,
|
8
|
+
:width,
|
9
|
+
:height,
|
10
|
+
:tags,
|
11
|
+
:total_history,
|
12
|
+
:total_favorite,
|
13
|
+
:create_date,
|
14
|
+
:update_date
|
15
|
+
]
|
16
|
+
attr_accessor *FIELDS
|
17
|
+
def initialize data={}
|
18
|
+
super(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def histories
|
22
|
+
@histories ||= Leeno::Array.new( Api::History.find_histories(canvas_id) )
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
include Leeno
|
2
|
+
|
3
|
+
class Leeno::Model::History < Model::Base
|
4
|
+
FIELDS = [
|
5
|
+
:canvas_id,
|
6
|
+
:history_id,
|
7
|
+
:parent_id,
|
8
|
+
:image_large,
|
9
|
+
:image_small,
|
10
|
+
:image_thumb,
|
11
|
+
:create_date,
|
12
|
+
:update_date
|
13
|
+
]
|
14
|
+
attr_accessor *FIELDS
|
15
|
+
def initialize data={}
|
16
|
+
super(data)
|
17
|
+
@canvas = Model::Canvas.new(data["canvas"]) unless data["canvas"].nil?
|
18
|
+
@parent = Model::History.new(data["parent"]) unless data["parent"].nil?
|
19
|
+
@children = Leeno::Array.new(data["children"].map{|h|Model::History.new(h)}) unless data["children"].nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def canvas
|
23
|
+
@canvas ||= Api::Canvas.find(canvas_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def parent
|
27
|
+
return nil if (parent_id.nil? || parent_id.to_i == 0)
|
28
|
+
@parent ||= Api::History.find(canvas_id, parent_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def children
|
32
|
+
@children ||= Leeno::Array.new(Api::History.find(canvas_id, history_id).children)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
include Leeno::Api
|
4
|
+
|
5
|
+
|
6
|
+
describe Canvas do
|
7
|
+
|
8
|
+
describe "#model_class" do
|
9
|
+
it "ModelClassが取得出来る事" do
|
10
|
+
Canvas.model_class.should == Leeno::Model::Canvas
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#find" do
|
15
|
+
it "第一引数にnilで結果が取得出来ない事" do
|
16
|
+
Canvas.find(nil).should == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "API経由でデータが取得出来る事" do
|
20
|
+
success!
|
21
|
+
Canvas.find("1cz").class.should == Leeno::Model::Canvas
|
22
|
+
end
|
23
|
+
|
24
|
+
it "データの取得が出来ない場合、nilが返される事" do
|
25
|
+
error!
|
26
|
+
Canvas.find(0).should == nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#find!" do
|
31
|
+
it "第一引数にnilで結果が取得出来ない事" do
|
32
|
+
proc{Canvas.find!(nil)}.should raise_error(Leeno::DocumentNotFound)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "API経由でデータが取得出来る事" do
|
36
|
+
success!
|
37
|
+
Canvas.find!("1cz").class.should == Leeno::Model::Canvas
|
38
|
+
end
|
39
|
+
|
40
|
+
it "データの取得が出来ない場合、DocumentNotFoundが返される事" do
|
41
|
+
error!
|
42
|
+
proc{Canvas.find!(0)}.should raise_error(Leeno::DocumentNotFound)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
include Leeno::Api
|
4
|
+
|
5
|
+
|
6
|
+
describe History do
|
7
|
+
|
8
|
+
describe "#model_class" do
|
9
|
+
it "ModelClassが取得出来る事" do
|
10
|
+
History.model_class.should == Leeno::Model::History
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#find" do
|
15
|
+
it "第一引数,第二引数にnilで結果が取得出来ない事" do
|
16
|
+
History.find(nil, nil).should == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "第二引数にnilで結果が取得出来ない事" do
|
20
|
+
History.find("1cz", nil).should == nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "データの取得が出来ない場合、nilが返される事" do
|
24
|
+
error!
|
25
|
+
History.find(0, 0).should == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "API経由でデータが取得出来る事" do
|
29
|
+
success!
|
30
|
+
History.find("1cz", 1).class.should == Leeno::Model::History
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#find!" do
|
35
|
+
it "第一引数,第二引数にnilで結果が取得出来ない事" do
|
36
|
+
proc{History.find!(nil, nil)}.should raise_error(Leeno::DocumentNotFound)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "第二引数にnilで結果が取得出来ない事" do
|
40
|
+
proc{History.find!("1cz", nil)}.should raise_error(Leeno::DocumentNotFound)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "データの取得が出来ない場合、nilが返される事" do
|
44
|
+
error!
|
45
|
+
proc{History.find!(0, 0)}.should raise_error(Leeno::DocumentNotFound)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "API経由でデータが取得出来る事" do
|
49
|
+
success!
|
50
|
+
History.find!("1cz", 1).class.should == Leeno::Model::History
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#find_histories" do
|
55
|
+
it "第一引数にnilで結果が取得出来ない事" do
|
56
|
+
History.find_histories(nil).should == Leeno::Array.new
|
57
|
+
end
|
58
|
+
|
59
|
+
it "データの取得が出来ない場合、Leeno::Arrayが返される事" do
|
60
|
+
error!
|
61
|
+
History.find_histories(0).should == Leeno::Array.new
|
62
|
+
end
|
63
|
+
|
64
|
+
it "結果が二件取得出来る事" do
|
65
|
+
success!
|
66
|
+
History.find_histories("1cz").size.should == 2
|
67
|
+
end
|
68
|
+
|
69
|
+
it "history_id: 1, 2が取得出来ている事" do
|
70
|
+
success!
|
71
|
+
History.find_histories("1cz").map(&:history_id).should == [1,2]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#find_histories!" do
|
76
|
+
it "第一引数にnilで結果が取得出来ない事" do
|
77
|
+
proc{History.find_histories!(nil)}.should raise_error(Leeno::DocumentNotFound)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "データの取得が出来ない場合、nilが返される事" do
|
81
|
+
error!
|
82
|
+
proc{History.find_histories!(0)}.should raise_error(Leeno::DocumentNotFound)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "結果が二件取得出来る事" do
|
86
|
+
success!
|
87
|
+
History.find_histories!("1cz").size.should == 2
|
88
|
+
end
|
89
|
+
|
90
|
+
it "history_id: 1, 2が取得出来ている事" do
|
91
|
+
success!
|
92
|
+
History.find_histories!("1cz").map(&:history_id).should == [1,2]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe Array do
|
5
|
+
|
6
|
+
describe ".to_json" do
|
7
|
+
it "castされること" do
|
8
|
+
history_success!
|
9
|
+
history = Leeno::Api::History.find("1cz", 1)
|
10
|
+
history.children.to_json.map(&:class).uniq.should == [Hash]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
include Leeno::Model
|
4
|
+
|
5
|
+
describe Canvas do
|
6
|
+
before do
|
7
|
+
success!
|
8
|
+
@canvas = Leeno::Api::Canvas.find("1cz")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "インスタンス変数が正しく設定されていること" do
|
12
|
+
it do
|
13
|
+
@canvas.instance_variables.should == [:@canvas_id, :@title, :@name, :@width, :@height, :@tags, :@total_history, :@total_favorite, :@create_date, :@update_date]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".histories" do
|
18
|
+
before do
|
19
|
+
success!
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Model::Historyクラスの配列が取得できること" do
|
23
|
+
histories = Leeno::Api::Canvas.find("1cz").histories
|
24
|
+
histories.map(&:class).uniq.should == [Leeno::Model::History]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "@historiesがnilであること" do
|
28
|
+
canvas = Leeno::Api::Canvas.find("1cz")
|
29
|
+
canvas.instance_eval{@histories}.should be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it ".historiesを呼び出したら@historiesに結果が代入されること" do
|
33
|
+
canvas = Leeno::Api::Canvas.find("1cz")
|
34
|
+
histories = canvas.histories
|
35
|
+
canvas.instance_eval{@histories}.should == histories
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ".to_json" do
|
40
|
+
it "インスタンス変数 => 値形式に変換されること" do
|
41
|
+
success!
|
42
|
+
canvas = Leeno::Api::Canvas.find("1cz")
|
43
|
+
canvas.to_json.keys.should == canvas.instance_variables.map{|i|i.to_s.sub(/@/,"").to_sym}
|
44
|
+
end
|
45
|
+
|
46
|
+
it ".histories" do
|
47
|
+
success!
|
48
|
+
histories = Leeno::Api::Canvas.find("1cz").histories
|
49
|
+
histories.to_json.map(&:class).uniq.should == [Hash]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
include Leeno::Model
|
4
|
+
|
5
|
+
describe History do
|
6
|
+
|
7
|
+
describe "インスタンス変数が正しく設定されていること" do
|
8
|
+
context "関連情報を取得しないクエリの場合" do
|
9
|
+
before do
|
10
|
+
success!
|
11
|
+
@history = Leeno::Api::History.find("1cz", 1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "正しく設定されていること" do
|
15
|
+
@history.instance_variables.should == [:@canvas_id, :@history_id, :@parent_id, :@image_large, :@image_small, :@image_thumb, :@create_date, :@update_date]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "@canvasがnilである事" do
|
19
|
+
@history.instance_eval{@canvas}.should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "@parentがnilである事" do
|
23
|
+
@history.instance_eval{@parent}.should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "関連情報を取得するクエリの場合" do
|
28
|
+
before do
|
29
|
+
history_success!
|
30
|
+
@history = Leeno::Api::History.find("1cz", 1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "正しく設定されていること" do
|
34
|
+
@history.instance_variables.should == [:@canvas_id, :@history_id, :@parent_id, :@image_large, :@image_small, :@image_thumb, :@create_date, :@update_date, :@canvas, :@parent, :@children]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "@canvasにModel::Canvasクラスが設定されている事" do
|
38
|
+
@history.instance_eval{@canvas}.class.should == Leeno::Model::Canvas
|
39
|
+
end
|
40
|
+
|
41
|
+
it "@parentにModel::Historyクラスが設定されている事" do
|
42
|
+
@history.instance_eval{@parent}.class.should == Leeno::Model::History
|
43
|
+
end
|
44
|
+
|
45
|
+
it "@childrenにModel::Historyクラスの配列が設定されている事" do
|
46
|
+
@history.instance_eval{@children}.map(&:class).uniq.should == [Leeno::Model::History]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe ".canvas" do
|
52
|
+
before do
|
53
|
+
success!
|
54
|
+
@history = Leeno::Api::History.find("1cz", 1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "canvas(Model::Canvas)が取得出来ること" do
|
58
|
+
@history.canvas.class.should == Leeno::Model::Canvas
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ".parent" do
|
63
|
+
before do
|
64
|
+
success!
|
65
|
+
@history = Leeno::Api::History.find("1cz", 1)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "parent(Model::History)が取得出来ること" do
|
69
|
+
@history.parent.class.should == Leeno::Model::History
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".children" do
|
74
|
+
before do
|
75
|
+
history_success!
|
76
|
+
@history = Leeno::Api::History.find("1cz", 1)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "配列が取得出来ること" do
|
80
|
+
@history.children.class.should == Leeno::Array
|
81
|
+
end
|
82
|
+
|
83
|
+
it "children(Model::History)が取得出来ること" do
|
84
|
+
@history.children.first.class.should == Leeno::Model::History
|
85
|
+
end
|
86
|
+
|
87
|
+
it "ネストしたModel::Historyの@childrenはnilであること" do
|
88
|
+
child = @history.children.first
|
89
|
+
child.instance_eval{@children}.should be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it "ネストしたModel::Historyで一度.childrenを呼び出せばその後@childrenを参照すること" do
|
93
|
+
child = @history.children.first
|
94
|
+
children = child.children
|
95
|
+
child.instance_eval{@children}.should == children
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe ".to_json" do
|
100
|
+
it "インスタンス変数 => 値形式に変換されること" do
|
101
|
+
success!
|
102
|
+
history = Leeno::Api::History.find("1cz", 1)
|
103
|
+
history.to_json.keys.should == history.instance_variables.map{|i|i.to_s.sub(/@/,"").to_sym}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "インスタンス変数 => 値形式に変換されること[ parent ]" do
|
107
|
+
history_success!
|
108
|
+
history = Leeno::Api::History.find("1cz", 1).parent
|
109
|
+
history.to_json.keys.should == history.instance_variables.map{|i|i.to_s.sub(/@/,"").to_sym}
|
110
|
+
end
|
111
|
+
|
112
|
+
it "インスタンス変数 => 値形式に変換されること[ children ]" do
|
113
|
+
history_success!
|
114
|
+
history = Leeno::Api::History.find("1cz", 1).children.first
|
115
|
+
history.to_json.keys.should == history.instance_variables.map{|i|i.to_s.sub(/@/,"").to_sym}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "rubygems"
|
3
|
+
require 'mocktra'
|
4
|
+
require 'leeno'
|
5
|
+
#require 'rspec/rails'
|
6
|
+
|
7
|
+
|
8
|
+
def success!
|
9
|
+
Mocktra('leeno.jp') do
|
10
|
+
get '/api/canvas.json' do
|
11
|
+
return '{"result":{"canvas_id":"1cz","title":"\u30bf\u30a4\u30c8\u30eb\u7121\u3057","name":"\u540d\u7121\u3057\u3055\u3093","width":600,"height":400,"total_history":50,"total_favorite":0,"create_date":"2012-03-28T15:03:47+09:00","update_date":"2012-05-08T15:52:39+09:00"},"status":"ok","message":""}'
|
12
|
+
end
|
13
|
+
get '/api/history.json' do
|
14
|
+
return '{"result":{"history_id":2,"parent_id":1,"canvas_id":"158","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image_small_thumb.png","create_date":"2012-03-04T00:31:54+09:00","update_date":"2012-05-01T00:38:04+09:00"},"status":"ok","message":""}'
|
15
|
+
end
|
16
|
+
get '/api/histories.json' do
|
17
|
+
return '{"result":[{"history_id":1,"parent_id":null,"canvas_id":"158","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-1/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-1/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-1/image_small_thumb.png","create_date":"2012-03-04T00:31:54+09:00","update_date":"2012-05-01T00:38:04+09:00"},{"history_id":2,"parent_id":1,"canvas_id":"158","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/158-2/image_small_thumb.png","create_date":"2012-03-04T00:31:54+09:00","update_date":"2012-05-01T00:38:04+09:00"}],"status":"ok","message":""}'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def error!
|
23
|
+
Mocktra('leeno.jp') do
|
24
|
+
get '/api/canvas.json' do
|
25
|
+
return '{"result":"","status":"error","message":"Data Not Found"}'
|
26
|
+
end
|
27
|
+
get '/api/history.json' do
|
28
|
+
return '{"result":"","status":"error","message":"Data Not Found"}'
|
29
|
+
end
|
30
|
+
get '/api/histories.json' do
|
31
|
+
return '{"result":"","status":"error","message":"Data Not Found"}'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def history_success!
|
37
|
+
Mocktra('leeno.jp') do
|
38
|
+
get '/api/canvas.json' do
|
39
|
+
return '{"result":{"canvas_id":"1cz","title":"\u30bf\u30a4\u30c8\u30eb\u7121\u3057","name":"\u540d\u7121\u3057\u3055\u3093","width":600,"height":400,"total_history":50,"total_favorite":0,"create_date":"2012-03-28T15:03:47+09:00","update_date":"2012-05-08T15:52:39+09:00"},"status":"ok","message":""}'
|
40
|
+
end
|
41
|
+
get '/api/history.json' do
|
42
|
+
return '{"result":{"history_id":2,"parent_id":1,"canvas_id":"1g3","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-2/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-2/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-2/image_small_thumb.png","create_date":"2012-05-30T20:08:10+09:00","update_date":"2012-05-30T20:08:10+09:00","canvas":{"canvas_id":"1g3","title":"\u306b\u3082\u3064\u305f\u3061\u3081\u3082","name":"nanany_k","width":600,"height":400,"total_history":3,"total_favorite":0,"create_date":"2012-05-30T11:28:16+09:00","update_date":"2012-05-31T00:37:36+09:00"},"parent":{"history_id":1,"parent_id":null,"canvas_id":"1g3","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-1/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-1/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-1/image_small_thumb.png","create_date":"2012-05-30T11:28:16+09:00","update_date":"2012-05-30T11:28:16+09:00"},"children":[{"history_id":3,"parent_id":2,"canvas_id":"1g3","image_large":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-3/image.png","image_small":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-3/image_thumb.png","image_thumb":"http://s3-ap-northeast-1.amazonaws.com/leeno/c/1g3-3/image_small_thumb.png","create_date":"2012-05-31T00:37:36+09:00","update_date":"2012-05-31T00:37:36+09:00"}]},"status":"ok","message":""}'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
$LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leeno
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- soplana
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-31 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: &2156470500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156470500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday_middleware
|
27
|
+
requirement: &2156469960 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.8.7
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156469960
|
36
|
+
description: LeenoAPI client for Ruby
|
37
|
+
email:
|
38
|
+
- sonosheet.jp@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- leeno.gemspec
|
49
|
+
- lib/leeno.rb
|
50
|
+
- lib/leeno/api/base.rb
|
51
|
+
- lib/leeno/api/canvas.rb
|
52
|
+
- lib/leeno/api/history.rb
|
53
|
+
- lib/leeno/extention/array.rb
|
54
|
+
- lib/leeno/model/base.rb
|
55
|
+
- lib/leeno/model/canvas.rb
|
56
|
+
- lib/leeno/model/history.rb
|
57
|
+
- lib/leeno/version.rb
|
58
|
+
- spec/api/canvas_spec.rb
|
59
|
+
- spec/api/history_spec.rb
|
60
|
+
- spec/extention/array.rb
|
61
|
+
- spec/model/canvas_spec.rb
|
62
|
+
- spec/model/history_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: https://github.com/soplana/leeno
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.17
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: LeenoAPI client for Ruby
|
88
|
+
test_files:
|
89
|
+
- spec/api/canvas_spec.rb
|
90
|
+
- spec/api/history_spec.rb
|
91
|
+
- spec/extention/array.rb
|
92
|
+
- spec/model/canvas_spec.rb
|
93
|
+
- spec/model/history_spec.rb
|
94
|
+
- spec/spec_helper.rb
|