apiture 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +20 -0
  5. data/README.md +38 -0
  6. data/Rakefile +6 -0
  7. data/apiture.gemspec +30 -0
  8. data/lib/apiture.rb +24 -0
  9. data/lib/apiture/api_base.rb +27 -0
  10. data/lib/apiture/api_builder.rb +196 -0
  11. data/lib/apiture/api_error.rb +3 -0
  12. data/lib/apiture/api_group.rb +28 -0
  13. data/lib/apiture/data_model.rb +24 -0
  14. data/lib/apiture/endpoint.rb +25 -0
  15. data/lib/apiture/middleware/auth/api_key.rb +39 -0
  16. data/lib/apiture/middleware/auth/basic.rb +25 -0
  17. data/lib/apiture/middleware/auth/oauth2.rb +31 -0
  18. data/lib/apiture/middleware/convert_json_body.rb +15 -0
  19. data/lib/apiture/middleware/debug.rb +20 -0
  20. data/lib/apiture/middleware/set_body_parameter.rb +20 -0
  21. data/lib/apiture/middleware/set_header.rb +15 -0
  22. data/lib/apiture/middleware/set_parameter_base.rb +37 -0
  23. data/lib/apiture/middleware/set_path_parameter.rb +18 -0
  24. data/lib/apiture/middleware/set_query_parameter.rb +13 -0
  25. data/lib/apiture/middleware_builder.rb +15 -0
  26. data/lib/apiture/middleware_stack.rb +21 -0
  27. data/lib/apiture/request_context.rb +103 -0
  28. data/lib/apiture/swagger/data_type_field.rb +25 -0
  29. data/lib/apiture/swagger/definition.rb +20 -0
  30. data/lib/apiture/swagger/external_docs.rb +10 -0
  31. data/lib/apiture/swagger/info.rb +14 -0
  32. data/lib/apiture/swagger/node.rb +149 -0
  33. data/lib/apiture/swagger/operation.rb +32 -0
  34. data/lib/apiture/swagger/parameter.rb +35 -0
  35. data/lib/apiture/swagger/parser.rb +148 -0
  36. data/lib/apiture/swagger/path.rb +37 -0
  37. data/lib/apiture/swagger/property.rb +15 -0
  38. data/lib/apiture/swagger/security.rb +21 -0
  39. data/lib/apiture/swagger/security_definition.rb +23 -0
  40. data/lib/apiture/swagger/specification.rb +31 -0
  41. data/lib/apiture/uri.rb +36 -0
  42. data/lib/apiture/utils/inflections.rb +46 -0
  43. data/lib/apiture/version.rb +3 -0
  44. data/spec/apiture/api_builder_spec.rb +20 -0
  45. data/spec/apiture/swagger/parser_spec.rb +107 -0
  46. data/spec/apiture/swagger/specification_spec.rb +19 -0
  47. data/spec/apiture_spec.rb +228 -0
  48. data/spec/files/github.json +186 -0
  49. data/spec/files/harvest.json +75 -0
  50. data/spec/files/honeybadger.json +80 -0
  51. data/spec/files/mandrill.json +502 -0
  52. data/spec/files/pivotal_tracker.json +94 -0
  53. data/spec/files/slack.json +88 -0
  54. data/spec/files/uber.json +43 -0
  55. data/spec/fixtures/vcr_cassettes/github_checkAuthorization.yml +70 -0
  56. data/spec/fixtures/vcr_cassettes/github_getUser.yml +82 -0
  57. data/spec/fixtures/vcr_cassettes/harvest_invoiceList.yml +85 -0
  58. data/spec/fixtures/vcr_cassettes/honeybadger.yml +98 -0
  59. data/spec/fixtures/vcr_cassettes/mandrill_messageSend.yml +44 -0
  60. data/spec/fixtures/vcr_cassettes/mandrill_userPing.yml +44 -0
  61. data/spec/fixtures/vcr_cassettes/pivotal_tracker_create_story.yml +61 -0
  62. data/spec/fixtures/vcr_cassettes/slack.yml +43 -0
  63. data/spec/fixtures/vcr_cassettes/uber_getProducts.yml +60 -0
  64. data/spec/spec_helper.rb +11 -0
  65. metadata +241 -0
