json_roa-client 1.0.0.pre.beta.1 → 1.0.0.pre.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -1
- data/lib/json_roa/client/relation.rb +9 -0
- data/lib/json_roa/client/version.rb +1 -1
- data/spec/data/root.yml +1 -1
- data/spec/methods_spec.rb +1 -1
- data/spec/template_expansion_spec.rb +36 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46382a4f2f15aff6db0a65d35cf46f7a6dab4ccc
|
4
|
+
data.tar.gz: f64826275e7ce06c69deac16ddaad67b997fe103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70cd3d8b62f0ad4d6557cdbb635b9487ccca60868c3d17002552b343967ce16041fa1da3d5b734d539d8a47d25e3983ee2b590a18903bf8183bcc27c2bdd2934
|
7
|
+
data.tar.gz: 804362c743bef126bf91fc7b5bd8726d239caa5aca1e07a2f4aa3824df9e4ad1e9a1366d7b845da9d578317d1e7f0c4f32ef08e4f9a334e6315c96d32c3ea249
|
data/README.md
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
# Ruby JSON-ROA Client
|
2
2
|
|
3
|
-
A ruby client for `
|
3
|
+
A ruby client for `JSON-ROA`.
|
4
|
+
|
5
|
+
## Semantic Versioning and Rubygems Versioning
|
6
|
+
|
7
|
+
This library is _BETA_ because the [JSON-ROA specifciation][] itself is
|
8
|
+
_BETA_. This library uses [Semantic Versioning][] and the current version
|
9
|
+
is [1.0.0-beta.2](./lib/json_roa/client/version.rb).
|
10
|
+
|
11
|
+
The rubygems system [claims also to use semantic versioning][] and even *urges
|
12
|
+
gem developers to follow it*. Rubygems transforms the version as given above
|
13
|
+
into `1.0.0.pre.beta.1`. Any work using this library should specify the
|
14
|
+
following in the Gemfile
|
15
|
+
|
16
|
+
gem 'json_roa-client', '= 1.0.0.pre.beta.2'
|
17
|
+
|
18
|
+
or the following in the gemspec
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'json_roa-client', '= 1.0.0.pre.beta.2'
|
21
|
+
|
22
|
+
In the latter case, building the gem will result in a warning because of the
|
23
|
+
prerelease. You can safely ignore this warning. It is in the context of
|
24
|
+
semantic versioning misleading. However, it is important to fix the dependency
|
25
|
+
by using the `=` sign. In this case, violation would warrant a warning.
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
[JSON-ROA specifciation]: http://json-roa.github.io/specification.html
|
31
|
+
[Semantic Versioning]: http://semver.org/
|
32
|
+
[claims also to use semantic versioning]: http://guides.rubygems.org/patterns/#semantic-versioning
|
4
33
|
|
5
34
|
## Usage
|
6
35
|
|
@@ -26,9 +26,18 @@ module JSON_ROA
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def assert_proper_query_parameters! query_parameters, template
|
30
|
+
unless Set.new(query_parameters.keys).subset? Set.new(template.keys)
|
31
|
+
raise StandardError, ["query_parameters", query_parameters.keys.to_s,
|
32
|
+
"do not match template parameters",
|
33
|
+
template.keys.to_s].join(" ")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
def run_request method, query_parameters, body, headers, &block
|
30
38
|
href= @data['href']
|
31
39
|
template= ::Addressable::Template.new(href)
|
40
|
+
assert_proper_query_parameters! query_parameters, template
|
32
41
|
expanded_url= template.expand(query_parameters)
|
33
42
|
response=@conn.run_request( \
|
34
43
|
method.to_sym, expanded_url, body, headers, &block)
|
data/spec/data/root.yml
CHANGED
data/spec/methods_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "methods of the relation /tasks/t1" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
subject(:task1_self_relation) \
|
10
|
-
{root_relation.get().relation("task").get(id
|
10
|
+
{root_relation.get().relation("task").get("id" => "t1").self_relation}
|
11
11
|
|
12
12
|
it "is a relation" do
|
13
13
|
expect(task1_self_relation.class).to be== JSON_ROA::Client::Relation
|
@@ -1,27 +1,51 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
-
describe "template expansion
|
3
|
+
describe "template expansion" do
|
4
4
|
|
5
5
|
let :root_relation do
|
6
6
|
JSON_ROA::Client.connect("/")
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
context "task relation" do
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
subject(:task_relation) {root_relation.get().relation("task")}
|
12
|
+
|
13
|
+
it "is a relation" do
|
14
|
+
expect(task_relation.class).to be== JSON_ROA::Client::Relation
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is templated" do
|
18
|
+
expect(task_relation.data['href']).to be== "/tasks/{id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "get with parameter to expand" do
|
22
|
+
subject(:task_resource){task_relation.get("id" => "t1")}
|
23
|
+
|
24
|
+
it "is a resource of t1" do
|
25
|
+
expect(task_resource.class).to be== JSON_ROA::Client::Resource
|
26
|
+
expect(task_resource.self_relation.data["href"]).to be== "/tasks/t1"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
14
30
|
|
15
|
-
it "is templated" do
|
16
|
-
expect(task_relation.data['href']).to be== "/tasks/{id}"
|
17
31
|
end
|
18
32
|
|
19
|
-
|
20
|
-
|
33
|
+
context "tasks relation" do
|
34
|
+
|
35
|
+
subject(:tasks_relation) {root_relation.get().relation("tasks")}
|
36
|
+
|
37
|
+
describe "get with existing parameter to expand" do
|
38
|
+
it "does not raise an error" do
|
39
|
+
expect{ tasks_relation.get("x" => "foo")
|
40
|
+
}.not_to raise_error
|
41
|
+
end
|
42
|
+
end
|
21
43
|
|
22
|
-
|
23
|
-
|
24
|
-
|
44
|
+
describe "get with a non-existing parameter to expand" do
|
45
|
+
it "raises an error" do
|
46
|
+
expect{ tasks_relation.get("non_existing_query_parameter" => "foo")
|
47
|
+
}.to raise_error /query_parameters .* do not match template parameters/
|
48
|
+
end
|
25
49
|
end
|
26
50
|
|
27
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_roa-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Schank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|