metatron_ruby_client 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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +140 -0
  3. data/config.json +13 -0
  4. data/docs/Asset.md +9 -0
  5. data/docs/AssetAttributes.md +8 -0
  6. data/docs/AssetData.md +10 -0
  7. data/docs/AssetMeta.md +8 -0
  8. data/docs/AssetResultSet.md +10 -0
  9. data/docs/AssetResultSetMeta.md +8 -0
  10. data/docs/DefaultApi.md +631 -0
  11. data/docs/Error.md +10 -0
  12. data/docs/Errors.md +8 -0
  13. data/docs/Item.md +9 -0
  14. data/docs/ItemData.md +8 -0
  15. data/docs/ItemResultSet.md +10 -0
  16. data/docs/Links.md +10 -0
  17. data/docs/Manifestation.md +9 -0
  18. data/docs/ManifestationAttributes.md +11 -0
  19. data/docs/ManifestationData.md +11 -0
  20. data/docs/ManifestationRelationships.md +10 -0
  21. data/docs/ManifestationResultSet.md +10 -0
  22. data/docs/Meta.md +10 -0
  23. data/docs/OneToManyRelationship.md +10 -0
  24. data/docs/OneToOneRelationship.md +10 -0
  25. data/docs/Resource.md +10 -0
  26. data/docs/ResourceData.md +11 -0
  27. data/docs/ResourceLink.md +9 -0
  28. data/docs/ResultSetMeta.md +10 -0
  29. data/docs/Work.md +9 -0
  30. data/docs/WorkAttributes.md +8 -0
  31. data/docs/WorkData.md +11 -0
  32. data/docs/WorkRelationships.md +8 -0
  33. data/docs/WorkResultSet.md +11 -0
  34. data/generate.sh +0 -0
  35. data/git_push.sh +52 -0
  36. data/lib/metatron_ruby_client/api/default_api.rb +727 -0
  37. data/lib/metatron_ruby_client/api_client.rb +361 -0
  38. data/lib/metatron_ruby_client/api_error.rb +34 -0
  39. data/lib/metatron_ruby_client/configuration.rb +170 -0
  40. data/lib/metatron_ruby_client/models/asset.rb +195 -0
  41. data/lib/metatron_ruby_client/models/asset_attributes.rb +212 -0
  42. data/lib/metatron_ruby_client/models/asset_data.rb +208 -0
  43. data/lib/metatron_ruby_client/models/asset_meta.rb +198 -0
  44. data/lib/metatron_ruby_client/models/asset_result_set.rb +202 -0
  45. data/lib/metatron_ruby_client/models/asset_result_set_meta.rb +196 -0
  46. data/lib/metatron_ruby_client/models/error.rb +208 -0
  47. data/lib/metatron_ruby_client/models/errors.rb +184 -0
  48. data/lib/metatron_ruby_client/models/item.rb +197 -0
  49. data/lib/metatron_ruby_client/models/item_data.rb +186 -0
  50. data/lib/metatron_ruby_client/models/item_result_set.rb +206 -0
  51. data/lib/metatron_ruby_client/models/links.rb +204 -0
  52. data/lib/metatron_ruby_client/models/manifestation.rb +197 -0
  53. data/lib/metatron_ruby_client/models/manifestation_attributes.rb +209 -0
  54. data/lib/metatron_ruby_client/models/manifestation_data.rb +235 -0
  55. data/lib/metatron_ruby_client/models/manifestation_relationships.rb +200 -0
  56. data/lib/metatron_ruby_client/models/manifestation_result_set.rb +214 -0
  57. data/lib/metatron_ruby_client/models/meta.rb +260 -0
  58. data/lib/metatron_ruby_client/models/one_to_many_relationship.rb +206 -0
  59. data/lib/metatron_ruby_client/models/one_to_one_relationship.rb +204 -0
  60. data/lib/metatron_ruby_client/models/resource.rb +281 -0
  61. data/lib/metatron_ruby_client/models/resource_data.rb +221 -0
  62. data/lib/metatron_ruby_client/models/resource_link.rb +199 -0
  63. data/lib/metatron_ruby_client/models/result_set_meta.rb +203 -0
  64. data/lib/metatron_ruby_client/models/work.rb +197 -0
  65. data/lib/metatron_ruby_client/models/work_attributes.rb +186 -0
  66. data/lib/metatron_ruby_client/models/work_data.rb +235 -0
  67. data/lib/metatron_ruby_client/models/work_relationships.rb +182 -0
  68. data/lib/metatron_ruby_client/models/work_result_set.rb +213 -0
  69. data/lib/metatron_ruby_client/version.rb +13 -0
  70. data/lib/metatron_ruby_client.rb +60 -0
  71. data/metatron_ruby_client.gemspec +31 -0
  72. data/spec/api/default_api_spec.rb +218 -0
  73. data/spec/models/asset_attributes_spec.rb +46 -0
  74. data/spec/models/asset_data_spec.rb +66 -0
  75. data/spec/models/asset_meta_spec.rb +46 -0
  76. data/spec/models/asset_result_set_spec.rb +66 -0
  77. data/spec/models/asset_spec.rb +56 -0
  78. data/spec/models/error_spec.rb +66 -0
  79. data/spec/models/errors_spec.rb +46 -0
  80. data/spec/models/item_data_spec.rb +46 -0
  81. data/spec/models/item_result_set_spec.rb +66 -0
  82. data/spec/models/item_spec.rb +56 -0
  83. data/spec/models/links_spec.rb +66 -0
  84. data/spec/models/manifestation_attributes_spec.rb +76 -0
  85. data/spec/models/manifestation_data_spec.rb +76 -0
  86. data/spec/models/manifestation_relationships_spec.rb +66 -0
  87. data/spec/models/manifestation_result_set_spec.rb +66 -0
  88. data/spec/models/manifestation_spec.rb +56 -0
  89. data/spec/models/meta_spec.rb +66 -0
  90. data/spec/models/one_to_many_relationship_spec.rb +66 -0
  91. data/spec/models/one_to_one_relationship_spec.rb +66 -0
  92. data/spec/models/resource_data_spec.rb +76 -0
  93. data/spec/models/resource_link_spec.rb +56 -0
  94. data/spec/models/resource_spec.rb +66 -0
  95. data/spec/models/result_set_meta_spec.rb +66 -0
  96. data/spec/models/work_attributes_spec.rb +46 -0
  97. data/spec/models/work_data_spec.rb +76 -0
  98. data/spec/models/work_relationships_spec.rb +46 -0
  99. data/spec/models/work_result_set_spec.rb +76 -0
  100. data/spec/models/work_spec.rb +56 -0
  101. data/stub-service/.swagger-codegen-ignore +23 -0
  102. data/stub-service/Gemfile +4 -0
  103. data/stub-service/Gemfile.lock +22 -0
  104. data/stub-service/LICENSE +201 -0
  105. data/stub-service/README.md +29 -0
  106. data/stub-service/api/default_api.rb +370 -0
  107. data/stub-service/config.ru +2 -0
  108. data/stub-service/lib/result_set.rb +37 -0
  109. data/stub-service/lib/swaggering.rb +163 -0
  110. data/stub-service/my_app.rb +13 -0
  111. data/stub-service/responses/works/includes/manifestations.assets.yaml +42 -0
  112. data/stub-service/responses/works/includes/manifestations.yaml +88 -0
  113. data/stub-service/responses/works/result_set.yaml +18 -0
  114. data/stub-service/swagger.yaml +756 -0
  115. data/swagger-codegen-cli.jar +0 -0
  116. 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"