@@ -0,0 +1,94 @@
1
+ {
2
+ "swagger": "2.0",
3
+
4
+ "info": {
5
+ "title": "PivotalTracker",
6
+ "description": "Agile project management tool for software teams",
7
+ "version": "5"
8
+ },
9
+
10
+ "host": "www.pivotaltracker.com",
11
+
12
+ "basePath": "/services/v5",
13
+
14
+ "schemes": ["https"],
15
+
16
+ "produces": ["application/json"],
17
+
18
+ "paths": {
19
+ "/projects/{projectId}/stories": {
20
+ "post": {
21
+ "summary": "Create a new story",
22
+ "externalDocs": {
23
+ "url": "https://www.pivotaltracker.com/help/api/rest/v5#projects_project_id_stories_post"
24
+ },
25
+ "operationId": "createStory",
26
+ "parameters": [
27
+ {
28
+ "name": "projectId",
29
+ "in": "path",
30
+ "required": true,
31
+ "type": "string"
32
+ },
33
+ {
34
+ "name": "story",
35
+ "in": "body",
36
+ "required": true,
37
+ "schema": "NewStory"
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ },
43
+
44
+ "definitions": {
45
+ "NewStory": {
46
+ "title": "New Story",
47
+ "type": "object",
48
+ "properties": {
49
+ "cl_numbers": { "type": "string" },
50
+ "current_state": {
51
+ "type": "string",
52
+ "enum": [
53
+ "accepted",
54
+ "delivered",
55
+ "finished",
56
+ "started",
57
+ "rejected",
58
+ "unstarted",
59
+ "unscheduled"
60
+ ]
61
+ },
62
+ "external_id": { "type": "string" },
63
+ "deadline": { "type": "string" },
64
+ "description": { "type": "string" },
65
+ "estimate": { "type": "string" },
66
+ "integration_id": { "type": "string" },
67
+ "planned_iteration_number": { "type": "string" },
68
+ "requested_by_id": { "type": "string" },
69
+ "accepted_at": { "type": "string" },
70
+ "before_id": { "type": "string" },
71
+ "created_at": { "type": "string" },
72
+ "after_id": { "type": "string" },
73
+ "name": { "type": "string" },
74
+ "story_type": {
75
+ "type": "string",
76
+ "enum": [ "feature", "bug", "chore", "release" ]
77
+ }
78
+ },
79
+ "required": [ "name" ]
80
+ }
81
+ },
82
+
83
+ "securityDefinitions": {
84
+ "apiToken": {
85
+ "type": "apiKey",
86
+ "name": "X-TrackerToken",
87
+ "in": "header"
88
+ }
89
+ },
90
+
91
+ "security": {
92
+ "apiToken": []
93
+ }
94
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "swagger": "2.0",
3
+
4
+ "info": {
5
+ "title": "Slack",
6
+ "description": "Slack Incoming Webhook",
7
+ "version": "1"
8
+ },
9
+
10
+ "host": "hooks.slack.com",
11
+
12
+ "basePath": "/services",
13
+
14
+ "schemes": ["https"],
15
+
16
+ "produces": ["application/json"],
17
+
18
+ "paths": {
19
+ "/{path}": {
20
+ "post": {
21
+ "summary": "Post message into Slack",
22
+ "operationId": "postMessage",
23
+ "parameters": [
24
+ {
25
+ "name": "path",
26
+ "in": "path",
27
+ "required": true,
28
+ "type": "string"
29
+ },
30
+ {
31
+ "name": "payload",
32
+ "in": "body",
33
+ "required": true,
34
+ "schema": "Payload"
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ },
40
+
41
+ "definitions": {
42
+ "Payload": {
43
+ "title": "Payload",
44
+ "type": "object",
45
+ "required": [ "text" ],
46
+ "properties": {
47
+ "text": { "type": "string" },
48
+ "username": { "type": "string" },
49
+ "icon_url": { "type": "string" },
50
+ "icon_emoji": { "type": "string" },
51
+ "channel": { "type": "string" },
52
+ "attachments": {
53
+ "type": "array",
54
+ "items": {
55
+ "$ref": "#/definitions/Attachment"
56
+ }
57
+ }
58
+ }
59
+ },
60
+ "Attachment": {
61
+ "title": "Attachment",
62
+ "type": "object",
63
+ "required": ["fallback"],
64
+ "properties": {
65
+ "fallback": { "type": "string" },
66
+ "text": { "type": "string" },
67
+ "pretext": { "type": "string" },
68
+ "color": { "type": "string" },
69
+ "fields": {
70
+ "type": "array",
71
+ "items": {
72
+ "$ref": "#/definitions/AttachmentField"
73
+ }
74
+ }
75
+ },
76
+ "AttachmentField": {
77
+ "title": "Attachment Field",
78
+ "type": "object",
79
+ "required": ["title"],
80
+ "properties": {
81
+ "title": { "type": "string" },
82
+ "value": { "type": "string" },
83
+ "short": { "type": "boolean" }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "swagger": "2.0",
3
+
4
+ "info": {
5
+ "title": "Uber",
6
+ "version": "1"
7
+ },
8
+
9
+ "host": "api.uber.com",
10
+
11
+ "basePath": "/v1",
12
+
13
+ "schemes": ["https"],
14
+
15
+ "produces": ["application/json"],
16
+
17
+ "securityDefinitions": {
18
+ "server_token": {
19
+ "type": "apiKey",
20
+ "name": "Authorization",
21
+ "in": "header",
22
+ "x-format": "Token %s"
23
+ }
24
+ },
25
+
26
+ "paths": {
27
+ "/products": {
28
+ "get": {
29
+ "summary": "Return information about products offered at a given location.",
30
+ "operationId": "getProducts",
31
+ "parameters": [{
32
+ "name": "latitude",
33
+ "in": "query",
34
+ "type": "number"
35
+ }, {
36
+ "name": "longitude",
37
+ "in": "query",
38
+ "type": "number"
39
+ }]
40
+ }
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,70 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://afakeclientid:afakeclientsecret@api.github.com/applications/afakeclientid/tokens/afaketoken
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - apiture-rb/0.1.3
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - GitHub.com
23
+ Date:
24
+ - Sat, 16 Apr 2016 03:56:12 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Status:
30
+ - 200 OK
31
+ X-Ratelimit-Limit:
32
+ - '5000'
33
+ X-Ratelimit-Remaining:
34
+ - '4995'
35
+ X-Ratelimit-Reset:
36
+ - '1460780527'
37
+ Cache-Control:
38
+ - public, max-age=60, s-maxage=60
39
+ Vary:
40
+ - Accept
41
+ - Accept-Encoding
42
+ Etag:
43
+ - W/"fcf97fafc3a143f7521813244d11fa3b"
44
+ X-Github-Media-Type:
45
+ - github.v3
46
+ Access-Control-Expose-Headers:
47
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
48
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
49
+ Access-Control-Allow-Origin:
50
+ - "*"
51
+ Content-Security-Policy:
52
+ - default-src 'none'
53
+ Strict-Transport-Security:
54
+ - max-age=31536000; includeSubdomains; preload
55
+ X-Content-Type-Options:
56
+ - nosniff
57
+ X-Frame-Options:
58
+ - deny
59
+ X-Xss-Protection:
60
+ - 1; mode=block
61
+ X-Served-By:
62
+ - bae57931a6fe678a3dffe9be8e7819c8
63
+ X-Github-Request-Id:
64
+ - AC00357F:1559F:FA3B3AE:5711B7DC
65
+ body:
66
+ encoding: ASCII-8BIT
67
+ string: '{"id":23378498,"url":"https://api.github.com/authorizations/23378498","app":{"name":"IncomingHQ","url":"http://incominghq.com","client_id":"afakeclientid"},"token":"afaketoken","hashed_token":"22289e4c0f521282ee035d6dc7cd4e265c3621d5baa0922a6bcd82fd52e2ea02","token_last_eight":"88ad08bc","note":null,"note_url":null,"created_at":"2015-10-18T14:18:18Z","updated_at":"2015-10-29T22:02:09Z","scopes":["repo"],"fingerprint":null,"user":{"login":"cyu","id":2431,"avatar_url":"https://avatars.githubusercontent.com/u/2431?v=3","gravatar_id":"","url":"https://api.github.com/users/cyu","html_url":"https://github.com/cyu","followers_url":"https://api.github.com/users/cyu/followers","following_url":"https://api.github.com/users/cyu/following{/other_user}","gists_url":"https://api.github.com/users/cyu/gists{/gist_id}","starred_url":"https://api.github.com/users/cyu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyu/subscriptions","organizations_url":"https://api.github.com/users/cyu/orgs","repos_url":"https://api.github.com/users/cyu/repos","events_url":"https://api.github.com/users/cyu/events{/privacy}","received_events_url":"https://api.github.com/users/cyu/received_events","type":"User","site_admin":false}}'
68
+ http_version:
69
+ recorded_at: Sat, 16 Apr 2016 03:56:12 GMT
70
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,82 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.github.com/user
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - apiture-rb/0.1.3
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Bearer afaketoken
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - GitHub.com
23
+ Date:
24
+ - Sun, 16 Aug 2015 11:44:41 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Content-Length:
28
+ - '1097'
29
+ Status:
30
+ - 200 OK
31
+ X-Ratelimit-Limit:
32
+ - '5000'
33
+ X-Ratelimit-Remaining:
34
+ - '4999'
35
+ X-Ratelimit-Reset:
36
+ - '1439729081'
37
+ Cache-Control:
38
+ - private, max-age=60, s-maxage=60
39
+ Last-Modified:
40
+ - Thu, 30 Jul 2015 10:31:45 GMT
41
+ Etag:
42
+ - '"9d21057f20dc65085a97b97880dba697"'
43
+ X-Oauth-Scopes:
44
+ - read:org, repo:status
45
+ X-Accepted-Oauth-Scopes:
46
+ - ''
47
+ X-Oauth-Client-Id:
48
+ - xxx
49
+ Vary:
50
+ - Accept, Authorization, Cookie, X-GitHub-OTP
51
+ - Accept-Encoding
52
+ X-Github-Media-Type:
53
+ - github.v3; format=json
54
+ X-Xss-Protection:
55
+ - 1; mode=block
56
+ X-Frame-Options:
57
+ - deny
58
+ Content-Security-Policy:
59
+ - default-src 'none'
60
+ Access-Control-Allow-Credentials:
61
+ - 'true'
62
+ Access-Control-Expose-Headers:
63
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
64
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
65
+ Access-Control-Allow-Origin:
66
+ - "*"
67
+ X-Github-Request-Id:
68
+ - 49CF3EF9:7C7A:4DC7847:55D077A9
69
+ Strict-Transport-Security:
70
+ - max-age=31536000; includeSubdomains; preload
71
+ X-Content-Type-Options:
72
+ - nosniff
73
+ X-Served-By:
74
+ - 173530fed4bbeb1e264b2ed22e8b5c20
75
+ body:
76
+ encoding: UTF-8
77
+ string: '{"login":"cyu","id":2431,"avatar_url":"https://avatars.githubusercontent.com/u/2431?v=3","gravatar_id":"","url":"https://api.github.com/users/cyu","html_url":"https://github.com/cyu","followers_url":"https://api.github.com/users/cyu/followers","following_url":"https://api.github.com/users/cyu/following{/other_user}","gists_url":"https://api.github.com/users/cyu/gists{/gist_id}","starred_url":"https://api.github.com/users/cyu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyu/subscriptions","organizations_url":"https://api.github.com/users/cyu/orgs","repos_url":"https://api.github.com/users/cyu/repos","events_url":"https://api.github.com/users/cyu/events{/privacy}","received_events_url":"https://api.github.com/users/cyu/received_events","type":"User","site_admin":false,"name":"Calvin
78
+ Yu","company":"Scoutmob","blog":"http://blog.codeeg.com","location":"Atlanta,
79
+ GA","email":"me@sourcebender.com","hireable":null,"bio":null,"public_repos":54,"public_gists":18,"followers":30,"following":7,"created_at":"2008-03-06T18:28:14Z","updated_at":"2015-07-30T10:31:45Z"}'
80
+ http_version:
81
+ recorded_at: Sun, 16 Aug 2015 11:44:42 GMT
82
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,85 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://fakedomain.harvestapp.com/invoices
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - apiture-rb/0.1.4
12
+ Accept:
13
+ - application/json
14
+ Authorization:
15
+ - Bearer faketoken
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Wed, 04 Nov 2015 14:19:44 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 200 OK
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ Cache-Control:
40
+ - private, no-store, no-cache, max-age=0, must-revalidate
41
+ P3p:
42
+ - 'CP="Our privacy policy is available online: https://www.getharvest.com/services/privacy-policy"'
43
+ Content-Security-Policy:
44
+ - referrer origin-when-crossorigin
45
+ Content-Security-Policy-Report-Only:
46
+ - report-uri /csp_reports?authenticity_token=SFA%2FoMXIX0JQuAwnNhuaumd%2FRxxSAdFoVdI%2Bzc4Gbo4%3D;
47
+ default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' cache.harvestapp.com
48
+ www.googletagmanager.com www.googleadservices.com platform.twitter.com *.google-analytics.com
49
+ www.google.com js-agent.newrelic.com *.nr-data.net js.appcenter.intuit.com
50
+ ajax.googleapis.com; style-src 'self' 'unsafe-inline' cache.harvestapp.com
51
+ www.google.com js.appcenter.intuit.com
52
+ Access-Control-Allow-Origin:
53
+ - http://localhost:4567/auth/swagger/callback
54
+ Access-Control-Expose-Headers:
55
+ - X-Served-From,X-Company-Version,X-Asked-With-Method
56
+ Access-Control-Allow-Headers:
57
+ - Content-Type,Accept
58
+ Access-Control-Max-Age:
59
+ - '1200'
60
+ X-Served-From:
61
+ - https://fakedomain.harvestapp.com/invoices
62
+ Set-Cookie:
63
+ - _harvest_sess=UXR4Q0E4Y3c2RDJaRlFTVzlEWTNLTGErRnlDOEFtcTMvZHZFSEordXJLc3BBOXptc045UTZXL3RGVUhVUWhuTGFRZktCOGhkbUxzZitTWTkzOG5aMXRNYmNWZGFBZmNrQisveGE0M01QRWRYa3F4d3o3Qkw3WklGVFk4NU9TM1ZVaDlZejZ2R252cG9MZWcxRjlZdFRyV1MwYnlRQ1Bod1dNSE5HK2FZVWlid0Q5RnlDK1BzODZtT3Z1OGJHNDBNeEVpSXVvRnFDeTRIQmcwSFNIcW9SK29ZaVdFZE8vemwzSmpHL1FaeHB5TT0tLXk2MWFyTGlnQlJoclp5bTlJZjdPK1E9PQ%3D%3D--fe2967ef94293551fbb2b2e61f42a2fde20add6e;
64
+ domain=harvestapp.com; path=/; expires=Thu, 19 Nov 2015 14:19:44 -0000; secure;
65
+ HttpOnly
66
+ X-Request-Id:
67
+ - 7b38e38c-1581-4edb-95ce-2471b8e976bf
68
+ X-Runtime:
69
+ - '0.183979'
70
+ X-Server:
71
+ - rails5
72
+ X-Lb:
73
+ - lb1
74
+ Strict-Transport-Security:
75
+ - max-age=31536000; includeSubDomains
76
+ body:
77
+ encoding: UTF-8
78
+ string: '[{"invoices":{"id":1,"client_id":123,"period_start":"2015-10-16","period_end":"2015-10-31","number":"60","issued_at":"2015-11-02","due_at":"2015-11-17","amount":20.0,"currency":"United
79
+ States Dollar - USD","state":"draft","notes":"","purchase_order":"","due_amount":20.0,"due_at_human_format":"net
80
+ 15","created_at":"2015-11-03T02:27:53Z","updated_at":"2015-11-03T02:27:53Z","tax":null,"tax_amount":0.0,"subject":"","recurring_invoice_id":null,"tax2":null,"tax2_amount":0.0,"client_key":"abcd","estimate_id":null,"discount":null,"discount_amount":0.0,"retainer_id":null,"created_by_id":6,"project_id":null,"client_name":"Fake Client 1"}},{"invoices":{"id":2,"client_id":321,"period_start":"2015-10-16","period_end":"2015-10-31","number":"59","issued_at":"2015-11-02","due_at":"2015-11-17","amount":30.0,"currency":"United
81
+ States Dollar - USD","state":"open","notes":"","purchase_order":"","due_amount":30.0,"due_at_human_format":"net
82
+ 15","created_at":"2015-11-03T02:26:47Z","updated_at":"2015-11-03T02:26:57Z","tax":null,"tax_amount":0.0,"subject":"","recurring_invoice_id":null,"tax2":null,"tax2_amount":0.0,"client_key":"abcd","estimate_id":null,"discount":null,"discount_amount":0.0,"retainer_id":null,"created_by_id":6,"project_id":null,"client_name":"Fake Client 2"}}]'
83
+ http_version:
84
+ recorded_at: Wed, 04 Nov 2015 14:19:44 GMT
85
+ recorded_with: VCR 2.9.3