metatron_ruby_client 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/README.md +140 -0
- data/config.json +13 -0
- data/docs/Asset.md +9 -0
- data/docs/AssetAttributes.md +8 -0
- data/docs/AssetData.md +10 -0
- data/docs/AssetMeta.md +8 -0
- data/docs/AssetResultSet.md +10 -0
- data/docs/AssetResultSetMeta.md +8 -0
- data/docs/DefaultApi.md +631 -0
- data/docs/Error.md +10 -0
- data/docs/Errors.md +8 -0
- data/docs/Item.md +9 -0
- data/docs/ItemData.md +8 -0
- data/docs/ItemResultSet.md +10 -0
- data/docs/Links.md +10 -0
- data/docs/Manifestation.md +9 -0
- data/docs/ManifestationAttributes.md +11 -0
- data/docs/ManifestationData.md +11 -0
- data/docs/ManifestationRelationships.md +10 -0
- data/docs/ManifestationResultSet.md +10 -0
- data/docs/Meta.md +10 -0
- data/docs/OneToManyRelationship.md +10 -0
- data/docs/OneToOneRelationship.md +10 -0
- data/docs/Resource.md +10 -0
- data/docs/ResourceData.md +11 -0
- data/docs/ResourceLink.md +9 -0
- data/docs/ResultSetMeta.md +10 -0
- data/docs/Work.md +9 -0
- data/docs/WorkAttributes.md +8 -0
- data/docs/WorkData.md +11 -0
- data/docs/WorkRelationships.md +8 -0
- data/docs/WorkResultSet.md +11 -0
- data/generate.sh +0 -0
- data/git_push.sh +52 -0
- data/lib/metatron_ruby_client/api/default_api.rb +727 -0
- data/lib/metatron_ruby_client/api_client.rb +361 -0
- data/lib/metatron_ruby_client/api_error.rb +34 -0
- data/lib/metatron_ruby_client/configuration.rb +170 -0
- data/lib/metatron_ruby_client/models/asset.rb +195 -0
- data/lib/metatron_ruby_client/models/asset_attributes.rb +212 -0
- data/lib/metatron_ruby_client/models/asset_data.rb +208 -0
- data/lib/metatron_ruby_client/models/asset_meta.rb +198 -0
- data/lib/metatron_ruby_client/models/asset_result_set.rb +202 -0
- data/lib/metatron_ruby_client/models/asset_result_set_meta.rb +196 -0
- data/lib/metatron_ruby_client/models/error.rb +208 -0
- data/lib/metatron_ruby_client/models/errors.rb +184 -0
- data/lib/metatron_ruby_client/models/item.rb +197 -0
- data/lib/metatron_ruby_client/models/item_data.rb +186 -0
- data/lib/metatron_ruby_client/models/item_result_set.rb +206 -0
- data/lib/metatron_ruby_client/models/links.rb +204 -0
- data/lib/metatron_ruby_client/models/manifestation.rb +197 -0
- data/lib/metatron_ruby_client/models/manifestation_attributes.rb +209 -0
- data/lib/metatron_ruby_client/models/manifestation_data.rb +235 -0
- data/lib/metatron_ruby_client/models/manifestation_relationships.rb +200 -0
- data/lib/metatron_ruby_client/models/manifestation_result_set.rb +214 -0
- data/lib/metatron_ruby_client/models/meta.rb +260 -0
- data/lib/metatron_ruby_client/models/one_to_many_relationship.rb +206 -0
- data/lib/metatron_ruby_client/models/one_to_one_relationship.rb +204 -0
- data/lib/metatron_ruby_client/models/resource.rb +281 -0
- data/lib/metatron_ruby_client/models/resource_data.rb +221 -0
- data/lib/metatron_ruby_client/models/resource_link.rb +199 -0
- data/lib/metatron_ruby_client/models/result_set_meta.rb +203 -0
- data/lib/metatron_ruby_client/models/work.rb +197 -0
- data/lib/metatron_ruby_client/models/work_attributes.rb +186 -0
- data/lib/metatron_ruby_client/models/work_data.rb +235 -0
- data/lib/metatron_ruby_client/models/work_relationships.rb +182 -0
- data/lib/metatron_ruby_client/models/work_result_set.rb +213 -0
- data/lib/metatron_ruby_client/version.rb +13 -0
- data/lib/metatron_ruby_client.rb +60 -0
- data/metatron_ruby_client.gemspec +31 -0
- data/spec/api/default_api_spec.rb +218 -0
- data/spec/models/asset_attributes_spec.rb +46 -0
- data/spec/models/asset_data_spec.rb +66 -0
- data/spec/models/asset_meta_spec.rb +46 -0
- data/spec/models/asset_result_set_spec.rb +66 -0
- data/spec/models/asset_spec.rb +56 -0
- data/spec/models/error_spec.rb +66 -0
- data/spec/models/errors_spec.rb +46 -0
- data/spec/models/item_data_spec.rb +46 -0
- data/spec/models/item_result_set_spec.rb +66 -0
- data/spec/models/item_spec.rb +56 -0
- data/spec/models/links_spec.rb +66 -0
- data/spec/models/manifestation_attributes_spec.rb +76 -0
- data/spec/models/manifestation_data_spec.rb +76 -0
- data/spec/models/manifestation_relationships_spec.rb +66 -0
- data/spec/models/manifestation_result_set_spec.rb +66 -0
- data/spec/models/manifestation_spec.rb +56 -0
- data/spec/models/meta_spec.rb +66 -0
- data/spec/models/one_to_many_relationship_spec.rb +66 -0
- data/spec/models/one_to_one_relationship_spec.rb +66 -0
- data/spec/models/resource_data_spec.rb +76 -0
- data/spec/models/resource_link_spec.rb +56 -0
- data/spec/models/resource_spec.rb +66 -0
- data/spec/models/result_set_meta_spec.rb +66 -0
- data/spec/models/work_attributes_spec.rb +46 -0
- data/spec/models/work_data_spec.rb +76 -0
- data/spec/models/work_relationships_spec.rb +46 -0
- data/spec/models/work_result_set_spec.rb +76 -0
- data/spec/models/work_spec.rb +56 -0
- data/stub-service/.swagger-codegen-ignore +23 -0
- data/stub-service/Gemfile +4 -0
- data/stub-service/Gemfile.lock +22 -0
- data/stub-service/LICENSE +201 -0
- data/stub-service/README.md +29 -0
- data/stub-service/api/default_api.rb +370 -0
- data/stub-service/config.ru +2 -0
- data/stub-service/lib/result_set.rb +37 -0
- data/stub-service/lib/swaggering.rb +163 -0
- data/stub-service/my_app.rb +13 -0
- data/stub-service/responses/works/includes/manifestations.assets.yaml +42 -0
- data/stub-service/responses/works/includes/manifestations.yaml +88 -0
- data/stub-service/responses/works/result_set.yaml +18 -0
- data/stub-service/swagger.yaml +756 -0
- data/swagger-codegen-cli.jar +0 -0
- metadata +369 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/cross_origin'
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :base_path, :api_version, :swagger_version, :format_specifier
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@api_version = '1.0'
|
10
|
+
@base_path = 'http://localhost:4567'
|
11
|
+
@swagger_version = '1.1'
|
12
|
+
@format_specifier = ".json"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Swaggering < Sinatra::Base
|
17
|
+
register Sinatra::CrossOrigin
|
18
|
+
|
19
|
+
@@routes = {}
|
20
|
+
@@configuration = Configuration.new
|
21
|
+
|
22
|
+
attr_accessor :configuration
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
get("/resources" + @@configuration.format_specifier) {
|
26
|
+
cross_origin
|
27
|
+
Swaggering.to_resource_listing
|
28
|
+
}
|
29
|
+
|
30
|
+
# for swagger.yaml
|
31
|
+
get("/swagger.yaml") {
|
32
|
+
cross_origin
|
33
|
+
File.read("./swagger.yaml");
|
34
|
+
}
|
35
|
+
|
36
|
+
@@configuration ||= Configuration.new
|
37
|
+
yield(@@configuration) if block_given?
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.add_route(method, path, swag={}, opts={}, &block)
|
41
|
+
#fullPath = swag["resourcePath"].to_s + @@configuration.format_specifier + path
|
42
|
+
fullPath = path.gsub(/{(.*?)}/, ':\1')
|
43
|
+
|
44
|
+
accepted = case method.to_s.downcase
|
45
|
+
when 'get'
|
46
|
+
get(fullPath, opts, &block)
|
47
|
+
true
|
48
|
+
when 'post'
|
49
|
+
post(fullPath, opts, &block)
|
50
|
+
true
|
51
|
+
when 'delete'
|
52
|
+
delete(fullPath, opts, &block)
|
53
|
+
true
|
54
|
+
when 'put'
|
55
|
+
put(fullPath, opts, &block)
|
56
|
+
true
|
57
|
+
else
|
58
|
+
puts "Error adding route: #{method} #{fullPath}"
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
if accepted then
|
63
|
+
resourcePath = swag["resourcePath"].to_s
|
64
|
+
ops = @@routes[resourcePath]
|
65
|
+
if ops.nil?
|
66
|
+
ops = Array.new
|
67
|
+
@@routes.merge!(resourcePath => ops)
|
68
|
+
|
69
|
+
get(resourcePath + @@configuration.format_specifier) do
|
70
|
+
cross_origin
|
71
|
+
Swaggering.to_api(resourcePath)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
swag.merge!("httpMethod" => method.to_s.upcase)
|
76
|
+
ops.push(swag)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.to_resource_listing
|
81
|
+
apis = Array.new
|
82
|
+
(@@routes.keys).each do |key|
|
83
|
+
api = {
|
84
|
+
"path" => (key + ".{format}"),
|
85
|
+
"description" => "no description"
|
86
|
+
}
|
87
|
+
apis.push api
|
88
|
+
end
|
89
|
+
|
90
|
+
resource = {
|
91
|
+
"apiVersion" => @@configuration.api_version,
|
92
|
+
"swaggerVersion" => @@configuration.swagger_version,
|
93
|
+
"apis" => apis
|
94
|
+
}
|
95
|
+
|
96
|
+
resource.to_json
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.to_api(resourcePath)
|
100
|
+
apis = {}
|
101
|
+
models = []
|
102
|
+
|
103
|
+
@@routes[resourcePath].each do |route|
|
104
|
+
endpoint = route["endpoint"].gsub(/:(\w+)(\/?)/,'{\1}\2')
|
105
|
+
path = (resourcePath + ".{format}" + endpoint)
|
106
|
+
api = apis[path]
|
107
|
+
if api.nil?
|
108
|
+
api = {"path" => path, "description" => "description", "operations" => []}
|
109
|
+
apis.merge!(path => api)
|
110
|
+
end
|
111
|
+
|
112
|
+
parameters = route["parameters"]
|
113
|
+
|
114
|
+
unless parameters.nil? then
|
115
|
+
parameters.each do |param|
|
116
|
+
av_string = param["allowableValues"]
|
117
|
+
unless av_string.nil?
|
118
|
+
if av_string.count('[') > 0
|
119
|
+
pattern = /^([A-Z]*)\[(.*)\]/
|
120
|
+
match = pattern.match av_string
|
121
|
+
case match.to_a[1]
|
122
|
+
when "LIST"
|
123
|
+
allowables = match.to_a[2].split(',')
|
124
|
+
param["allowableValues"] = {
|
125
|
+
"valueType" => "LIST",
|
126
|
+
"values" => allowables
|
127
|
+
}
|
128
|
+
when "RANGE"
|
129
|
+
allowables = match.to_a[2].split(',')
|
130
|
+
param["allowableValues"] = {
|
131
|
+
"valueType" => "RANGE",
|
132
|
+
"min" => allowables[0],
|
133
|
+
"max" => allowables[1]
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
op = {
|
142
|
+
"httpMethod" => route["httpMethod"],
|
143
|
+
"description" => route["summary"],
|
144
|
+
"responseClass" => route["responseClass"],
|
145
|
+
"notes" => route["notes"],
|
146
|
+
"nickname" => route["nickname"],
|
147
|
+
"summary" => route["summary"],
|
148
|
+
"parameters" => route["parameters"]
|
149
|
+
}
|
150
|
+
api["operations"].push(op)
|
151
|
+
end
|
152
|
+
|
153
|
+
api_listing = {
|
154
|
+
"apiVersion" => @@configuration.api_version,
|
155
|
+
"swaggerVersion" => @@configuration.swagger_version,
|
156
|
+
"basePath" => @@configuration.base_path,
|
157
|
+
"resourcePath" => resourcePath,
|
158
|
+
"apis" => apis.values,
|
159
|
+
"models" => models
|
160
|
+
}
|
161
|
+
api_listing.to_json
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require './lib/swaggering'
|
2
|
+
|
3
|
+
# only need to extend if you want special configuration!
|
4
|
+
class MyApp < Swaggering
|
5
|
+
self.configure do |config|
|
6
|
+
config.api_version = '2016-07-15T09:42:29Z'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# include the api files
|
11
|
+
Dir["./api/*.rb"].each { |file|
|
12
|
+
require file
|
13
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
include: works/includes/manifestations
|
2
|
+
relationships:
|
3
|
+
-
|
4
|
+
id: abc:0003
|
5
|
+
type: manifestations
|
6
|
+
relationship: assets
|
7
|
+
relationships:
|
8
|
+
-
|
9
|
+
id: xyz:0001
|
10
|
+
type: assets
|
11
|
+
|
12
|
+
id: abc:0001
|
13
|
+
type: manifestations
|
14
|
+
relationship: assets
|
15
|
+
relationships:
|
16
|
+
-
|
17
|
+
id: xyz:0002
|
18
|
+
type: assets
|
19
|
+
|
20
|
+
resources:
|
21
|
+
-
|
22
|
+
id: xyz:0001
|
23
|
+
type: assets
|
24
|
+
relationships:
|
25
|
+
manifestations:
|
26
|
+
data:
|
27
|
+
-
|
28
|
+
id: abc:0003
|
29
|
+
type: manifestations
|
30
|
+
attributes:
|
31
|
+
property: value of 0001
|
32
|
+
-
|
33
|
+
id: xyz:0002
|
34
|
+
type: assets
|
35
|
+
relationships:
|
36
|
+
manifestations:
|
37
|
+
data:
|
38
|
+
-
|
39
|
+
id: abc:0001
|
40
|
+
type: manifestations
|
41
|
+
attributes:
|
42
|
+
property: value of 0002
|
@@ -0,0 +1,88 @@
|
|
1
|
+
relationships:
|
2
|
+
-
|
3
|
+
id: anatomy_of_a_frog/authora
|
4
|
+
type: works
|
5
|
+
relationship: manifestations
|
6
|
+
relationships:
|
7
|
+
-
|
8
|
+
id: abc:0001
|
9
|
+
type: manifestations
|
10
|
+
-
|
11
|
+
id: abc:0002
|
12
|
+
type: manifestations
|
13
|
+
-
|
14
|
+
id: froggy_went_a_courtin/bloggsj
|
15
|
+
type: works
|
16
|
+
relationship: manifestations
|
17
|
+
relationships:
|
18
|
+
-
|
19
|
+
id: abc:0003
|
20
|
+
type: manifestations
|
21
|
+
resources:
|
22
|
+
-
|
23
|
+
id: "abc:0001"
|
24
|
+
type: "manifestations"
|
25
|
+
attributes:
|
26
|
+
identifiers:
|
27
|
+
isbn:
|
28
|
+
- "9780123456789"
|
29
|
+
place_of_publication: "Birmingham"
|
30
|
+
publishing_status: "00"
|
31
|
+
publisher:
|
32
|
+
imprint: "Talis Educational Press"
|
33
|
+
name: "Talis Information Limited"
|
34
|
+
country: xku
|
35
|
+
dates:
|
36
|
+
published: "1998"
|
37
|
+
title: Anatomy of a Frog
|
38
|
+
relationships:
|
39
|
+
works:
|
40
|
+
data:
|
41
|
+
-
|
42
|
+
id: anatomy_of_a_frog/authora
|
43
|
+
type: works
|
44
|
+
-
|
45
|
+
id: "abc:0002"
|
46
|
+
type: "manifestations"
|
47
|
+
attributes:
|
48
|
+
identifiers:
|
49
|
+
isbn:
|
50
|
+
- "978012345678X"
|
51
|
+
place_of_publication: "Birmingham"
|
52
|
+
publishing_status: "00"
|
53
|
+
publisher:
|
54
|
+
imprint: "Talis Educational Press"
|
55
|
+
name: "Talis Information Limited"
|
56
|
+
country: xku
|
57
|
+
dates:
|
58
|
+
published: "2005"
|
59
|
+
title: Anatomy of a Frog
|
60
|
+
edition_statment: 2nd edition
|
61
|
+
relationships:
|
62
|
+
works:
|
63
|
+
data:
|
64
|
+
-
|
65
|
+
id: anatomy_of_a_frog/authora
|
66
|
+
type: works
|
67
|
+
-
|
68
|
+
id: "abc:0003"
|
69
|
+
type: "manifestations"
|
70
|
+
attributes:
|
71
|
+
identifiers:
|
72
|
+
isbn:
|
73
|
+
- "9789876543210"
|
74
|
+
place_of_publication: "Tennessee"
|
75
|
+
publishing_status: "00"
|
76
|
+
publisher:
|
77
|
+
imprint: "Song books"
|
78
|
+
name: "Song books"
|
79
|
+
country: xxu
|
80
|
+
dates:
|
81
|
+
published: "1988"
|
82
|
+
title: Froggy Went a Courtin'
|
83
|
+
relationships:
|
84
|
+
works:
|
85
|
+
data:
|
86
|
+
-
|
87
|
+
id: froggy_went_a_courtin/bloggsj
|
88
|
+
type: works
|
@@ -0,0 +1,18 @@
|
|
1
|
+
meta:
|
2
|
+
count: 2
|
3
|
+
total: 2
|
4
|
+
offset: 0
|
5
|
+
limit: 10
|
6
|
+
data:
|
7
|
+
-
|
8
|
+
id: "anatomy_of_a_frog/authora"
|
9
|
+
type: "works"
|
10
|
+
attributes:
|
11
|
+
title: "Anatomy of a Frog"
|
12
|
+
authors: "Anne Author"
|
13
|
+
-
|
14
|
+
id: "froggy_went_a_courtin/bloggsj"
|
15
|
+
type: "works"
|
16
|
+
attributes:
|
17
|
+
title: "Froggy Went A Courtin'"
|
18
|
+
authors: "Joe Bloggs"
|