api_navigator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +26 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +4 -0
- data/Dangerfile +2 -0
- data/Gemfile +23 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/RELEASING.md +4 -0
- data/Rakefile +34 -0
- data/UPGRADING.md +4 -0
- data/api_navigator.gemspec +23 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/fixtures_2.rb +253 -0
- data/lib/api_navigator.rb +45 -0
- data/lib/api_navigator/attributes.rb +20 -0
- data/lib/api_navigator/collection_hash.rb +90 -0
- data/lib/api_navigator/curie.rb +47 -0
- data/lib/api_navigator/entry_point.rb +157 -0
- data/lib/api_navigator/link.rb +160 -0
- data/lib/api_navigator/link_collection.rb +63 -0
- data/lib/api_navigator/resource.rb +130 -0
- data/lib/api_navigator/resources/collection_resource.rb +41 -0
- data/lib/api_navigator/resources/member_resource.rb +63 -0
- data/lib/api_navigator/version.rb +3 -0
- data/lib/faraday/connection.rb +17 -0
- data/spec/fixtures/requests.rb +157 -0
- data/spec/fixtures/sample.json +108 -0
- data/spec/lib/api_navigator/attribute_spec.rb +36 -0
- data/spec/lib/api_navigator/collection_hash_spec.rb +71 -0
- data/spec/lib/api_navigator/entry_point_spec.rb +185 -0
- data/spec/lib/api_navigator/link_collection_spec.rb +77 -0
- data/spec/lib/api_navigator/link_spec.rb +343 -0
- data/spec/lib/api_navigator/resource_spec.rb +368 -0
- data/spec/spec_helper.rb +112 -0
- data/spec/support/book_resource.rb +10 -0
- data/spec/support/request_helper.rb +8 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 524678c0c11ba690fca89e18aeadd0f78bf5971aee1894932330c57d6a2504ae
|
4
|
+
data.tar.gz: 4c5a52483b9f8a427a2fbe0395c6fcc1afe58892771ecf37c9a35f3924baddc6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c256f751653e5744d6e8a8d9a06c9138bf243b6a506971ea82792afe801d9234c5a15037a342005527ff0a522dd3ec0ffe4fa85142249f302bdf12a9b7f5ddf4
|
7
|
+
data.tar.gz: 939e6a10298963f490eee05c1fcdd04f5f0220208d32d076033920a1ae693b88f2d8d6c8dd4af508e4c6daeeca47f0097cd841168d1c090a0efd87a2d9f0d8a7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
api_navigator
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
sudo: false
|
4
|
+
|
5
|
+
matrix:
|
6
|
+
include:
|
7
|
+
- rvm: 2.4.1
|
8
|
+
- rvm: 2.4.1
|
9
|
+
script:
|
10
|
+
- bundle exec danger
|
11
|
+
- rvm: jruby-9.1.12.0
|
12
|
+
- rvm: jruby-head
|
13
|
+
- rvm: 2.2.7
|
14
|
+
- rvm: 2.3.4
|
15
|
+
- rvm: rbx-2
|
16
|
+
- rvm: ruby-head
|
17
|
+
allow_failures:
|
18
|
+
- rvm: ruby-head
|
19
|
+
- rvm: jruby-head
|
20
|
+
- rvm: rbx-2
|
21
|
+
|
22
|
+
before_install:
|
23
|
+
- gem update --system
|
24
|
+
- gem install bundler
|
25
|
+
|
26
|
+
bundler_args: --without development
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
data/Dangerfile
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# NOTE: this is temporary until Bundler 2.0 changes how github: references work.
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo['/'] ? repo : "#{repo}/#{repo}"}.git" }
|
3
|
+
|
4
|
+
source 'https://rubygems.org'
|
5
|
+
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'pry'
|
10
|
+
gem 'pry-byebug', '~> 3.4'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rubocop', '~> 0.50.0', require: false
|
13
|
+
gem 'simplecov', require: false
|
14
|
+
gem 'rspec', '~> 3.7'
|
15
|
+
gem 'guard-rspec'
|
16
|
+
gem 'factory_bot_rails'
|
17
|
+
gem 'faker'
|
18
|
+
end
|
19
|
+
|
20
|
+
group :test do
|
21
|
+
gem 'turn'
|
22
|
+
gem 'webmock'
|
23
|
+
end
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012-2018 Oriol Gual, Codegram Technologies and Contributors
|
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
data/RELEASING.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup :default, :test, :development
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
if ENV['COVERAGE']
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '/test/'
|
12
|
+
add_filter '/features/'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'rake/testtask'
|
17
|
+
|
18
|
+
Rake::TestTask.new(:test) do |t|
|
19
|
+
t.libs << 'lib'
|
20
|
+
t.libs << 'test'
|
21
|
+
t.pattern = 'test/**/*_test.rb'
|
22
|
+
t.verbose = false
|
23
|
+
t.warning = true
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'runs the whole spinach suite'
|
27
|
+
task :spinach do
|
28
|
+
ruby '-S spinach'
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'rubocop/rake_task'
|
32
|
+
RuboCop::RakeTask.new(:rubocop)
|
33
|
+
|
34
|
+
task default: %i[test spinach rubocop]
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../lib/api_navigator/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Martin Schweizer']
|
6
|
+
gem.email = ['martin@verticonaut.me']
|
7
|
+
gem.description = 'ApiNavigator base on api_navigator from Oriol Gual'
|
8
|
+
gem.summary = ''
|
9
|
+
gem.homepage = 'https://github.com/verticonaut/api_navigator/'
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- rspec/*`.split("\n")
|
13
|
+
gem.name = 'api_navigator'
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = ApiNavigator::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'faraday', '>= 0.9.0'
|
18
|
+
gem.add_dependency 'faraday_middleware'
|
19
|
+
gem.add_dependency 'faraday_hal_middleware'
|
20
|
+
gem.add_dependency 'uri_template'
|
21
|
+
gem.add_dependency 'net-http-digest_auth'
|
22
|
+
gem.add_dependency 'faraday-digestauth'
|
23
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "irb/completion"
|
5
|
+
require "api_navigator"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require "pry"
|
12
|
+
|
13
|
+
Dir['spec/fixtures/**/*.*'].each { |f| puts f: f; require_relative "../#{f}" }
|
14
|
+
|
15
|
+
Pry.start
|
data/bin/setup
ADDED
data/fixtures_2.rb
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Spinach
|
4
|
+
module Fixtures2
|
5
|
+
|
6
|
+
def root_response
|
7
|
+
'{
|
8
|
+
"_links": {
|
9
|
+
"self": { "href": "/" },
|
10
|
+
"posts": { "href": "/posts" },
|
11
|
+
"search": { "href": "/search{?q}", "templated": true },
|
12
|
+
"tagged": { "href": "/search{?tags*}", "templated": true },
|
13
|
+
"api:authors": { "href": "/authors" },
|
14
|
+
"next": { "href": "/page2" }
|
15
|
+
}
|
16
|
+
}'
|
17
|
+
end
|
18
|
+
|
19
|
+
# collection resource
|
20
|
+
def posts_response
|
21
|
+
response = {
|
22
|
+
data: [
|
23
|
+
{
|
24
|
+
data: {
|
25
|
+
title: 'Book 1',
|
26
|
+
body: 'Book 1 Body',
|
27
|
+
year: 1999,
|
28
|
+
publisher: {
|
29
|
+
data: {
|
30
|
+
name: 'Manning Publisher',
|
31
|
+
},
|
32
|
+
_links: {
|
33
|
+
self: {
|
34
|
+
href: "http://localhost:3000/sample/publisher/1",
|
35
|
+
}
|
36
|
+
},
|
37
|
+
_meta: { type: "publisher" }
|
38
|
+
},
|
39
|
+
},
|
40
|
+
_links: {
|
41
|
+
self: {
|
42
|
+
href: "http://localhost:3000/sample/books/1",
|
43
|
+
},
|
44
|
+
authors: {
|
45
|
+
href: "http://localhost:3000/sample/book/1/authors",
|
46
|
+
},
|
47
|
+
publisher: {
|
48
|
+
href: "http://localhost:3000/sample/book/1/publisher",
|
49
|
+
},
|
50
|
+
},
|
51
|
+
_meta: { type: "book" }
|
52
|
+
},
|
53
|
+
{
|
54
|
+
data: {
|
55
|
+
title: 'Book 2',
|
56
|
+
body: 'Book 2 Body',
|
57
|
+
year: 1999,
|
58
|
+
publisher: {
|
59
|
+
data: {
|
60
|
+
name: 'PragBook Publisher',
|
61
|
+
},
|
62
|
+
_links: {
|
63
|
+
self: {
|
64
|
+
href: "http://localhost:3000/sample/publisher/2",
|
65
|
+
}
|
66
|
+
},
|
67
|
+
_meta: { type: "publisher" }
|
68
|
+
},
|
69
|
+
},
|
70
|
+
_links: {
|
71
|
+
self: {
|
72
|
+
href: "http://localhost:3000/sample/books/2",
|
73
|
+
},
|
74
|
+
authors: {
|
75
|
+
href: "http://localhost:3000/sample/book/2/authors",
|
76
|
+
},
|
77
|
+
publisher: {
|
78
|
+
href: "http://localhost:3000/sample/book/2/publisher",
|
79
|
+
},
|
80
|
+
},
|
81
|
+
_meta: { type: "book" }
|
82
|
+
},
|
83
|
+
],
|
84
|
+
_links: {
|
85
|
+
self: {
|
86
|
+
href: "http://localhost:3000/sample/books",
|
87
|
+
}
|
88
|
+
},
|
89
|
+
_meta: { total_number_of: 22 }
|
90
|
+
}
|
91
|
+
|
92
|
+
response
|
93
|
+
end
|
94
|
+
|
95
|
+
# singular resource
|
96
|
+
def post_response
|
97
|
+
response = {
|
98
|
+
data: {
|
99
|
+
title: 'Book 1',
|
100
|
+
body: 'Book 1 Body',
|
101
|
+
year: 1999,
|
102
|
+
publisher: {
|
103
|
+
data: {
|
104
|
+
name: 'Manning Publisher',
|
105
|
+
},
|
106
|
+
_links: {
|
107
|
+
self: {
|
108
|
+
href: "http://localhost:3000/sample/publisher/1",
|
109
|
+
}
|
110
|
+
},
|
111
|
+
_meta: { type: "book" }
|
112
|
+
},
|
113
|
+
},
|
114
|
+
_links: {
|
115
|
+
self: {
|
116
|
+
href: "http://localhost:3000/sample/books/1",
|
117
|
+
},
|
118
|
+
authors: {
|
119
|
+
href: "http://localhost:3000/sample/book/1/authors",
|
120
|
+
},
|
121
|
+
publisher: {
|
122
|
+
href: "http://localhost:3000/sample/book/1/publisher",
|
123
|
+
},
|
124
|
+
},
|
125
|
+
_meta: { type: "book" }
|
126
|
+
}
|
127
|
+
|
128
|
+
response
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
__END__
|
135
|
+
# singular resource - nested
|
136
|
+
{
|
137
|
+
data: {
|
138
|
+
attr1: 'ffg1',
|
139
|
+
attr2: 'ffg2',
|
140
|
+
attr3: 'ffg2',
|
141
|
+
attr4: 'ffg4',
|
142
|
+
publisher: {
|
143
|
+
data: { name: 'Publisher 1'},
|
144
|
+
_meta: {
|
145
|
+
type: 'publisher'
|
146
|
+
}
|
147
|
+
},
|
148
|
+
authors: [
|
149
|
+
{
|
150
|
+
data: {
|
151
|
+
name: 'Author1'
|
152
|
+
},
|
153
|
+
_links: {
|
154
|
+
authors: {
|
155
|
+
rel: 'self',
|
156
|
+
href: "http:…/author/1"
|
157
|
+
}
|
158
|
+
},
|
159
|
+
_meta: {
|
160
|
+
type: 'author'
|
161
|
+
}
|
162
|
+
},
|
163
|
+
{
|
164
|
+
data: {
|
165
|
+
name: 'Author2'
|
166
|
+
},
|
167
|
+
_links: {
|
168
|
+
self: {
|
169
|
+
href: "http:…/author/1"
|
170
|
+
}
|
171
|
+
authors: {
|
172
|
+
href: "http:…/authors"
|
173
|
+
}
|
174
|
+
books: {
|
175
|
+
href: "http:…/author1/books"
|
176
|
+
}
|
177
|
+
},
|
178
|
+
_meta: {
|
179
|
+
type: 'author'
|
180
|
+
}
|
181
|
+
}
|
182
|
+
]
|
183
|
+
},
|
184
|
+
_links: {
|
185
|
+
authors: {
|
186
|
+
href: "http:…/authors"
|
187
|
+
}
|
188
|
+
},
|
189
|
+
_meta: {
|
190
|
+
type: 'resource_type'
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
# singular resource - nested ~/authors.json?…
|
195
|
+
{
|
196
|
+
data: [
|
197
|
+
{
|
198
|
+
data: {
|
199
|
+
name: 'Author1'
|
200
|
+
},
|
201
|
+
_links: {
|
202
|
+
authors: {
|
203
|
+
rel: 'self',
|
204
|
+
href: "http:…/author/1"
|
205
|
+
}
|
206
|
+
},
|
207
|
+
_meta: {
|
208
|
+
type: 'author'
|
209
|
+
}
|
210
|
+
},
|
211
|
+
{
|
212
|
+
data: {
|
213
|
+
name: 'Author2'
|
214
|
+
},
|
215
|
+
_links: {
|
216
|
+
authors: {
|
217
|
+
rel: 'self',
|
218
|
+
href: "http:…/author/1"
|
219
|
+
}
|
220
|
+
},
|
221
|
+
_meta: {
|
222
|
+
type: 'author'
|
223
|
+
}
|
224
|
+
}
|
225
|
+
]
|
226
|
+
_links: {
|
227
|
+
self: {
|
228
|
+
name: 'Authors',
|
229
|
+
href: "http:…/authors"
|
230
|
+
}
|
231
|
+
},
|
232
|
+
_meta: {
|
233
|
+
type: 'resource_type'
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
# js-compact
|
240
|
+
{
|
241
|
+
attr1: 'ffg1',
|
242
|
+
attr2: 'ffg2',
|
243
|
+
attr3: 'ffg2',
|
244
|
+
attr4: 'ffg4',
|
245
|
+
publisher: { name: 'Publisher 1'},
|
246
|
+
authors: [
|
247
|
+
{ name: 'Author1' },
|
248
|
+
{ name: 'Author2' }
|
249
|
+
]
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
# articles?_include="{authors: 'person'},publisher"
|