scorpio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55d580a59cb3f4bfb5e14d22b3346ce4b5788bab
4
+ data.tar.gz: 61d98721cca646e140e98ee92db03b7f407e9c6b
5
+ SHA512:
6
+ metadata.gz: 639ffe35d820fc2e5a4248a633fbd82398038f60faea79cbc5fba9efe699515b826753231e2ea513842cc726822809a0e1b25abdd26316ac970857097318fafd
7
+ data.tar.gz: d9593590fa2c85f55ead1b6cd41ac5deac54020be3accaca4251e029e19170a04266cb94066b7c8473c7b02732b85209dd333fc75de11154035ec8860e2a9d57
@@ -0,0 +1 @@
1
+ SimpleCov.start
@@ -0,0 +1,4 @@
1
+ # v0.0.1
2
+
3
+ - initial Scorpio::Model
4
+ - initial Scorpio::Model::PickleAdapter
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ethan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # Scorpio
2
+
3
+ Scorpio is a library intended to make use of the API description document format defined for Google's API discovery service for various purposes.
4
+
5
+ For background on the Google discovery service and the API description format it defines, see:
6
+
7
+ - https://developers.google.com/discovery/
8
+ - https://developers.google.com/discovery/v1/reference/
9
+
10
+ This document defines schemas using the JSON schema specification: http://json-schema.org/
11
+
12
+ ## Scorpio::Model
13
+
14
+ Scorpio::Model aims to represent RESTful resources in ruby classes with as little code as possible, given a service with a properly constructed API description.
15
+
16
+ A model representing a resource needs to be configured, minimally, with:
17
+
18
+ - the API description for the REST API
19
+ - the base URL where the service is deployed, relative to which are the paths of the API description
20
+ - the schema(s) the model represents
21
+
22
+ If the resource has HTTP methods associated with it (most, but not all resources will):
23
+
24
+ - the name of the resource corresponding to the model
25
+
26
+ When these are set, Scorpio::Model looks through the API description and dynamically sets up methods for the model:
27
+
28
+ - accessors for properties of the model defined as properties of schemas representing the resource in the description
29
+ - API method calls on the model class and, where appropriate, on the model instance
30
+
31
+ ### Example: Blog
32
+
33
+ Scorpio's tests are a good place to read example code of an API
34
+
35
+ The Blog service is defined in test/blog.rb. It uses ActiveRecord models and Sinatra to make a simple RESTful service.
36
+
37
+ Its API is described in `test/blog_description.yml`, defining the Article resource, several methods (some of which are instance methods), and schemas.
38
+
39
+ The client is set up in `test/blog_scorpio_models.rb`. The base class BlogModel defines the base_url and the api description, as well as some other optional setup done for testing.
40
+
41
+ The Article model inherits from BlogModel and is set with its resource name and the keys of its schema in the API description.
42
+
43
+ Based on those, Article gets the methods of the API description which are tested in `test/scorpio_test.rb`.
44
+
45
+ [This section will be fleshed out with more description and less just telling you, dear reader, to read the test code, as development progresses.]
46
+
47
+ ### Scorpio Model pickle adapter
48
+
49
+ Scorpio provides a pickle adapter to use models with [Pickle](https://rubygems.org/gems/pickle). `require 'scorpio/pickle_adapter'`, ensure that the pickle ORM adapter is enabled, and you should be able to create models as normal with pickle.
50
+
51
+ ## Other
52
+
53
+ The detailed, machine-interpretable description of an API provided by a properly-constructed API description document opens up numerous possibilities to automate aspects of clients and services to an API. These are planned to be implemented in Scorpio:
54
+
55
+ - generating human-readable HTML documentation for an API
56
+ - constructing test objects in a manner similar to FactoryGirl, allowing you to write tests that depend on a service without having to interact with an actual running instance of that service to run your tests
57
+ - rack middleware to test that outgoing HTTP responses are conformant to their response schemas
58
+ - rack middleware to test that incoming HTTP requests are conformant to their request schemas, and that the service handles bad requests appropriately (e.g. ensuring that for any bad request, the service responds with a 4xx error instead of 2xx).
59
+ - integrating with ORMs to generate HTTP responses that are conformant to the response schema corresponding to the resource corresponding to the ORM model
60
+ - generating model validations for ORMs
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,544 @@
1
+ # retrieved from
2
+ kind: discovery#restDescription
3
+ etag: '"C5oy1hgQsABtYOYIOXWcR3BgYqU/Pyg0A4J33Dq212hoe9BYpSm0dl4"'
4
+ discoveryVersion: v1
5
+ id: discovery:v1
6
+ name: discovery
7
+ version: v1
8
+ title: APIs Discovery Service
9
+ description: Provides information about other Google APIs, such as what APIs are available,
10
+ the resource, and method details for each API.
11
+ ownerDomain: google.com
12
+ ownerName: Google
13
+ icons:
14
+ x16: http://www.google.com/images/icons/feature/filing_cabinet_search-g16.png
15
+ x32: http://www.google.com/images/icons/feature/filing_cabinet_search-g32.png
16
+ documentationLink: https://developers.google.com/discovery/
17
+ protocol: rest
18
+ baseUrl: https://www.googleapis.com/discovery/v1/
19
+ basePath: "/discovery/v1/"
20
+ rootUrl: https://www.googleapis.com/
21
+ servicePath: discovery/v1/
22
+ batchPath: batch
23
+ parameters:
24
+ alt:
25
+ type: string
26
+ description: Data format for the response.
27
+ default: json
28
+ enum:
29
+ - json
30
+ enumDescriptions:
31
+ - Responses with Content-Type of application/json
32
+ location: query
33
+ fields:
34
+ type: string
35
+ description: Selector specifying which fields to include in a partial response.
36
+ location: query
37
+ key:
38
+ type: string
39
+ description: API key. Your API key identifies your project and provides you with
40
+ API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
41
+ location: query
42
+ oauth_token:
43
+ type: string
44
+ description: OAuth 2.0 token for the current user.
45
+ location: query
46
+ prettyPrint:
47
+ type: boolean
48
+ description: Returns response with indentations and line breaks.
49
+ default: 'true'
50
+ location: query
51
+ quotaUser:
52
+ type: string
53
+ description: Available to use for quota purposes for server-side applications.
54
+ Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
55
+ Overrides userIp if both are provided.
56
+ location: query
57
+ userIp:
58
+ type: string
59
+ description: IP address of the site where the request originates. Use this if
60
+ you want to enforce per-user limits.
61
+ location: query
62
+ schemas:
63
+ DirectoryList:
64
+ id: DirectoryList
65
+ type: object
66
+ properties:
67
+ discoveryVersion:
68
+ type: string
69
+ description: Indicate the version of the Discovery API used to generate this
70
+ doc.
71
+ default: v1
72
+ items:
73
+ type: array
74
+ description: The individual directory entries. One entry per api/version pair.
75
+ items:
76
+ type: object
77
+ properties:
78
+ description:
79
+ type: string
80
+ description: The description of this API.
81
+ discoveryLink:
82
+ type: string
83
+ description: A link to the discovery document.
84
+ discoveryRestUrl:
85
+ type: string
86
+ description: The URL for the discovery REST document.
87
+ documentationLink:
88
+ type: string
89
+ description: A link to human readable documentation for the API.
90
+ icons:
91
+ type: object
92
+ description: Links to 16x16 and 32x32 icons representing the API.
93
+ properties:
94
+ x16:
95
+ type: string
96
+ description: The URL of the 16x16 icon.
97
+ x32:
98
+ type: string
99
+ description: The URL of the 32x32 icon.
100
+ id:
101
+ type: string
102
+ description: The id of this API.
103
+ kind:
104
+ type: string
105
+ description: The kind for this response.
106
+ default: discovery#directoryItem
107
+ labels:
108
+ type: array
109
+ description: Labels for the status of this API, such as labs or deprecated.
110
+ items:
111
+ type: string
112
+ name:
113
+ type: string
114
+ description: The name of the API.
115
+ preferred:
116
+ type: boolean
117
+ description: True if this version is the preferred version to use.
118
+ title:
119
+ type: string
120
+ description: The title of this API.
121
+ version:
122
+ type: string
123
+ description: The version of the API.
124
+ kind:
125
+ type: string
126
+ description: The kind for this response.
127
+ default: discovery#directoryList
128
+ JsonSchema:
129
+ id: JsonSchema
130
+ type: object
131
+ properties:
132
+ "$ref":
133
+ type: string
134
+ description: A reference to another schema. The value of this property is
135
+ the "id" of another schema.
136
+ additionalProperties:
137
+ "$ref": JsonSchema
138
+ description: If this is a schema for an object, this property is the schema
139
+ for any additional properties with dynamic keys on this object.
140
+ annotations:
141
+ type: object
142
+ description: Additional information about this property.
143
+ properties:
144
+ required:
145
+ type: array
146
+ description: A list of methods for which this property is required on
147
+ requests.
148
+ items:
149
+ type: string
150
+ default:
151
+ type: string
152
+ description: The default value of this property (if one exists).
153
+ description:
154
+ type: string
155
+ description: A description of this object.
156
+ enum:
157
+ type: array
158
+ description: Values this parameter may take (if it is an enum).
159
+ items:
160
+ type: string
161
+ enumDescriptions:
162
+ type: array
163
+ description: The descriptions for the enums. Each position maps to the corresponding
164
+ value in the "enum" array.
165
+ items:
166
+ type: string
167
+ format:
168
+ type: string
169
+ description: 'An additional regular expression or key that helps constrain
170
+ the value. For more details see: http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.23'
171
+ id:
172
+ type: string
173
+ description: Unique identifier for this schema.
174
+ items:
175
+ "$ref": JsonSchema
176
+ description: If this is a schema for an array, this property is the schema
177
+ for each element in the array.
178
+ location:
179
+ type: string
180
+ description: Whether this parameter goes in the query or the path for REST
181
+ requests.
182
+ maximum:
183
+ type: string
184
+ description: The maximum value of this parameter.
185
+ minimum:
186
+ type: string
187
+ description: The minimum value of this parameter.
188
+ pattern:
189
+ type: string
190
+ description: 'The regular expression this parameter must conform to. Uses
191
+ Java 6 regex format: http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html'
192
+ properties:
193
+ type: object
194
+ description: If this is a schema for an object, list the schema for each property
195
+ of this object.
196
+ additionalProperties:
197
+ "$ref": JsonSchema
198
+ description: A single property of this object. The value is itself a JSON
199
+ Schema object describing this property.
200
+ readOnly:
201
+ type: boolean
202
+ description: The value is read-only, generated by the service. The value cannot
203
+ be modified by the client. If the value is included in a POST, PUT, or PATCH
204
+ request, it is ignored by the service.
205
+ repeated:
206
+ type: boolean
207
+ description: Whether this parameter may appear multiple times.
208
+ required:
209
+ type: boolean
210
+ description: Whether the parameter is required.
211
+ type:
212
+ type: string
213
+ description: 'The value type for this schema. A list of values can be found
214
+ here: http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1'
215
+ variant:
216
+ type: object
217
+ description: In a variant data type, the value of one property is used to
218
+ determine how to interpret the entire entity. Its value must exist in a
219
+ map of descriminant values to schema names.
220
+ properties:
221
+ discriminant:
222
+ type: string
223
+ description: The name of the type discriminant property.
224
+ map:
225
+ type: array
226
+ description: The map of discriminant value to schema to use for parsing..
227
+ items:
228
+ type: object
229
+ properties:
230
+ "$ref":
231
+ type: string
232
+ type_value:
233
+ type: string
234
+ RestDescription:
235
+ id: RestDescription
236
+ type: object
237
+ properties:
238
+ auth:
239
+ type: object
240
+ description: Authentication information.
241
+ properties:
242
+ oauth2:
243
+ type: object
244
+ description: OAuth 2.0 authentication information.
245
+ properties:
246
+ scopes:
247
+ type: object
248
+ description: Available OAuth 2.0 scopes.
249
+ additionalProperties:
250
+ type: object
251
+ description: The scope value.
252
+ properties:
253
+ description:
254
+ type: string
255
+ description: Description of scope.
256
+ basePath:
257
+ type: string
258
+ description: "[DEPRECATED] The base path for REST requests."
259
+ baseUrl:
260
+ type: string
261
+ description: "[DEPRECATED] The base URL for REST requests."
262
+ batchPath:
263
+ type: string
264
+ description: The path for REST batch requests.
265
+ default: batch
266
+ canonicalName:
267
+ type: string
268
+ description: Indicates how the API name should be capitalized and split into
269
+ various parts. Useful for generating pretty class names.
270
+ description:
271
+ type: string
272
+ description: The description of this API.
273
+ discoveryVersion:
274
+ type: string
275
+ description: Indicate the version of the Discovery API used to generate this
276
+ doc.
277
+ default: v1
278
+ documentationLink:
279
+ type: string
280
+ description: A link to human readable documentation for the API.
281
+ etag:
282
+ type: string
283
+ description: The ETag for this response.
284
+ readOnly: true
285
+ exponentialBackoffDefault:
286
+ type: boolean
287
+ description: Enable exponential backoff for suitable methods in the generated
288
+ clients.
289
+ features:
290
+ type: array
291
+ description: A list of supported features for this API.
292
+ items:
293
+ type: string
294
+ icons:
295
+ type: object
296
+ description: Links to 16x16 and 32x32 icons representing the API.
297
+ properties:
298
+ x16:
299
+ type: string
300
+ description: The URL of the 16x16 icon.
301
+ x32:
302
+ type: string
303
+ description: The URL of the 32x32 icon.
304
+ id:
305
+ type: string
306
+ description: The ID of this API.
307
+ kind:
308
+ type: string
309
+ description: The kind for this response.
310
+ default: discovery#restDescription
311
+ labels:
312
+ type: array
313
+ description: Labels for the status of this API, such as labs or deprecated.
314
+ items:
315
+ type: string
316
+ methods:
317
+ type: object
318
+ description: API-level methods for this API.
319
+ additionalProperties:
320
+ "$ref": RestMethod
321
+ description: An individual method description.
322
+ name:
323
+ type: string
324
+ description: The name of this API.
325
+ ownerDomain:
326
+ type: string
327
+ description: The domain of the owner of this API. Together with the ownerName
328
+ and a packagePath values, this can be used to generate a library for this
329
+ API which would have a unique fully qualified name.
330
+ ownerName:
331
+ type: string
332
+ description: The name of the owner of this API. See ownerDomain.
333
+ packagePath:
334
+ type: string
335
+ description: The package of the owner of this API. See ownerDomain.
336
+ parameters:
337
+ type: object
338
+ description: Common parameters that apply across all apis.
339
+ additionalProperties:
340
+ "$ref": JsonSchema
341
+ description: Description of a single parameter.
342
+ protocol:
343
+ type: string
344
+ description: The protocol described by this document.
345
+ default: rest
346
+ resources:
347
+ type: object
348
+ description: The resources in this API.
349
+ additionalProperties:
350
+ "$ref": RestResource
351
+ description: An individual resource description. Contains methods and sub-resources
352
+ related to this resource.
353
+ revision:
354
+ type: string
355
+ description: The version of this API.
356
+ rootUrl:
357
+ type: string
358
+ description: The root URL under which all API services live.
359
+ schemas:
360
+ type: object
361
+ description: The schemas for this API.
362
+ additionalProperties:
363
+ "$ref": JsonSchema
364
+ description: An individual schema description.
365
+ servicePath:
366
+ type: string
367
+ description: The base path for all REST requests.
368
+ title:
369
+ type: string
370
+ description: The title of this API.
371
+ version:
372
+ type: string
373
+ description: The version of this API.
374
+ version_module:
375
+ type: boolean
376
+ RestMethod:
377
+ id: RestMethod
378
+ type: object
379
+ properties:
380
+ description:
381
+ type: string
382
+ description: Description of this method.
383
+ etagRequired:
384
+ type: boolean
385
+ description: Whether this method requires an ETag to be specified. The ETag
386
+ is sent as an HTTP If-Match or If-None-Match header.
387
+ httpMethod:
388
+ type: string
389
+ description: HTTP method used by this method.
390
+ id:
391
+ type: string
392
+ description: A unique ID for this method. This property can be used to match
393
+ methods between different versions of Discovery.
394
+ mediaUpload:
395
+ type: object
396
+ description: Media upload parameters.
397
+ properties:
398
+ accept:
399
+ type: array
400
+ description: MIME Media Ranges for acceptable media uploads to this method.
401
+ items:
402
+ type: string
403
+ maxSize:
404
+ type: string
405
+ description: Maximum size of a media upload, such as "1MB", "2GB" or "3TB".
406
+ protocols:
407
+ type: object
408
+ description: Supported upload protocols.
409
+ properties:
410
+ resumable:
411
+ type: object
412
+ description: Supports the Resumable Media Upload protocol.
413
+ properties:
414
+ multipart:
415
+ type: boolean
416
+ description: True if this endpoint supports uploading multipart
417
+ media.
418
+ default: 'true'
419
+ path:
420
+ type: string
421
+ description: The URI path to be used for upload. Should be used
422
+ in conjunction with the basePath property at the api-level.
423
+ simple:
424
+ type: object
425
+ description: Supports uploading as a single HTTP request.
426
+ properties:
427
+ multipart:
428
+ type: boolean
429
+ description: True if this endpoint supports upload multipart media.
430
+ default: 'true'
431
+ path:
432
+ type: string
433
+ description: The URI path to be used for upload. Should be used
434
+ in conjunction with the basePath property at the api-level.
435
+ parameterOrder:
436
+ type: array
437
+ description: Ordered list of required parameters, serves as a hint to clients
438
+ on how to structure their method signatures. The array is ordered such that
439
+ the "most-significant" parameter appears first.
440
+ items:
441
+ type: string
442
+ parameters:
443
+ type: object
444
+ description: Details for all parameters in this method.
445
+ additionalProperties:
446
+ "$ref": JsonSchema
447
+ description: Details for a single parameter in this method.
448
+ path:
449
+ type: string
450
+ description: The URI path of this REST method. Should be used in conjunction
451
+ with the basePath property at the api-level.
452
+ request:
453
+ type: object
454
+ description: The schema for the request.
455
+ properties:
456
+ "$ref":
457
+ type: string
458
+ description: Schema ID for the request schema.
459
+ parameterName:
460
+ type: string
461
+ description: parameter name.
462
+ response:
463
+ type: object
464
+ description: The schema for the response.
465
+ properties:
466
+ "$ref":
467
+ type: string
468
+ description: Schema ID for the response schema.
469
+ scopes:
470
+ type: array
471
+ description: OAuth 2.0 scopes applicable to this method.
472
+ items:
473
+ type: string
474
+ supportsMediaDownload:
475
+ type: boolean
476
+ description: Whether this method supports media downloads.
477
+ supportsMediaUpload:
478
+ type: boolean
479
+ description: Whether this method supports media uploads.
480
+ supportsSubscription:
481
+ type: boolean
482
+ description: Whether this method supports subscriptions.
483
+ useMediaDownloadService:
484
+ type: boolean
485
+ description: Indicates that downloads from this method should use the download
486
+ service URL (i.e. "/download"). Only applies if the method supports media
487
+ download.
488
+ RestResource:
489
+ id: RestResource
490
+ type: object
491
+ properties:
492
+ methods:
493
+ type: object
494
+ description: Methods on this resource.
495
+ additionalProperties:
496
+ "$ref": RestMethod
497
+ description: Description for any methods on this resource.
498
+ resources:
499
+ type: object
500
+ description: Sub-resources on this resource.
501
+ additionalProperties:
502
+ "$ref": RestResource
503
+ description: Description for any sub-resources on this resource.
504
+ resources:
505
+ apis:
506
+ methods:
507
+ getRest:
508
+ id: discovery.apis.getRest
509
+ path: apis/{api}/{version}/rest
510
+ httpMethod: GET
511
+ description: Retrieve the description of a particular version of an api.
512
+ parameters:
513
+ api:
514
+ type: string
515
+ description: The name of the API.
516
+ required: true
517
+ location: path
518
+ version:
519
+ type: string
520
+ description: The version of the API.
521
+ required: true
522
+ location: path
523
+ parameterOrder:
524
+ - api
525
+ - version
526
+ response:
527
+ "$ref": RestDescription
528
+ list:
529
+ id: discovery.apis.list
530
+ path: apis
531
+ httpMethod: GET
532
+ description: Retrieve the list of APIs supported at this endpoint.
533
+ parameters:
534
+ name:
535
+ type: string
536
+ description: Only include APIs with the given name.
537
+ location: query
538
+ preferred:
539
+ type: boolean
540
+ description: Return only the preferred version of an API.
541
+ default: 'false'
542
+ location: query
543
+ response:
544
+ "$ref": DirectoryList