apes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +82 -0
  4. data/.travis-gemfile +15 -0
  5. data/.travis.yml +15 -0
  6. data/.yardopts +1 -0
  7. data/CHANGELOG.md +3 -0
  8. data/Gemfile +22 -0
  9. data/README.md +177 -0
  10. data/Rakefile +44 -0
  11. data/apes.gemspec +34 -0
  12. data/doc/Apes.html +130 -0
  13. data/doc/Apes/Concerns.html +127 -0
  14. data/doc/Apes/Concerns/Errors.html +1089 -0
  15. data/doc/Apes/Concerns/Pagination.html +636 -0
  16. data/doc/Apes/Concerns/Request.html +766 -0
  17. data/doc/Apes/Concerns/Response.html +940 -0
  18. data/doc/Apes/Controller.html +1100 -0
  19. data/doc/Apes/Errors.html +125 -0
  20. data/doc/Apes/Errors/AuthenticationError.html +133 -0
  21. data/doc/Apes/Errors/BadRequestError.html +157 -0
  22. data/doc/Apes/Errors/BaseError.html +320 -0
  23. data/doc/Apes/Errors/InvalidDataError.html +157 -0
  24. data/doc/Apes/Errors/MissingDataError.html +157 -0
  25. data/doc/Apes/Model.html +378 -0
  26. data/doc/Apes/PaginationCursor.html +2138 -0
  27. data/doc/Apes/RuntimeConfiguration.html +909 -0
  28. data/doc/Apes/Serializers.html +125 -0
  29. data/doc/Apes/Serializers/JSON.html +389 -0
  30. data/doc/Apes/Serializers/JWT.html +452 -0
  31. data/doc/Apes/Serializers/List.html +347 -0
  32. data/doc/Apes/UrlsParser.html +1432 -0
  33. data/doc/Apes/Validators.html +125 -0
  34. data/doc/Apes/Validators/BaseValidator.html +278 -0
  35. data/doc/Apes/Validators/BooleanValidator.html +494 -0
  36. data/doc/Apes/Validators/EmailValidator.html +350 -0
  37. data/doc/Apes/Validators/PhoneValidator.html +375 -0
  38. data/doc/Apes/Validators/ReferenceValidator.html +372 -0
  39. data/doc/Apes/Validators/TimestampValidator.html +640 -0
  40. data/doc/Apes/Validators/UuidValidator.html +372 -0
  41. data/doc/Apes/Validators/ZipCodeValidator.html +372 -0
  42. data/doc/Apes/Version.html +189 -0
  43. data/doc/ApplicationController.html +547 -0
  44. data/doc/Concerns.html +128 -0
  45. data/doc/Concerns/ErrorHandling.html +826 -0
  46. data/doc/Concerns/PaginationHandling.html +463 -0
  47. data/doc/Concerns/RequestHandling.html +512 -0
  48. data/doc/Concerns/ResponseHandling.html +579 -0
  49. data/doc/Errors.html +126 -0
  50. data/doc/Errors/AuthenticationError.html +123 -0
  51. data/doc/Errors/BadRequestError.html +147 -0
  52. data/doc/Errors/BaseError.html +289 -0
  53. data/doc/Errors/InvalidDataError.html +147 -0
  54. data/doc/Errors/MissingDataError.html +147 -0
  55. data/doc/Model.html +315 -0
  56. data/doc/PaginationCursor.html +764 -0
  57. data/doc/Serializers.html +126 -0
  58. data/doc/Serializers/JSON.html +253 -0
  59. data/doc/Serializers/JWT.html +253 -0
  60. data/doc/Serializers/List.html +245 -0
  61. data/doc/Validators.html +126 -0
  62. data/doc/Validators/BaseValidator.html +209 -0
  63. data/doc/Validators/BooleanValidator.html +391 -0
  64. data/doc/Validators/EmailValidator.html +298 -0
  65. data/doc/Validators/PhoneValidator.html +313 -0
  66. data/doc/Validators/ReferenceValidator.html +284 -0
  67. data/doc/Validators/TimestampValidator.html +476 -0
  68. data/doc/Validators/UuidValidator.html +310 -0
  69. data/doc/Validators/ZipCodeValidator.html +310 -0
  70. data/doc/_index.html +435 -0
  71. data/doc/class_list.html +58 -0
  72. data/doc/css/common.css +1 -0
  73. data/doc/css/full_list.css +57 -0
  74. data/doc/css/style.css +339 -0
  75. data/doc/file.README.html +252 -0
  76. data/doc/file_list.html +60 -0
  77. data/doc/frames.html +26 -0
  78. data/doc/index.html +252 -0
  79. data/doc/js/app.js +219 -0
  80. data/doc/js/full_list.js +181 -0
  81. data/doc/js/jquery.js +4 -0
  82. data/doc/method_list.html +615 -0
  83. data/doc/top-level-namespace.html +112 -0
  84. data/lib/apes.rb +40 -0
  85. data/lib/apes/concerns/errors.rb +111 -0
  86. data/lib/apes/concerns/pagination.rb +81 -0
  87. data/lib/apes/concerns/request.rb +237 -0
  88. data/lib/apes/concerns/response.rb +74 -0
  89. data/lib/apes/controller.rb +77 -0
  90. data/lib/apes/errors.rb +38 -0
  91. data/lib/apes/model.rb +94 -0
  92. data/lib/apes/pagination_cursor.rb +152 -0
  93. data/lib/apes/runtime_configuration.rb +80 -0
  94. data/lib/apes/serializers.rb +88 -0
  95. data/lib/apes/urls_parser.rb +233 -0
  96. data/lib/apes/validators.rb +234 -0
  97. data/lib/apes/version.rb +24 -0
  98. data/spec/apes/concerns/errors_spec.rb +141 -0
  99. data/spec/apes/concerns/pagination_spec.rb +114 -0
  100. data/spec/apes/concerns/request_spec.rb +244 -0
  101. data/spec/apes/concerns/response_spec.rb +79 -0
  102. data/spec/apes/controller_spec.rb +54 -0
  103. data/spec/apes/errors_spec.rb +14 -0
  104. data/spec/apes/models_spec.rb +148 -0
  105. data/spec/apes/pagination_cursor_spec.rb +113 -0
  106. data/spec/apes/runtime_configuration_spec.rb +100 -0
  107. data/spec/apes/serializers_spec.rb +70 -0
  108. data/spec/apes/urls_parser_spec.rb +150 -0
  109. data/spec/apes/validators_spec.rb +237 -0
  110. data/spec/spec_helper.rb +30 -0
  111. data/views/_included.json.jbuilder +9 -0
  112. data/views/_pagination.json.jbuilder +9 -0
  113. data/views/collection.json.jbuilder +4 -0
  114. data/views/errors/400.json.jbuilder +9 -0
  115. data/views/errors/403.json.jbuilder +7 -0
  116. data/views/errors/404.json.jbuilder +6 -0
  117. data/views/errors/422.json.jbuilder +19 -0
  118. data/views/errors/500.json.jbuilder +12 -0
  119. data/views/errors/501.json.jbuilder +7 -0
  120. data/views/layouts/general.json.jbuilder +36 -0
  121. data/views/object.json.jbuilder +4 -0
  122. metadata +262 -0
