jsonism 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/jsonism.gemspec +26 -0
- data/lib/jsonism.rb +16 -0
- data/lib/jsonism/client.rb +44 -0
- data/lib/jsonism/definer.rb +42 -0
- data/lib/jsonism/error.rb +4 -0
- data/lib/jsonism/link.rb +43 -0
- data/lib/jsonism/request.rb +97 -0
- data/lib/jsonism/version.rb +3 -0
- data/spec/fixtures/schema.json +152 -0
- data/spec/jsonism/client_spec.rb +76 -0
- data/spec/spec_helper.rb +7 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5974d3d075706ced2dba0cbf08836c273631104
|
4
|
+
data.tar.gz: 904c1343e967ecb95335eaba195a6f11e4cae904
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff268a39733452a783f162a646e9772fc8351bd3221b0de026837955b1f3e1d017564b43220e40db11337888f6ae8d6fbc6699fcf8c74180dec12f314527ab05
|
7
|
+
data.tar.gz: e75a3f4eb5072fac3ab3e18b52f7b2d2df28a3aa833c5acfec5292f5935fa5d8273253483d11dcde331e584991475d9acd736d079b9e0f19dbdf113bc7ff69d1
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryo Nakamura
|
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,42 @@
|
|
1
|
+
# Jsonism
|
2
|
+
Generate HTTP Client from JSON Schema.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
```ruby
|
6
|
+
# Prepare JSON Schema for your API
|
7
|
+
body = File.read("schema.json")
|
8
|
+
schema = JSON.parse(body)
|
9
|
+
|
10
|
+
# Create an HTTP client from JSON Schema which is a Hash object
|
11
|
+
client = Jsonism::Client.new(schema: schema)
|
12
|
+
client.methods(false) #=> [:create_app, :delete_app, :info_app, :list_app, :update_app, :list_recipe]
|
13
|
+
|
14
|
+
# GET /apps
|
15
|
+
client.list_app
|
16
|
+
|
17
|
+
# GET /apps/1
|
18
|
+
client.info_app(id: 1)
|
19
|
+
|
20
|
+
# POST /apps
|
21
|
+
client.create_app(name: "alpha")
|
22
|
+
|
23
|
+
# PUT /apps/1
|
24
|
+
client.update_app(id: 1, name: "bravo")
|
25
|
+
|
26
|
+
# DELETE /apps/1
|
27
|
+
client.delete_app(id: 1)
|
28
|
+
|
29
|
+
# GET /recipes
|
30
|
+
client.list_recipe
|
31
|
+
```
|
32
|
+
|
33
|
+
## Errors
|
34
|
+
```
|
35
|
+
StandardError
|
36
|
+
|
|
37
|
+
`---Jsonism::Error
|
38
|
+
|
|
39
|
+
|---Jsonism::Client::BaseUrlNotFound
|
40
|
+
|
|
41
|
+
`---Jsonism::Request::MissingParams
|
42
|
+
```
|
data/Rakefile
ADDED
data/jsonism.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "jsonism/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jsonism"
|
7
|
+
spec.version = Jsonism::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "Generate HTTP Client from JSON Schema."
|
11
|
+
spec.homepage = "https://github.com/r7kamura/jsonism"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "activesupport"
|
20
|
+
spec.add_dependency "faraday"
|
21
|
+
spec.add_dependency "faraday_middleware"
|
22
|
+
spec.add_dependency "json_schema"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "2.14.1"
|
26
|
+
end
|
data/lib/jsonism.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "active_support/core_ext/hash/indifferent_access"
|
2
|
+
require "active_support/core_ext/hash/keys"
|
3
|
+
require "active_support/core_ext/hash/slice"
|
4
|
+
require "active_support/core_ext/object/try"
|
5
|
+
require "active_support/core_ext/string/inflections"
|
6
|
+
require "faraday"
|
7
|
+
require "faraday_middleware"
|
8
|
+
require "json"
|
9
|
+
require "json_schema"
|
10
|
+
|
11
|
+
require "jsonism/error"
|
12
|
+
require "jsonism/client"
|
13
|
+
require "jsonism/definer"
|
14
|
+
require "jsonism/link"
|
15
|
+
require "jsonism/request"
|
16
|
+
require "jsonism/version"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Jsonism
|
2
|
+
class Client
|
3
|
+
# @param schema [Hash] JSON Schema
|
4
|
+
# @raise [JsonSchema::SchemaError]
|
5
|
+
def initialize(schema: nil)
|
6
|
+
@schema = ::JsonSchema.parse!(schema).tap(&:expand_references!)
|
7
|
+
define
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Faraday::Connection]
|
11
|
+
def connection
|
12
|
+
@connection ||= Faraday.new(url: base_url) do |connection|
|
13
|
+
connection.request :json
|
14
|
+
connection.response :json
|
15
|
+
connection.adapter :net_http
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] Base URL of API
|
20
|
+
# @note Base URL is gained from the top-level link property whose `rel` is self
|
21
|
+
# @raise [Jsonism::Client::BaseUrlNotFound]
|
22
|
+
def base_url
|
23
|
+
@base_url ||= root_link.try(:href) or raise BaseUrlNotFound
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Defines some methods into itself from its JSON Schema
|
29
|
+
def define
|
30
|
+
Definer.call(client: self, schema: @schema)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Finds link that has "self" rel to resolve API base URL
|
34
|
+
# @return [JsonSchema::Schema::Link, nil]
|
35
|
+
def root_link
|
36
|
+
@schema.links.find do |link|
|
37
|
+
link.rel == "self"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class BaseUrlNotFound < Error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Jsonism
|
2
|
+
class Definer
|
3
|
+
# Utility wrapper
|
4
|
+
def self.call(*args)
|
5
|
+
new(*args).call
|
6
|
+
end
|
7
|
+
|
8
|
+
# Recursively extracts all links from given JSON schema
|
9
|
+
# @param schema [JsonSchema::Schema]
|
10
|
+
# @return [Array<JsonSchema::Schema::Link>]
|
11
|
+
def self.extract_links(schema)
|
12
|
+
links = schema.links.select {|link| link.method && link.href }
|
13
|
+
links + schema.properties.map {|key, schema| extract_links(schema) }.flatten
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param client [Jsonism::Client]
|
17
|
+
# @param schema [JsonSchema::Schema] JSON Schema
|
18
|
+
def initialize(client: nil, schema: nil)
|
19
|
+
@client = client
|
20
|
+
@schema = schema
|
21
|
+
end
|
22
|
+
|
23
|
+
# Defines methods to call HTTP request from its JSON schema
|
24
|
+
def call
|
25
|
+
client = @client
|
26
|
+
links.each do |link|
|
27
|
+
@client.define_singleton_method(link.method_signature) do |params = {}, headers = {}|
|
28
|
+
Request.call(client: client, headers: headers, link: link, params: params)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Array<JsonSchema::Schema::Link>] Links defined in its JSON schema
|
36
|
+
def links
|
37
|
+
@links ||= self.class.extract_links(@schema).map do |link|
|
38
|
+
Link.new(link: link)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/jsonism/link.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Jsonism
|
2
|
+
class Link
|
3
|
+
# @param schema [JsonSchema::Schema::Link]
|
4
|
+
def initialize(link: nil)
|
5
|
+
@link = link
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
# @example
|
10
|
+
# method_signature #=> "list_app"
|
11
|
+
def method_signature
|
12
|
+
link_title.underscore + "_" + schema_title.gsub(" ", "").underscore
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] Uppercase requet method
|
16
|
+
# @example
|
17
|
+
# method #=> "GET"
|
18
|
+
def method
|
19
|
+
@link.method.to_s.upcase
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Stirng]
|
23
|
+
# @example
|
24
|
+
# href #=> "/apps"
|
25
|
+
def href
|
26
|
+
@link.href
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def schema_title
|
32
|
+
schema.title
|
33
|
+
end
|
34
|
+
|
35
|
+
def link_title
|
36
|
+
@link.title
|
37
|
+
end
|
38
|
+
|
39
|
+
def schema
|
40
|
+
@link.target_schema || @link.parent
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Jsonism
|
2
|
+
class Request
|
3
|
+
# Utility wrapper
|
4
|
+
def self.call(*args)
|
5
|
+
new(*args).call
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param client [Jsonism::Client]
|
9
|
+
# @param headers [Hash]
|
10
|
+
# @param link [Jsonism::Link]
|
11
|
+
# @param params [Hash]
|
12
|
+
def initialize(client: nil, headers: {}, link: nil, params: {})
|
13
|
+
@client = client
|
14
|
+
@headers = headers
|
15
|
+
@link = link
|
16
|
+
@params = params.with_indifferent_access
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sends HTTP request
|
20
|
+
def call
|
21
|
+
if has_valid_params?
|
22
|
+
@client.connection.send(method, path)
|
23
|
+
else
|
24
|
+
raise MissingParams, missing_params
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# @return [true, false] False if any keys in path template are missing
|
31
|
+
def has_valid_params?
|
32
|
+
missing_params.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Array<Stirng>] Missing parameter names
|
36
|
+
def missing_params
|
37
|
+
@missing_params ||= path_keys - @params.keys
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String] Method name to call connection's methods
|
41
|
+
# @example
|
42
|
+
# method #=> "get"
|
43
|
+
def method
|
44
|
+
@link.method.downcase
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [String] Path whose URI template is resolved
|
48
|
+
# @example
|
49
|
+
# path #=> "/apps/1"
|
50
|
+
def path
|
51
|
+
path_with_template % path_params.symbolize_keys
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
# @example
|
56
|
+
# path_with_template #=> "/apps/%{id}"
|
57
|
+
def path_with_template
|
58
|
+
@link.href.gsub(/{(.+)}/) do |matched|
|
59
|
+
key = CGI.unescape($1).gsub(/[()]/, "").split("/").last
|
60
|
+
"%{#{key}}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Array<String>] Parameter names required for path
|
65
|
+
# @exmaple
|
66
|
+
# path_keys #=> ["id"]
|
67
|
+
def path_keys
|
68
|
+
@link.href.scan(/{(.+)}/).map do |str|
|
69
|
+
CGI.unescape($1).gsub(/[()]/, "").split("/").last
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [ActiveSupport::HashWithIndifferentAccess] Params to be embedded into path
|
74
|
+
# @example
|
75
|
+
# path_params #=> { id: 1 }
|
76
|
+
def path_params
|
77
|
+
@params.slice(*path_keys)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [ActiveSupport::HashWithIndifferentAccess] Params to be used for request body or query string
|
81
|
+
# @example
|
82
|
+
# request_params #=> { name: "example" }
|
83
|
+
def request_params
|
84
|
+
@params.except(*path_keys)
|
85
|
+
end
|
86
|
+
|
87
|
+
class MissingParams < Error
|
88
|
+
def initialize(missing_params)
|
89
|
+
@missing_params = missing_params
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
@missing_params.join(", ") + " params are missing"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/hyper-schema",
|
3
|
+
"definitions": {
|
4
|
+
"app": {
|
5
|
+
"$schema": "http://json-schema.org/draft-04/hyper-schema",
|
6
|
+
"description": "An app is a program to be deployed.",
|
7
|
+
"id": "schemata/app",
|
8
|
+
"title": "App",
|
9
|
+
"type": [
|
10
|
+
"object"
|
11
|
+
],
|
12
|
+
"required": ["id"],
|
13
|
+
"definitions": {
|
14
|
+
"id": {
|
15
|
+
"description": "unique identifier of app",
|
16
|
+
"example": "01234567-89ab-cdef-0123-456789abcdef",
|
17
|
+
"format": "uuid",
|
18
|
+
"readOnly": true,
|
19
|
+
"type": [
|
20
|
+
"string"
|
21
|
+
]
|
22
|
+
},
|
23
|
+
"name": {
|
24
|
+
"description": "unique name of app",
|
25
|
+
"example": "example",
|
26
|
+
"pattern": "^[a-z][a-z0-9-]{3,50}$",
|
27
|
+
"readOnly": false,
|
28
|
+
"type": [
|
29
|
+
"string"
|
30
|
+
]
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"links": [
|
34
|
+
{
|
35
|
+
"description": "Create a new app.",
|
36
|
+
"href": "/apps",
|
37
|
+
"method": "POST",
|
38
|
+
"rel": "create",
|
39
|
+
"schema": {
|
40
|
+
"properties": {
|
41
|
+
"name": {
|
42
|
+
"$ref": "#/definitions/app/definitions/name"
|
43
|
+
}
|
44
|
+
},
|
45
|
+
"type": [
|
46
|
+
"object"
|
47
|
+
]
|
48
|
+
},
|
49
|
+
"title": "Create"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"description": "Delete an existing app.",
|
53
|
+
"href": "/apps/{(%23%2Fdefinitions%2Fapp%2Fdefinitions%2Fid)}",
|
54
|
+
"method": "DELETE",
|
55
|
+
"rel": "destroy",
|
56
|
+
"title": "Delete"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"description": "Info for existing app.",
|
60
|
+
"href": "/apps/{(%23%2Fdefinitions%2Fapp%2Fdefinitions%2Fid)}",
|
61
|
+
"method": "GET",
|
62
|
+
"rel": "self",
|
63
|
+
"title": "Info"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"description": "List existing apps.",
|
67
|
+
"href": "/apps",
|
68
|
+
"method": "GET",
|
69
|
+
"rel": "instances",
|
70
|
+
"title": "List"
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"description": "Update an existing app.",
|
74
|
+
"href": "/apps/{(%23%2Fdefinitions%2Fapp%2Fdefinitions%2Fid)}",
|
75
|
+
"method": "PATCH",
|
76
|
+
"rel": "update",
|
77
|
+
"schema": {
|
78
|
+
"properties": {
|
79
|
+
"name": {
|
80
|
+
"$ref": "#/definitions/app/definitions/name"
|
81
|
+
}
|
82
|
+
},
|
83
|
+
"type": [
|
84
|
+
"object"
|
85
|
+
]
|
86
|
+
},
|
87
|
+
"title": "Update"
|
88
|
+
}
|
89
|
+
],
|
90
|
+
"properties": {
|
91
|
+
"id": {
|
92
|
+
"$ref": "#/definitions/app/definitions/id"
|
93
|
+
},
|
94
|
+
"name": {
|
95
|
+
"$ref": "#/definitions/app/definitions/name"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
},
|
99
|
+
"recipe": {
|
100
|
+
"$schema": "http://json-schema.org/draft-04/hyper-schema",
|
101
|
+
"description": "cooking Recipe",
|
102
|
+
"title": "Recipe",
|
103
|
+
"type": [
|
104
|
+
"object"
|
105
|
+
],
|
106
|
+
"definitions": {
|
107
|
+
"id": {
|
108
|
+
"description": "unique identifier of recipe",
|
109
|
+
"format": "uuid",
|
110
|
+
"readOnly": true,
|
111
|
+
"example": 1,
|
112
|
+
"type": [
|
113
|
+
"string"
|
114
|
+
]
|
115
|
+
}
|
116
|
+
},
|
117
|
+
"links": [
|
118
|
+
{
|
119
|
+
"description": "List recipes",
|
120
|
+
"href": "/recipes",
|
121
|
+
"method": "GET",
|
122
|
+
"rel": "instances",
|
123
|
+
"title": "list"
|
124
|
+
}
|
125
|
+
],
|
126
|
+
"properties": {
|
127
|
+
"id": {
|
128
|
+
"$ref": "#/definitions/recipe/definitions/id"
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
},
|
133
|
+
"properties": {
|
134
|
+
"app": {
|
135
|
+
"$ref": "#/definitions/app"
|
136
|
+
},
|
137
|
+
"recipe": {
|
138
|
+
"$ref": "#/definitions/recipe"
|
139
|
+
}
|
140
|
+
},
|
141
|
+
"type": [
|
142
|
+
"object"
|
143
|
+
],
|
144
|
+
"description": "A schema for a small example API.",
|
145
|
+
"links": [
|
146
|
+
{
|
147
|
+
"href": "http://localhost:8080",
|
148
|
+
"rel": "self"
|
149
|
+
}
|
150
|
+
],
|
151
|
+
"title": "Example API"
|
152
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jsonism::Client do
|
4
|
+
let(:instance) do
|
5
|
+
described_class.new(schema: schema)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:schema) do
|
9
|
+
JSON.parse(schema_body)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:schema_body) do
|
13
|
+
File.read(schema_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:schema_path) do
|
17
|
+
File.expand_path("../../fixtures/schema.json", __FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".new" do
|
21
|
+
subject do
|
22
|
+
instance
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a new Jsonism::Client from given JSON Schema" do
|
26
|
+
should be_a described_class
|
27
|
+
end
|
28
|
+
|
29
|
+
it "defines some methods from links property" do
|
30
|
+
should be_respond_to :create_app
|
31
|
+
should be_respond_to :delete_app
|
32
|
+
should be_respond_to :info_app
|
33
|
+
should be_respond_to :list_app
|
34
|
+
should be_respond_to :list_recipe
|
35
|
+
should be_respond_to :update_app
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#list_app" do
|
40
|
+
subject do
|
41
|
+
instance.list_app
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sends HTTP request to GET /apps" do
|
45
|
+
instance.connection.should_receive(:get).with("/apps")
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#info_app" do
|
51
|
+
subject do
|
52
|
+
instance.info_app(params)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:params) do
|
56
|
+
{ id: 1 }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with valid condition" do
|
60
|
+
it "sends HTTP request to GET /apps/:id" do
|
61
|
+
instance.connection.should_receive(:get).with("/apps/1")
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with missing params" do
|
67
|
+
before do
|
68
|
+
params.delete(:id)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "raises Jsonism::Request::MissingParams" do
|
72
|
+
expect { subject }.to raise_error(Jsonism::Request::MissingParams, "id params are missing")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsonism
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json_schema
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.14.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.14.1
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- r7kamura@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- jsonism.gemspec
|
124
|
+
- lib/jsonism.rb
|
125
|
+
- lib/jsonism/client.rb
|
126
|
+
- lib/jsonism/definer.rb
|
127
|
+
- lib/jsonism/error.rb
|
128
|
+
- lib/jsonism/link.rb
|
129
|
+
- lib/jsonism/request.rb
|
130
|
+
- lib/jsonism/version.rb
|
131
|
+
- spec/fixtures/schema.json
|
132
|
+
- spec/jsonism/client_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: https://github.com/r7kamura/jsonism
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.2.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Generate HTTP Client from JSON Schema.
|
158
|
+
test_files:
|
159
|
+
- spec/fixtures/schema.json
|
160
|
+
- spec/jsonism/client_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
has_rdoc:
|