spore 0.0.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/LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +58 -0
- data/TODO.rdoc +5 -0
- data/VERSION +1 -0
- data/lib/spore.rb +290 -0
- data/lib/spore/middleware.rb +42 -0
- data/lib/spore/middleware/format.rb +44 -0
- data/lib/spore/middleware/runtime.rb +20 -0
- data/lib/spore/spec_parser/json.rb +30 -0
- data/lib/spore/spec_parser/yaml.rb +15 -0
- data/test/github.json +185 -0
- data/test/github.xml +87 -0
- data/test/github.yml +142 -0
- data/test/github1.yml +14 -0
- data/test/github2.yml +15 -0
- data/test/helper.rb +12 -0
- data/test/test_collapsing.rb +13 -0
- data/test/test_constructor.rb +24 -0
- data/test/test_enable_if.rb +37 -0
- data/test/test_github.rb +51 -0
- data/test/test_middleware_runtime.rb +22 -0
- data/test/test_parser.rb +37 -0
- data/test/xml_parser.rb +7 -0
- metadata +123 -0
data/test/github1.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
name: GitHub1
|
3
|
+
methods:
|
4
|
+
list_public_keys:
|
5
|
+
authentication: true
|
6
|
+
method: GET
|
7
|
+
path: /:format/user/keys
|
8
|
+
required_params:
|
9
|
+
- format
|
10
|
+
meta:
|
11
|
+
documentation: http://develop.github.com/
|
12
|
+
base_url: http://github.com/api/v2/
|
13
|
+
version: "0.2"
|
14
|
+
authority: GITHUB:franckcuny
|
data/test/github2.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: GitHub2
|
3
|
+
methods:
|
4
|
+
list_public_keys:
|
5
|
+
authentication: true
|
6
|
+
method: GET
|
7
|
+
path: /:format/user/keys/:something_else
|
8
|
+
required_params:
|
9
|
+
- format
|
10
|
+
- something_else
|
11
|
+
meta:
|
12
|
+
documentation: http://develop.github.com/
|
13
|
+
base_url: http://github.com/api/v2/
|
14
|
+
version: "0.2"
|
15
|
+
authority: GITHUB:franckcuny
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'test-unit', '>= 2.1.0'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
require "spore"
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
class TestCollapsing < Test::Unit::TestCase
|
4
|
+
|
5
|
+
test "Use of different api in same project" do
|
6
|
+
spore1 = Spore.new(File.expand_path('../github1.yml',__FILE__))
|
7
|
+
spore2 = Spore.new(File.expand_path('../github2.yml',__FILE__))
|
8
|
+
assert_nothing_raised do
|
9
|
+
spore1.list_public_keys(:format => :json)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestConstructor < Test::Unit::TestCase
|
5
|
+
|
6
|
+
|
7
|
+
def test_build_fail
|
8
|
+
assert_raise ArgumentError do
|
9
|
+
spore = Spore.new()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_build_github_json
|
14
|
+
github_spec = File.join(File.dirname(__FILE__), 'github.json')
|
15
|
+
spore = Spore.new(github_spec)
|
16
|
+
assert_kind_of Spore, spore
|
17
|
+
|
18
|
+
assert_equal 'http://github.com/api/v2', spore.base_url
|
19
|
+
assert_equal '0.2', spore.version
|
20
|
+
assert_equal '/:format/user/search/:search', spore.methods['user_search']['path']
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'spore/middleware/format'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class Spore
|
7
|
+
class Middleware
|
8
|
+
class FooBar < Spore::Middleware
|
9
|
+
def process_request(env)
|
10
|
+
[302, ['Location', 'http://www.google.com'], []]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestEnableIf < Test::Unit::TestCase
|
17
|
+
|
18
|
+
|
19
|
+
def test_build_github_json
|
20
|
+
github_spec = File.join(File.dirname(__FILE__), 'github.json')
|
21
|
+
spore = Spore.new(github_spec)
|
22
|
+
spore.enable(Spore::Middleware::Format, :format => 'json')
|
23
|
+
|
24
|
+
# user_search is not altered
|
25
|
+
r = spore.user_search(:format => 'json', :search => 'sukria')
|
26
|
+
assert_equal 'sukria', r.body['users'][0]['name']
|
27
|
+
|
28
|
+
spore.enable_if(Spore::Middleware::FooBar, {}) do |env|
|
29
|
+
env['spore.request_path'].match(/\/user\/search/)
|
30
|
+
end
|
31
|
+
|
32
|
+
# user_search is altered
|
33
|
+
r = spore.user_search(:format => 'json', :search => 'sukria')
|
34
|
+
assert_equal 302, r.code
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/test_github.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'spore/middleware/format'
|
4
|
+
|
5
|
+
class TestGitHub < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
json = File.expand_path( '../github.json', __FILE__)
|
9
|
+
yaml = File.expand_path( '../github.yml', __FILE__)
|
10
|
+
@specs = [json,yaml]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basic_github_search
|
14
|
+
@specs.each do |spec|
|
15
|
+
gh = Spore.new(spec)
|
16
|
+
|
17
|
+
r = gh.user_search(:format => 'json', :search => 'sukria')
|
18
|
+
assert_kind_of HTTP::Message, r
|
19
|
+
assert_equal r.status, 200
|
20
|
+
assert_kind_of String, r.body.content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_github_search_without_mandatory_param
|
25
|
+
@specs.each do |spec|
|
26
|
+
gh = Spore.new(spec)
|
27
|
+
|
28
|
+
assert_raise Spore::RequiredParameterExptected do
|
29
|
+
r = gh.user_search(:format => 'json')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_with_format_github_search
|
35
|
+
@specs.each do |spec|
|
36
|
+
gh = Spore.new(spec)
|
37
|
+
|
38
|
+
gh.enable(Spore::Middleware::Format, :format => 'json')
|
39
|
+
|
40
|
+
assert_equal 1, gh.middlewares.size
|
41
|
+
|
42
|
+
r = gh.user_search(:format => 'json', :search => 'sukria')
|
43
|
+
assert_kind_of HTTP::Message, r
|
44
|
+
assert_equal r.status, 200
|
45
|
+
assert_kind_of Hash, r.body
|
46
|
+
assert_equal 'sukria', r.body['users'][0]['name']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'spore/middleware/runtime'
|
4
|
+
class TestRuntime < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_with_format_github_search
|
7
|
+
github_spec = File.join(File.dirname(__FILE__), 'github.json')
|
8
|
+
gh = Spore.new(github_spec)
|
9
|
+
|
10
|
+
gh.enable(Spore::Middleware::Runtime)
|
11
|
+
assert_equal 1, gh.middlewares.size
|
12
|
+
|
13
|
+
r = gh.user_search(:format => 'json', :search => 'sukria')
|
14
|
+
assert_kind_of HTTP::Message, r
|
15
|
+
assert_equal r.status, 200
|
16
|
+
|
17
|
+
assert_not_nil r.header['X-Spore-Runtime'][0]
|
18
|
+
assert r.header['X-Spore-Runtime'][0] > 0.00001
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
data/test/test_parser.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'spore/spec_parser/yaml'
|
4
|
+
require 'spore/spec_parser/json'
|
5
|
+
require 'rexml/document'
|
6
|
+
class TestParser < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_yaml_parser
|
9
|
+
spec = File.expand_path('../github.yml', __FILE__)
|
10
|
+
specs = Spore::SpecParser::Yaml.load_file(spec)
|
11
|
+
assert_instance_of Hash, specs
|
12
|
+
assert specs.has_key?('name')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_json_parser
|
16
|
+
spec = File.expand_path('../github.json', __FILE__)
|
17
|
+
specs = Spore::SpecParser::Json.load_file(spec)
|
18
|
+
assert_instance_of Hash, specs
|
19
|
+
assert specs.has_key?('name')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_custom_parser
|
23
|
+
file = File.expand_path('../xml_parser.rb', __FILE__)
|
24
|
+
spec = File.expand_path('../github.xml',__FILE__)
|
25
|
+
|
26
|
+
begin
|
27
|
+
parser = Spore.load_parser(spec, :require => file, :parser => 'MyCustomParser')
|
28
|
+
rescue LoadError
|
29
|
+
warn "Can not load XmlSimple gem. Please gem install xml-simple to run this test"
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
specs = parser.load_file(spec)
|
34
|
+
assert_instance_of Hash, specs
|
35
|
+
assert specs.has_key?('name')
|
36
|
+
end
|
37
|
+
end
|
data/test/xml_parser.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alexis Sukrieh <sukria@sukria.net> [sukria]
|
13
|
+
- Hery Ramihajamalala <hery@rails-royce.org> [hallelujah]
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-22 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 6
|
33
|
+
version: 1.4.6
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httpclient
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Spore is a specification for describing ReST API that can be parsed and used automatically by client implementations to communicate with the descibed API
|
50
|
+
email: <sukria@sukria.net>
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
files:
|
59
|
+
- LICENSE
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- TODO.rdoc
|
63
|
+
- VERSION
|
64
|
+
- lib/spore.rb
|
65
|
+
- lib/spore/middleware.rb
|
66
|
+
- lib/spore/middleware/format.rb
|
67
|
+
- lib/spore/middleware/runtime.rb
|
68
|
+
- lib/spore/spec_parser/json.rb
|
69
|
+
- lib/spore/spec_parser/yaml.rb
|
70
|
+
- test/github.json
|
71
|
+
- test/github.xml
|
72
|
+
- test/github.yml
|
73
|
+
- test/github1.yml
|
74
|
+
- test/github2.yml
|
75
|
+
- test/helper.rb
|
76
|
+
- test/test_collapsing.rb
|
77
|
+
- test/test_constructor.rb
|
78
|
+
- test/test_enable_if.rb
|
79
|
+
- test/test_github.rb
|
80
|
+
- test/test_middleware_runtime.rb
|
81
|
+
- test/test_parser.rb
|
82
|
+
- test/xml_parser.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/sukria/Ruby-Spore
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.3.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: A Ruby implementation for SPORE
|
115
|
+
test_files:
|
116
|
+
- test/helper.rb
|
117
|
+
- test/test_collapsing.rb
|
118
|
+
- test/test_constructor.rb
|
119
|
+
- test/test_enable_if.rb
|
120
|
+
- test/test_github.rb
|
121
|
+
- test/test_middleware_runtime.rb
|
122
|
+
- test/test_parser.rb
|
123
|
+
- test/xml_parser.rb
|