@@ -0,0 +1,30 @@
1
+ #
2
+ # This file is part of the apes gem. Copyright (C) 2016 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "bundler/setup"
7
+
8
+ if ENV["COVERAGE"]
9
+ require "simplecov"
10
+ require "coveralls"
11
+
12
+ Coveralls.wear! if ENV["CI"]
13
+
14
+ SimpleCov.start do
15
+ root = Pathname.new(File.dirname(__FILE__)) + ".."
16
+
17
+ add_filter do |src_file|
18
+ path = Pathname.new(src_file.filename).relative_path_from(root).to_s
19
+ path !~ /^lib/
20
+ end
21
+ end
22
+ end
23
+
24
+ require "active_record"
25
+ require "lazier"
26
+ ::I18n.enforce_available_locales = false
27
+ Lazier::I18n.default_locale = :en
28
+
29
+ require File.dirname(__FILE__) + "/../lib/apes"
30
+ Lazier.load!(:hash)
@@ -0,0 +1,9 @@
1
+ included = response_included(local_assigns[:included])
2
+
3
+ if included.present?
4
+ json.included(included.values) do |(resource, template)|
5
+ template ||= resource.class.to_s.underscore.singularize
6
+
7
+ json.partial!("models/#{template}", locals: {object: resource, included: true}) if resource
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ next_url = pagination_url(:next)
2
+ prev_url = pagination_url(:prev)
3
+ first_url = pagination_url(:first)
4
+
5
+ json.links do
6
+ json.next next_url if next_url
7
+ json.prev prev_url if prev_url
8
+ json.first first_url if first_url
9
+ end
@@ -0,0 +1,4 @@
1
+ json.data @objects do |object|
2
+ object_template = local_assigns.fetch(:model_template, response_template_for(object))
3
+ json.partial! partial: "models/#{object_template}", locals: {object: object}
4
+ end
@@ -0,0 +1,9 @@
1
+ unless local_assigns[:debug]
2
+ json.errors do
3
+ json.child! do
4
+ json.code response.code
5
+ json.title "Bad Request"
6
+ json.detail @reason || @errors
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ json.errors do
2
+ json.child! do
3
+ json.code 403
4
+ json.title "Forbidden"
5
+ json.detail @authentication_error[:error]
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ json.errors do
2
+ json.child! do
3
+ json.code 404
4
+ json.title "Not Found"
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ if @errors.is_a?(Hash)
2
+ errors = @errors.map {|field, errors|
3
+ [field, errors.ensure_array.first]
4
+ }
5
+
6
+ json.errors errors do |(field, error)|
7
+ json.code 422
8
+ json.title "Bad Attribute"
9
+ json.field field
10
+ error += "." unless error.end_with?(".")
11
+ json.detail error.capitalize
12
+ end
13
+ else
14
+ json.errors @errors.ensure_array do |error|
15
+ json.code 422
16
+ json.title "Unknown Attribute"
17
+ json.field error
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ json.errors do
2
+ json.child! do
3
+ json.code 500
4
+ json.title "Unexpected Server Error"
5
+
6
+ unless Rails.env.production?
7
+ json.message @exception.message
8
+ json.class @exception.class.to_s
9
+ json.backtrace @backtrace if @backtrace
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ json.errors do
2
+ json.child! do
3
+ json.code 501
4
+ json.title "Not Implemented"
5
+ json.detail "Unsupported Request."
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ json.jsonapi do
2
+ json.version "1.0"
3
+ end
4
+
5
+ json.meta do
6
+ json.status response.status
7
+ json.success response.status / 100 == 2 || response.status == 418
8
+ json.debug @debug || local_assigns[:debug] if @debug || local_assigns.key?(:debug)
9
+ json.handler sprintf("%s/%s", controller_name, action_name) unless Rails.env.production?
10
+ end
11
+
12
+ # Meta
13
+ meta = response_meta(local_assigns[:meta])
14
+ json.meta meta if meta.present?
15
+
16
+ if @count || @page_size
17
+ json.meta do
18
+ json.total @count
19
+ json.size @page_size || @cursor.size
20
+ end
21
+ end
22
+
23
+ # Data
24
+ data = response_data(local_assigns[:data])
25
+ json.data data if data.present?
26
+
27
+ # Template
28
+ json.merge! JSON.parse(yield) if block_given? && !local_assigns[:empty]
29
+
30
+ # Links
31
+ links = response_links(local_assigns[:links])
32
+ json.links links if links.present?
33
+
34
+ # Included and pagination
35
+ json.partial! "/included"
36
+ json.partial! "/pagination" if @objects && !pagination_skip? && pagination_supported?
@@ -0,0 +1,4 @@
1
+ json.data do
2
+ record_template = local_assigns.fetch(:model_template, response_template_for(@object))
3
+ json.partial! "models/#{record_template}", locals: {object: @object}
4
+ end
metadata ADDED
@@ -0,0 +1,262 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Shogun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lazier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mustache
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jwt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jbuilder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails-api
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ description: A tiny JSON API framework for Ruby on Rails.
98
+ email:
99
+ - shogun@cowtech.it
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis-gemfile"
107
+ - ".travis.yml"
108
+ - ".yardopts"
109
+ - CHANGELOG.md
110
+ - Gemfile
111
+ - README.md
112
+ - Rakefile
113
+ - apes.gemspec
114
+ - doc/Apes.html
115
+ - doc/Apes/Concerns.html
116
+ - doc/Apes/Concerns/Errors.html
117
+ - doc/Apes/Concerns/Pagination.html
118
+ - doc/Apes/Concerns/Request.html
119
+ - doc/Apes/Concerns/Response.html
120
+ - doc/Apes/Controller.html
121
+ - doc/Apes/Errors.html
122
+ - doc/Apes/Errors/AuthenticationError.html
123
+ - doc/Apes/Errors/BadRequestError.html
124
+ - doc/Apes/Errors/BaseError.html
125
+ - doc/Apes/Errors/InvalidDataError.html
126
+ - doc/Apes/Errors/MissingDataError.html
127
+ - doc/Apes/Model.html
128
+ - doc/Apes/PaginationCursor.html
129
+ - doc/Apes/RuntimeConfiguration.html
130
+ - doc/Apes/Serializers.html
131
+ - doc/Apes/Serializers/JSON.html
132
+ - doc/Apes/Serializers/JWT.html
133
+ - doc/Apes/Serializers/List.html
134
+ - doc/Apes/UrlsParser.html
135
+ - doc/Apes/Validators.html
136
+ - doc/Apes/Validators/BaseValidator.html
137
+ - doc/Apes/Validators/BooleanValidator.html
138
+ - doc/Apes/Validators/EmailValidator.html
139
+ - doc/Apes/Validators/PhoneValidator.html
140
+ - doc/Apes/Validators/ReferenceValidator.html
141
+ - doc/Apes/Validators/TimestampValidator.html
142
+ - doc/Apes/Validators/UuidValidator.html
143
+ - doc/Apes/Validators/ZipCodeValidator.html
144
+ - doc/Apes/Version.html
145
+ - doc/ApplicationController.html
146
+ - doc/Concerns.html
147
+ - doc/Concerns/ErrorHandling.html
148
+ - doc/Concerns/PaginationHandling.html
149
+ - doc/Concerns/RequestHandling.html
150
+ - doc/Concerns/ResponseHandling.html
151
+ - doc/Errors.html
152
+ - doc/Errors/AuthenticationError.html
153
+ - doc/Errors/BadRequestError.html
154
+ - doc/Errors/BaseError.html
155
+ - doc/Errors/InvalidDataError.html
156
+ - doc/Errors/MissingDataError.html
157
+ - doc/Model.html
158
+ - doc/PaginationCursor.html
159
+ - doc/Serializers.html
160
+ - doc/Serializers/JSON.html
161
+ - doc/Serializers/JWT.html
162
+ - doc/Serializers/List.html
163
+ - doc/Validators.html
164
+ - doc/Validators/BaseValidator.html
165
+ - doc/Validators/BooleanValidator.html
166
+ - doc/Validators/EmailValidator.html
167
+ - doc/Validators/PhoneValidator.html
168
+ - doc/Validators/ReferenceValidator.html
169
+ - doc/Validators/TimestampValidator.html
170
+ - doc/Validators/UuidValidator.html
171
+ - doc/Validators/ZipCodeValidator.html
172
+ - doc/_index.html
173
+ - doc/class_list.html
174
+ - doc/css/common.css
175
+ - doc/css/full_list.css
176
+ - doc/css/style.css
177
+ - doc/file.README.html
178
+ - doc/file_list.html
179
+ - doc/frames.html
180
+ - doc/index.html
181
+ - doc/js/app.js
182
+ - doc/js/full_list.js
183
+ - doc/js/jquery.js
184
+ - doc/method_list.html
185
+ - doc/top-level-namespace.html
186
+ - lib/apes.rb
187
+ - lib/apes/concerns/errors.rb
188
+ - lib/apes/concerns/pagination.rb
189
+ - lib/apes/concerns/request.rb
190
+ - lib/apes/concerns/response.rb
191
+ - lib/apes/controller.rb
192
+ - lib/apes/errors.rb
193
+ - lib/apes/model.rb
194
+ - lib/apes/pagination_cursor.rb
195
+ - lib/apes/runtime_configuration.rb
196
+ - lib/apes/serializers.rb
197
+ - lib/apes/urls_parser.rb
198
+ - lib/apes/validators.rb
199
+ - lib/apes/version.rb
200
+ - spec/apes/concerns/errors_spec.rb
201
+ - spec/apes/concerns/pagination_spec.rb
202
+ - spec/apes/concerns/request_spec.rb
203
+ - spec/apes/concerns/response_spec.rb
204
+ - spec/apes/controller_spec.rb
205
+ - spec/apes/errors_spec.rb
206
+ - spec/apes/models_spec.rb
207
+ - spec/apes/pagination_cursor_spec.rb
208
+ - spec/apes/runtime_configuration_spec.rb
209
+ - spec/apes/serializers_spec.rb
210
+ - spec/apes/urls_parser_spec.rb
211
+ - spec/apes/validators_spec.rb
212
+ - spec/spec_helper.rb
213
+ - views/_included.json.jbuilder
214
+ - views/_pagination.json.jbuilder
215
+ - views/collection.json.jbuilder
216
+ - views/errors/400.json.jbuilder
217
+ - views/errors/403.json.jbuilder
218
+ - views/errors/404.json.jbuilder
219
+ - views/errors/422.json.jbuilder
220
+ - views/errors/500.json.jbuilder
221
+ - views/errors/501.json.jbuilder
222
+ - views/layouts/general.json.jbuilder
223
+ - views/object.json.jbuilder
224
+ homepage: https://github.com/ShogunPanda/apes
225
+ licenses:
226
+ - MIT
227
+ metadata: {}
228
+ post_install_message:
229
+ rdoc_options: []
230
+ require_paths:
231
+ - lib
232
+ required_ruby_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: 2.3.0
237
+ required_rubygems_version: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ requirements: []
243
+ rubyforge_project: apes
244
+ rubygems_version: 2.5.1
245
+ signing_key:
246
+ specification_version: 4
247
+ summary: A tiny JSON API framework for Ruby on Rails.
248
+ test_files:
249
+ - spec/apes/concerns/errors_spec.rb
250
+ - spec/apes/concerns/pagination_spec.rb
251
+ - spec/apes/concerns/request_spec.rb
252
+ - spec/apes/concerns/response_spec.rb
253
+ - spec/apes/controller_spec.rb
254
+ - spec/apes/errors_spec.rb
255
+ - spec/apes/models_spec.rb
256
+ - spec/apes/pagination_cursor_spec.rb
257
+ - spec/apes/runtime_configuration_spec.rb
258
+ - spec/apes/serializers_spec.rb
259
+ - spec/apes/urls_parser_spec.rb
260
+ - spec/apes/validators_spec.rb
261
+ - spec/spec_helper.rb
262
+ has_rdoc: