json_roa-client 1.0.0.pre.beta.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +179 -0
- data/README.md +35 -26
- data/Rakefile +1 -2
- data/json_roa-client.gemspec +14 -12
- data/lib/json_roa/client.rb +16 -17
- data/lib/json_roa/client/collection.rb +18 -11
- data/lib/json_roa/client/relation.rb +21 -18
- data/lib/json_roa/client/resource.rb +14 -10
- data/lib/json_roa/client/version.rb +1 -1
- data/spec/api_query_spec.rb +19 -20
- data/spec/collection_spec.rb +19 -20
- data/spec/connect_spec.rb +7 -8
- data/spec/methods_spec.rb +12 -14
- data/spec/spec_helper.rb +30 -22
- data/spec/template_expansion_spec.rb +26 -26
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b48bd9fee8fa88a388136211e2b6fcadbb635ba
|
4
|
+
data.tar.gz: 487226246eb7481ccbefd741c5d35dbc2c4cd3db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289c5648a42ddcc4a39a7b3b606d233a7560c53c054703869721731acb2af6a71f196d6b194f988605af0886e3a5c40ef2092e270cbe3632ead68a186b28d1bc
|
7
|
+
data.tar.gz: d713aab8bf657eafc4f7fbf1d4b5147d29dce8c46e055cf3352a08f1f0efb90e2c17b370cfab1e792e538e36614c53857772e72a9beef160823de9002f6fddf4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'db/**/*'
|
4
|
+
- 'config/**/*'
|
5
|
+
- 'Gemfile'
|
6
|
+
RunRailsCops: true
|
7
|
+
|
8
|
+
Lint/AmbiguousOperator:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Lint/AmbiguousRegexpLiteral:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Lint/AssignmentInCondition:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Lint/DeprecatedClassMethods:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Lint/ParenthesesAsGroupedExpression:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Lint/RescueException:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Lint/ShadowingOuterLocalVariable:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Cop supports --auto-correct.
|
30
|
+
Lint/UnusedBlockArgument:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 136
|
35
|
+
|
36
|
+
# Configuration parameters: CountComments.
|
37
|
+
Metrics/ClassLength:
|
38
|
+
Max: 128
|
39
|
+
|
40
|
+
Metrics/CyclomaticComplexity:
|
41
|
+
Max: 10
|
42
|
+
|
43
|
+
# Configuration parameters: AllowURI, URISchemes.
|
44
|
+
Metrics/LineLength:
|
45
|
+
Max: 81
|
46
|
+
|
47
|
+
# Configuration parameters: CountComments.
|
48
|
+
Metrics/MethodLength:
|
49
|
+
Max: 124
|
50
|
+
|
51
|
+
Metrics/PerceivedComplexity:
|
52
|
+
Max: 11
|
53
|
+
|
54
|
+
Style/AccessorMethodName:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Cop supports --auto-correct.
|
58
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
59
|
+
Style/AndOr:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/AsciiComments:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
66
|
+
Style/ClassAndModuleChildren:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
# Cop supports --auto-correct.
|
70
|
+
Style/ColonMethodCall:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/Documentation:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
# Cop supports --auto-correct.
|
77
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
78
|
+
Style/EmptyLinesAroundBlockBody:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
# Cop supports --auto-correct.
|
82
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
83
|
+
Style/EmptyLinesAroundClassBody:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
# Cop supports --auto-correct.
|
87
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
88
|
+
Style/EmptyLinesAroundModuleBody:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
# Configuration parameters: Exclude.
|
92
|
+
Style/FileName:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/GuardClause:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
# Configuration parameters: MaxLineLength.
|
99
|
+
Style/IfUnlessModifier:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
# Cop supports --auto-correct.
|
103
|
+
# Configuration parameters: Width.
|
104
|
+
Style/IndentationWidth:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
Style/MultilineBlockChain:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
# Cop supports --auto-correct.
|
111
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
112
|
+
Style/MultilineOperationIndentation:
|
113
|
+
Enabled: false
|
114
|
+
|
115
|
+
# Cop supports --auto-correct.
|
116
|
+
Style/Not:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
# Cop supports --auto-correct.
|
120
|
+
Style/NumericLiterals:
|
121
|
+
MinDigits: 7
|
122
|
+
|
123
|
+
# Cop supports --auto-correct.
|
124
|
+
# Configuration parameters: AllowSafeAssignment.
|
125
|
+
Style/ParenthesesAroundCondition:
|
126
|
+
Enabled: false
|
127
|
+
|
128
|
+
# Cop supports --auto-correct.
|
129
|
+
Style/RedundantBegin:
|
130
|
+
Enabled: false
|
131
|
+
|
132
|
+
# Cop supports --auto-correct.
|
133
|
+
Style/RedundantSelf:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
Style/RescueModifier:
|
137
|
+
Enabled: false
|
138
|
+
|
139
|
+
# Cop supports --auto-correct.
|
140
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
141
|
+
Style/SignalException:
|
142
|
+
Enabled: false
|
143
|
+
|
144
|
+
# Cop supports --auto-correct.
|
145
|
+
Style/SpecialGlobalVars:
|
146
|
+
Enabled: false
|
147
|
+
|
148
|
+
Style/UnlessElse:
|
149
|
+
Enabled: false
|
150
|
+
|
151
|
+
# Cop supports --auto-correct.
|
152
|
+
# Configuration parameters: WordRegex.
|
153
|
+
Style/WordArray:
|
154
|
+
MinSize: 2
|
155
|
+
|
156
|
+
# Configuration parameters: Include.
|
157
|
+
Rails/HasAndBelongsToMany:
|
158
|
+
Enabled: false
|
159
|
+
|
160
|
+
# Configuration parameters: Include.
|
161
|
+
Rails/Output:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
# Configuration parameters: Include.
|
165
|
+
Rails/ReadWriteAttribute:
|
166
|
+
Enabled: false
|
167
|
+
|
168
|
+
# Configuration parameters: Include.
|
169
|
+
Rails/Validation:
|
170
|
+
Enabled: false
|
171
|
+
|
172
|
+
|
173
|
+
# Offense count: 6
|
174
|
+
Style/ClassAndModuleCamelCase:
|
175
|
+
Enabled: false
|
176
|
+
|
177
|
+
# Offense count: 2
|
178
|
+
Style/RegexpLiteral:
|
179
|
+
MaxSlashes: 0
|
data/README.md
CHANGED
@@ -2,34 +2,12 @@
|
|
2
2
|
|
3
3
|
A ruby client for `JSON-ROA`.
|
4
4
|
|
5
|
-
##
|
5
|
+
## State
|
6
6
|
|
7
|
-
|
8
|
-
_BETA_. This library uses [Semantic Versioning][] and the current version
|
9
|
-
is [1.0.0-beta.2](./lib/json_roa/client/version.rb).
|
7
|
+
[![Code Climate][]][]
|
10
8
|
|
11
|
-
|
12
|
-
|
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
|
9
|
+
[Code Climate]: https://codeclimate.com/github/json-roa/json-roa_ruby-client/badges/gpa.svg
|
10
|
+
[![Code Climate][]]: https://codeclimate.com/github/json-roa/json-roa_ruby-client
|
33
11
|
|
34
12
|
## Usage
|
35
13
|
|
@@ -97,3 +75,34 @@ end
|
|
97
75
|
[URI Template]: http://tools.ietf.org/html/rfc6570
|
98
76
|
[Faraday]: https://github.com/lostisland/faraday
|
99
77
|
|
78
|
+
|
79
|
+
|
80
|
+
## Semantic Versioning and Rubygems Versioning
|
81
|
+
|
82
|
+
This library is _BETA_ because the [JSON-ROA specifciation][] itself is
|
83
|
+
_BETA_. This library uses [Semantic Versioning][] and the current version
|
84
|
+
is [1.0.0-beta.2](./lib/json_roa/client/version.rb).
|
85
|
+
|
86
|
+
The rubygems system [claims also to use semantic versioning][] and even *urges
|
87
|
+
gem developers to follow it*. Rubygems transforms the version as given above
|
88
|
+
into `1.0.0.pre.beta.1`. Any work using this library should specify the
|
89
|
+
following in the Gemfile
|
90
|
+
|
91
|
+
gem 'json_roa-client', '= 1.0.0.pre.beta.2'
|
92
|
+
|
93
|
+
or the following in the gemspec
|
94
|
+
|
95
|
+
spec.add_runtime_dependency 'json_roa-client', '= 1.0.0.pre.beta.2'
|
96
|
+
|
97
|
+
In the latter case, building the gem will result in a warning because of the
|
98
|
+
prerelease. You can safely ignore this warning. It is in the context of
|
99
|
+
semantic versioning misleading. However, it is important to fix the dependency
|
100
|
+
by using the `=` sign. In this case, violation would warrant a warning.
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
[JSON-ROA specifciation]: http://json-roa.github.io/specification.html
|
106
|
+
[Semantic Versioning]: http://semver.org/
|
107
|
+
[claims also to use semantic versioning]: http://guides.rubygems.org/patterns/#semantic-versioning
|
108
|
+
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/json_roa-client.gemspec
CHANGED
@@ -4,25 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'json_roa/client/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'json_roa-client'
|
8
8
|
spec.version = JSON_ROA::Client::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Thomas Schank']
|
10
|
+
spec.email = ['DrTom@schank.ch']
|
11
|
+
spec.summary = 'The Ruby JSON-ROA Client Reference Implementation'
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency 'simplecov', '~> 0.9'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3'
|
26
|
+
spec.add_development_dependency 'cider_ci-support', '= 1.1.0.pre.beta.3'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
26
28
|
|
27
29
|
spec.add_dependency 'addressable', '~> 2'
|
28
30
|
spec.add_dependency 'faraday', '~> 0.9'
|
data/lib/json_roa/client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'json_roa/client/version'
|
2
|
+
require 'json_roa/client/resource'
|
3
3
|
require 'faraday'
|
4
4
|
require 'faraday_middleware'
|
5
5
|
|
@@ -11,33 +11,32 @@ module JSON_ROA
|
|
11
11
|
env.class.class_eval do |klass|
|
12
12
|
attr_accessor :json_roa_data
|
13
13
|
end
|
14
|
-
env.json_roa_data= env.body.delete(
|
14
|
+
env.json_roa_data = env.body.delete('_json-roa')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
module Client
|
20
20
|
|
21
|
-
class << self
|
21
|
+
class << self
|
22
22
|
|
23
|
-
def connect
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
def connect(url, &_block)
|
24
|
+
@conn = Faraday.new(
|
25
|
+
url: url,
|
26
|
+
headers: { accept: 'application/json-roa+json' }) do |conn|
|
27
|
+
conn.use ::JSON_ROA::Middleware
|
28
|
+
conn.response :json, content_type: /\bjson$/
|
29
|
+
conn.request :retry
|
30
|
+
conn.use Faraday::Response::RaiseError
|
31
|
+
conn.adapter Faraday.default_adapter
|
32
|
+
end
|
33
33
|
|
34
34
|
yield @conn if block_given?
|
35
|
-
|
36
|
-
Relation.new @conn, "root", {"href" => url}
|
37
|
-
|
35
|
+
Relation.new @conn, 'root', 'href' => url
|
38
36
|
end
|
39
37
|
|
40
38
|
end
|
39
|
+
|
41
40
|
end
|
42
41
|
|
43
42
|
end
|
@@ -4,32 +4,39 @@ module JSON_ROA
|
|
4
4
|
class Collection
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
@conn= conn
|
9
|
-
@resource= resource
|
7
|
+
def initialize(conn, resource)
|
8
|
+
@conn = conn
|
9
|
+
@resource = resource
|
10
10
|
end
|
11
11
|
|
12
|
-
def each
|
12
|
+
def each(&_block)
|
13
|
+
loop do
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
relations= @resource.json_roa_data['collection']['relations'] rescue []
|
15
|
+
relations = collection_data['relations'] rescue []
|
17
16
|
|
18
17
|
relations.each do |key, data|
|
19
|
-
yield Relation.new(@conn,key,data) if block_given?
|
18
|
+
yield Relation.new(@conn, key, data) if block_given?
|
20
19
|
end
|
21
20
|
|
22
|
-
next_val=
|
21
|
+
next_val = collection_data['next'] rescue nil
|
23
22
|
|
24
23
|
if relations.empty? or (not next_val)
|
25
|
-
break
|
24
|
+
break
|
26
25
|
else
|
27
|
-
@resource= Relation.new(@conn,
|
26
|
+
@resource = Relation.new(@conn, 'next', next_val).get
|
28
27
|
end
|
29
28
|
|
30
29
|
end
|
30
|
+
end
|
31
31
|
|
32
|
+
def collection_data
|
33
|
+
@resource.json_roa_data['collection']
|
32
34
|
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
"#{self.class.name}: #{collection_data}"
|
38
|
+
end
|
39
|
+
|
33
40
|
end
|
34
41
|
|
35
42
|
end
|
@@ -8,10 +8,10 @@ module JSON_ROA
|
|
8
8
|
attr_reader :data
|
9
9
|
attr_reader :key
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
@conn= conn
|
13
|
-
@key= key
|
14
|
-
@data= data
|
11
|
+
def initialize(conn, key, data)
|
12
|
+
@conn = conn
|
13
|
+
@key = key
|
14
|
+
@data = data
|
15
15
|
|
16
16
|
Faraday::Connection::METHODS.intersection(available_methods) \
|
17
17
|
.each do |method_name|
|
@@ -19,41 +19,44 @@ module JSON_ROA
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def define_http_method
|
22
|
+
def define_http_method(method_name)
|
23
23
|
define_singleton_method method_name \
|
24
|
-
do |query_parameters={}, body=nil, headers=nil, &block|
|
24
|
+
do |query_parameters = {}, body = nil, headers = nil, &block|
|
25
25
|
run_request method_name, query_parameters, body, headers, &block
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def assert_proper_query_parameters!
|
29
|
+
def assert_proper_query_parameters!(query_parameters, template)
|
30
30
|
unless Set.new(query_parameters.keys).subset? Set.new(template.keys)
|
31
|
-
raise StandardError, [
|
32
|
-
|
33
|
-
template.keys.to_s].join(
|
31
|
+
raise StandardError, ['query_parameters', query_parameters.keys.to_s,
|
32
|
+
'do not match template parameters',
|
33
|
+
template.keys.to_s].join(' ')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def run_request
|
38
|
-
href= @data['href']
|
39
|
-
template= ::Addressable::Template.new(href)
|
37
|
+
def run_request(method, query_parameters, body, headers, &block)
|
38
|
+
href = @data['href']
|
39
|
+
template = ::Addressable::Template.new(href)
|
40
40
|
assert_proper_query_parameters! query_parameters, template
|
41
|
-
expanded_url= template.expand(query_parameters)
|
42
|
-
response
|
41
|
+
expanded_url = template.expand(query_parameters)
|
42
|
+
response = @conn.run_request( \
|
43
43
|
method.to_sym, expanded_url, body, headers, &block)
|
44
|
-
::JSON_ROA::Client::Resource.new(@conn,response)
|
44
|
+
::JSON_ROA::Client::Resource.new(@conn, response)
|
45
45
|
end
|
46
46
|
|
47
47
|
def available_methods_data
|
48
|
-
@data['methods'] ||= {
|
48
|
+
@data['methods'] ||= { 'get' => {} }
|
49
49
|
end
|
50
50
|
|
51
51
|
def available_methods
|
52
52
|
available_methods_data.keys.map(&:to_sym)
|
53
53
|
end
|
54
54
|
|
55
|
+
def to_s
|
56
|
+
"#{self.class.name}: #{@data}"
|
57
|
+
end
|
58
|
+
|
55
59
|
end
|
56
60
|
|
57
61
|
end
|
58
62
|
end
|
59
|
-
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'json_roa/client/relation'
|
2
|
+
require 'json_roa/client/collection'
|
3
3
|
|
4
4
|
module JSON_ROA
|
5
5
|
module Client
|
@@ -8,19 +8,19 @@ module JSON_ROA
|
|
8
8
|
|
9
9
|
attr_reader :response
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
@conn= conn
|
13
|
-
@response= response || conn.get
|
11
|
+
def initialize(conn, response = nil)
|
12
|
+
@conn = conn
|
13
|
+
@response = response || conn.get
|
14
14
|
end
|
15
15
|
|
16
|
-
def relation
|
17
|
-
relhash= json_roa_data['relations'][key]
|
16
|
+
def relation(key)
|
17
|
+
relhash = json_roa_data['relations'][key]
|
18
18
|
::JSON_ROA::Client::Relation.new @conn, key, relhash
|
19
19
|
end
|
20
20
|
|
21
21
|
def self_relation
|
22
22
|
::JSON_ROA::Client::Relation.new( \
|
23
|
-
@conn,
|
23
|
+
@conn, 'self', json_roa_data['self_relation']) rescue nil
|
24
24
|
end
|
25
25
|
|
26
26
|
def data
|
@@ -32,10 +32,14 @@ module JSON_ROA
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def collection
|
35
|
-
::JSON_ROA::Client::Collection.new @conn, self
|
35
|
+
::JSON_ROA::Client::Collection.new @conn, self
|
36
36
|
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
"#{self.class.name}: #{data} #{json_roa_data}"
|
40
|
+
end
|
41
|
+
|
37
42
|
end
|
38
43
|
|
39
44
|
end
|
40
45
|
end
|
41
|
-
|
data/spec/api_query_spec.rb
CHANGED
@@ -1,39 +1,38 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
+
describe 'API: traversing from root to resource to some relation' do
|
3
4
|
|
4
|
-
describe
|
5
|
+
describe 'root relation' do
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
let :root_relation do
|
9
|
-
JSON_ROA::Client.connect("/")
|
7
|
+
let :root_relation do
|
8
|
+
JSON_ROA::Client.connect('/')
|
10
9
|
end
|
11
10
|
|
12
|
-
describe
|
11
|
+
describe 'root_resource via get' do
|
13
12
|
|
14
|
-
subject(:root_resource) {root_relation.get
|
13
|
+
subject(:root_resource) { root_relation.get }
|
15
14
|
|
16
|
-
it do
|
17
|
-
expect(root_resource.class).to be== JSON_ROA::Client::Resource
|
15
|
+
it do
|
16
|
+
expect(root_resource.class).to be == JSON_ROA::Client::Resource
|
18
17
|
end
|
19
18
|
|
20
|
-
describe
|
21
|
-
subject(:data) {root_resource.data}
|
19
|
+
describe 'data' do
|
20
|
+
subject(:data) { root_resource.data }
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
it do
|
23
|
+
expect(data).to be == { 'x' => 42 }
|
24
|
+
end
|
26
25
|
|
27
26
|
end
|
28
27
|
|
29
|
-
describe
|
30
|
-
subject(:task_relation) { root_resource.relation('task')}
|
28
|
+
describe 'task relation ' do
|
29
|
+
subject(:task_relation) { root_resource.relation('task') }
|
31
30
|
|
32
|
-
it
|
33
|
-
expect(task_relation.class).to be== JSON_ROA::Client::Relation
|
31
|
+
it 'is of class Relation' do
|
32
|
+
expect(task_relation.class).to be == JSON_ROA::Client::Relation
|
34
33
|
end
|
35
|
-
|
36
|
-
it
|
34
|
+
|
35
|
+
it 'responds to get' do
|
37
36
|
expect(task_relation.respond_to? :get).to be
|
38
37
|
end
|
39
38
|
|
data/spec/collection_spec.rb
CHANGED
@@ -2,41 +2,41 @@ require_relative 'spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe JSON_ROA::Client::Collection do
|
4
4
|
|
5
|
-
let :root_relation do
|
6
|
-
JSON_ROA::Client.connect(
|
5
|
+
let :root_relation do
|
6
|
+
JSON_ROA::Client.connect('/')
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
10
|
-
subject(:tasks_resource) {root_relation.get
|
9
|
+
describe 'tasks resource via get' do
|
10
|
+
subject(:tasks_resource) { root_relation.get.relation('tasks').get }
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(tasks_resource.class).to be== JSON_ROA::Client::Resource
|
12
|
+
it 'is a resource' do
|
13
|
+
expect(tasks_resource.class).to be == JSON_ROA::Client::Resource
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'responds to collection' do
|
17
17
|
expect(tasks_resource.respond_to? :collection).to be
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
subject(:tasks_collection) {tasks_resource.collection}
|
20
|
+
describe 'tasks collection' do
|
21
|
+
subject(:tasks_collection) { tasks_resource.collection }
|
22
22
|
|
23
|
-
it
|
24
|
-
expect(tasks_collection.class).to be== JSON_ROA::Client::Collection
|
23
|
+
it 'is a collection' do
|
24
|
+
expect(tasks_collection.class).to be == JSON_ROA::Client::Collection
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
expect(tasks_collection.count).to be== 1
|
27
|
+
it 'has exactly one element' do
|
28
|
+
expect(tasks_collection.count).to be == 1
|
29
29
|
end
|
30
30
|
|
31
|
-
describe
|
32
|
-
subject(:first_task) {tasks_collection.first}
|
31
|
+
describe 'the first task' do
|
32
|
+
subject(:first_task) { tasks_collection.first }
|
33
33
|
|
34
|
-
it
|
35
|
-
expect(first_task.class).to be== JSON_ROA::Client::Relation
|
34
|
+
it 'is a relation' do
|
35
|
+
expect(first_task.class).to be == JSON_ROA::Client::Relation
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
expect(first_task.data[
|
38
|
+
it 'leads to /task/t1' do
|
39
|
+
expect(first_task.data['href']).to be == '/tasks/t1'
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -46,4 +46,3 @@ describe JSON_ROA::Client::Collection do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
49
|
-
|
data/spec/connect_spec.rb
CHANGED
@@ -3,19 +3,18 @@ require 'json_roa/client'
|
|
3
3
|
require 'pry'
|
4
4
|
|
5
5
|
describe JSON_ROA::Client do
|
6
|
-
context
|
6
|
+
context 'when calling connect' do
|
7
7
|
|
8
|
-
it
|
9
|
-
expect(JSON_ROA::Client.connect(
|
10
|
-
be== JSON_ROA::Client::Relation
|
8
|
+
it 'returns an instance of JSON_ROA::Client::Relation' do
|
9
|
+
expect(JSON_ROA::Client.connect('http://example.com').class).to \
|
10
|
+
be == JSON_ROA::Client::Relation
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
JSON_ROA::Client.connect(
|
15
|
-
expect(conn.class).to be== Faraday::Connection
|
13
|
+
it 'exposes Faraday::Connection via the block' do
|
14
|
+
JSON_ROA::Client.connect('http://example.com') do |conn|
|
15
|
+
expect(conn.class).to be == Faraday::Connection
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
data/spec/methods_spec.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'methods of the relation /tasks/t1' do
|
4
4
|
|
5
|
-
let :root_relation do
|
6
|
-
JSON_ROA::Client.connect(
|
5
|
+
let :root_relation do
|
6
|
+
JSON_ROA::Client.connect('/')
|
7
7
|
end
|
8
8
|
|
9
9
|
subject(:task1_self_relation) \
|
10
|
-
{root_relation.get
|
10
|
+
{ root_relation.get.relation('task').get('id' => 't1').self_relation }
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(task1_self_relation.class).to be== JSON_ROA::Client::Relation
|
12
|
+
it 'is a relation' do
|
13
|
+
expect(task1_self_relation.class).to be == JSON_ROA::Client::Relation
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
18
|
-
expect{task1_self_relation.get
|
16
|
+
describe 'defined get' do
|
17
|
+
it 'does not raise' do
|
18
|
+
expect { task1_self_relation.get }.not_to raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
it
|
24
|
-
expect{task1_self_relation.post
|
22
|
+
describe 'not defined post' do
|
23
|
+
it 'does raise' do
|
24
|
+
expect { task1_self_relation.post }.to raise_error
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
29
|
-
|
30
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -17,9 +17,9 @@ module JSON_ROA
|
|
17
17
|
class << self
|
18
18
|
alias_method :original_connect, :connect
|
19
19
|
|
20
|
-
def connect
|
21
|
-
res= original_connect url, &block
|
22
|
-
res.conn= test_api
|
20
|
+
def connect(url, &block)
|
21
|
+
res = original_connect url, &block
|
22
|
+
res.conn = test_api
|
23
23
|
res
|
24
24
|
end
|
25
25
|
|
@@ -27,39 +27,47 @@ module JSON_ROA
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
YAML.load_file(File.expand_path("./data/root.yml",
|
30
|
+
def root_data
|
31
|
+
YAML.load_file(File.expand_path('./data/root.yml',
|
33
32
|
File.dirname(__FILE__)))
|
34
33
|
end
|
35
34
|
|
36
|
-
def tasks_page0_data
|
37
|
-
YAML.load_file(
|
38
|
-
|
35
|
+
def tasks_page0_data
|
36
|
+
YAML.load_file(File.expand_path('./data/tasks_page0.yml',
|
37
|
+
File.dirname(__FILE__)))
|
39
38
|
end
|
40
39
|
|
41
40
|
def tasks_page1_data
|
42
|
-
YAML.load_file(
|
43
|
-
|
41
|
+
YAML.load_file(File.expand_path('./data/tasks_page1.yml',
|
42
|
+
File.dirname(__FILE__)))
|
44
43
|
end
|
45
44
|
|
46
|
-
def task1_data
|
47
|
-
YAML.load_file(
|
48
|
-
|
45
|
+
def task1_data
|
46
|
+
YAML.load_file(File.expand_path('./data/task1.yml',
|
47
|
+
File.dirname(__FILE__)))
|
49
48
|
end
|
50
49
|
|
51
|
-
|
52
50
|
def test_api
|
53
51
|
Faraday.new do |conn|
|
54
|
-
headers= {content_type:
|
52
|
+
headers = { content_type: 'application/json-roa+json' }
|
55
53
|
conn.use ::JSON_ROA::Middleware
|
56
|
-
conn.response :json, :
|
54
|
+
conn.response :json, content_type: /\bjson$/
|
57
55
|
conn.adapter :test do |stub|
|
58
|
-
stub.get('/')
|
59
|
-
|
60
|
-
|
61
|
-
stub.get('/tasks
|
62
|
-
|
56
|
+
stub.get('/') do |env|
|
57
|
+
[200, headers, root_data.to_json]
|
58
|
+
end
|
59
|
+
stub.get('/tasks/') do |env|
|
60
|
+
[200, headers, tasks_page0_data.to_json]
|
61
|
+
end
|
62
|
+
stub.get('/tasks/?page=0') do |env|
|
63
|
+
[200, headers, tasks_page0_data.to_json]
|
64
|
+
end
|
65
|
+
stub.get('/tasks/?page=1') do |env|
|
66
|
+
[200, headers, tasks_page1_data.to_json]
|
67
|
+
end
|
68
|
+
stub.get('/tasks/t1') do |env|
|
69
|
+
[200, headers, task1_data.to_json]
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
65
73
|
end
|
@@ -1,55 +1,55 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'template expansion' do
|
4
4
|
|
5
|
-
let :root_relation do
|
6
|
-
JSON_ROA::Client.connect(
|
5
|
+
let :root_relation do
|
6
|
+
JSON_ROA::Client.connect('/')
|
7
7
|
end
|
8
8
|
|
9
|
-
context
|
9
|
+
context 'task relation' do
|
10
10
|
|
11
|
-
subject(:task_relation) {root_relation.get
|
11
|
+
subject(:task_relation) { root_relation.get.relation('task') }
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(task_relation.class).to be== JSON_ROA::Client::Relation
|
13
|
+
it 'is a relation' do
|
14
|
+
expect(task_relation.class).to be == JSON_ROA::Client::Relation
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(task_relation.data['href']).to be==
|
17
|
+
it 'is templated' do
|
18
|
+
expect(task_relation.data['href']).to be == '/tasks/{id}'
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
subject(:task_resource){task_relation.get(
|
21
|
+
describe 'get with parameter to expand' do
|
22
|
+
subject(:task_resource) { task_relation.get('id' => 't1') }
|
23
23
|
|
24
|
-
it
|
25
|
-
expect(task_resource.class).to be== JSON_ROA::Client::Resource
|
26
|
-
expect(task_resource.self_relation.data[
|
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
27
|
end
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'tasks relation' do
|
34
34
|
|
35
|
-
subject(:tasks_relation) {root_relation.get
|
35
|
+
subject(:tasks_relation) { root_relation.get.relation('tasks') }
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
39
|
-
expect
|
40
|
-
|
37
|
+
describe 'get with existing parameter to expand' do
|
38
|
+
it 'does not raise an error' do
|
39
|
+
expect do
|
40
|
+
tasks_relation.get('x' => 'foo')
|
41
|
+
end.not_to raise_error
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
describe
|
45
|
-
it
|
46
|
-
expect
|
47
|
-
|
45
|
+
describe 'get with a non-existing parameter to expand' do
|
46
|
+
it 'raises an error' do
|
47
|
+
expect do
|
48
|
+
tasks_relation.get('non_existing_query_parameter' => 'foo')
|
49
|
+
end.to raise_error /query_parameters .* do not match template parameters/
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
end
|
52
54
|
|
53
55
|
end
|
54
|
-
|
55
|
-
|
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
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Schank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cider_ci-support
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.1.0.pre.beta.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.1.0.pre.beta.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: addressable
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +159,7 @@ extra_rdoc_files: []
|
|
131
159
|
files:
|
132
160
|
- ".gitignore"
|
133
161
|
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
134
163
|
- Gemfile
|
135
164
|
- LICENSE.txt
|
136
165
|
- README.md
|
@@ -166,9 +195,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
195
|
version: '0'
|
167
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
197
|
requirements:
|
169
|
-
- - "
|
198
|
+
- - ">="
|
170
199
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
200
|
+
version: '0'
|
172
201
|
requirements: []
|
173
202
|
rubyforge_project:
|
174
203
|
rubygems_version: 2.2.2
|