radriar 0.1.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/TODO.md +5 -0
- data/lib/radriar.rb +7 -0
- data/lib/radriar/api/authentication.rb +30 -0
- data/lib/radriar/api/context.rb +47 -0
- data/lib/radriar/api/exception_handling.rb +47 -0
- data/lib/radriar/api/logging.rb +32 -0
- data/lib/radriar/api/strong_parameters_support.rb +9 -0
- data/lib/radriar/bugsnag.rb +1 -0
- data/lib/radriar/bugsnag/user_info.rb +24 -0
- data/lib/radriar/grape.rb +31 -0
- data/lib/radriar/representable.rb +17 -0
- data/lib/radriar/roar/hal.rb +21 -0
- data/lib/radriar/roar/key_translation.rb +57 -0
- data/lib/radriar/roar/links.rb +17 -0
- data/lib/radriar/roar/representers.rb +79 -0
- data/lib/radriar/version.rb +3 -0
- data/radriar.gemspec +35 -0
- data/spec/spec_helper.rb +83 -0
- metadata +239 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b2f240868f2a031e59cb508385c188e21c519c1
|
4
|
+
data.tar.gz: dfb6a0b56d81e1326544d4b6e06cb51d6dbc5649
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eefda213eda77dd73061d8729e524deb40d99ca8332ec08bfb885d75295dcfbb6d6f6506728f4e390d7b80788f88224359d113a5d1f2f89b6c0bec729f25f48e
|
7
|
+
data.tar.gz: d685d4e61915d4c4ce2f57b13e329305ddd51e48c3bb4bdb537d9184aaf8b419b84277d7ab9431a508344602dc4f415860420b0678df6951ae56481bcdd074be
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
vendor
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Adrian Perez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Radriar
|
2
|
+
|
3
|
+
A set of opinionated API design helpers for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'radriar'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install radriar
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Features
|
24
|
+
|
25
|
+
__TODO__: Redact
|
26
|
+
* Key translation (Snake case to underscore and viceversa).
|
27
|
+
* Optional field includes (Pass `fields` parameter in URL).
|
28
|
+
* Conventional error responses.
|
29
|
+
* Optional inclusion/exclusion of hypermedia (HAL).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( https://github.com/[my-github-username]/radriar/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/TODO.md
ADDED
data/lib/radriar.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Radriar
|
2
|
+
module API
|
3
|
+
module Authentication
|
4
|
+
def warden
|
5
|
+
env['warden']
|
6
|
+
end
|
7
|
+
|
8
|
+
def authenticated?
|
9
|
+
warden.authenticated? || !!find_user
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticate!
|
13
|
+
if authenticated?
|
14
|
+
current_user.tap { |u| u.try(:seen!)}
|
15
|
+
else
|
16
|
+
error!("401 Unauthorized", 401)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_user
|
21
|
+
warden.user || find_user
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_user
|
25
|
+
token = params[:access_token] || headers['Authorization']
|
26
|
+
User.find_for_token_authentication(token)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Radriar
|
2
|
+
module API
|
3
|
+
module Context
|
4
|
+
def context
|
5
|
+
OpenStruct.new(current_user: current_user)
|
6
|
+
end
|
7
|
+
|
8
|
+
def id
|
9
|
+
params[:id]
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_params
|
13
|
+
[permitted_params, create_handlers]
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_handlers
|
17
|
+
@create_handlers ||= {
|
18
|
+
success: ->(record) { represent(record) },
|
19
|
+
failure: ->(errors) { error!({
|
20
|
+
message: "Validation failed", errors: errors }, 422)
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_params
|
26
|
+
[id, permitted_params, update_handlers]
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_handlers
|
30
|
+
@update_handlers ||= {
|
31
|
+
success: ->(record) { represent(record) },
|
32
|
+
failure: ->(errors) { error!({
|
33
|
+
message: "Validation failed",
|
34
|
+
errors: errors }, 422)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def success_or_forbidden_handlers
|
40
|
+
@success_of_forbidden_handlers ||= {
|
41
|
+
success: ->(*) { status 200 },
|
42
|
+
failure: ->(msg) { error!(msg, 403)}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Radriar::API
|
2
|
+
module ExceptionHandling
|
3
|
+
module Grape
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
if defined?(Mongoid)
|
8
|
+
rescue_from Mongoid::Errors::DocumentNotFound do |e|
|
9
|
+
error_response(message: e.message, status: 404)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
rescue_from Grape::Exceptions::ValidationErrors do |e|
|
14
|
+
Rack::Response.new({
|
15
|
+
status: 422,
|
16
|
+
message: e.message,
|
17
|
+
errors: e.errors
|
18
|
+
}.to_json, 422, { "Content-Type" => "application/json"})
|
19
|
+
end
|
20
|
+
|
21
|
+
rescue_from Mongoid::Errors::Validations do |e|
|
22
|
+
Rack::Response.new({
|
23
|
+
message: "Validation failed",
|
24
|
+
status: 422,
|
25
|
+
errors: e.document.errors.messages
|
26
|
+
}.to_json, 422, {"Content-Type" => "application/json"})
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue_from Mongoid::Errors::DocumentNotFound do |e|
|
30
|
+
error_response(
|
31
|
+
message: "There was a problem finding a requested or associated record",
|
32
|
+
status: 404
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
rescue_from :all do |e|
|
37
|
+
if Rails.env.development? || Rails.env.test?
|
38
|
+
raise e
|
39
|
+
else
|
40
|
+
Bugsnag.notify(e) if defined?(Bugsnag)
|
41
|
+
error_response(message: "Internal server error", status: 500)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Radriar
|
2
|
+
module API
|
3
|
+
module Logging
|
4
|
+
class Instrumenter
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
payload = {
|
11
|
+
remote_addr: env['REMOTE_ADDR'],
|
12
|
+
request_method: env['REQUEST_METHOD'],
|
13
|
+
request_path: env['PATH_INFO'],
|
14
|
+
request_query: env['QUERY_STRING'],
|
15
|
+
x_organization: env['HTTP_X_ORGANIZATION']
|
16
|
+
}
|
17
|
+
|
18
|
+
ActiveSupport::Notifications.instrument('grape.request', payload) do
|
19
|
+
@app.call(env).tap do |response|
|
20
|
+
if payload[:params].present?
|
21
|
+
payload[:params] = env['api.endpoint'].params.to_hash
|
22
|
+
payload[:params].delete(:route_info)
|
23
|
+
payload[:params].delete(:format)
|
24
|
+
payload[:response_status] = response[0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "radriar/bugsnag/user_info"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Radriar
|
2
|
+
module Bugsnag
|
3
|
+
module UserInfo
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
included do
|
6
|
+
before do
|
7
|
+
::Bugsnag.before_notify_callbacks << ->(notif) do
|
8
|
+
if current_user
|
9
|
+
notif.add_tab(:user, {
|
10
|
+
id: current_user.id,
|
11
|
+
username: current_user.username,
|
12
|
+
ip: notif.user_id
|
13
|
+
})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Bugsnag.before_notify_callbacks.clear
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "radriar/api/authentication"
|
2
|
+
require "radriar/api/context"
|
3
|
+
require "radriar/api/exception_handling"
|
4
|
+
require "radriar/api/logging"
|
5
|
+
require "radriar/api/strong_parameters_support"
|
6
|
+
|
7
|
+
module Radriar
|
8
|
+
module Grape
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ::Grape::API
|
13
|
+
def self.radriarize(hypermedia: false, representer_namespace: nil, translate_keys: false)
|
14
|
+
class_eval do
|
15
|
+
format :json
|
16
|
+
default_format :json
|
17
|
+
|
18
|
+
helpers Radriar::API::Authentication
|
19
|
+
helpers Radriar::API::Logging
|
20
|
+
helpers Radriar::API::Context
|
21
|
+
helpers Radriar::API::StrongParametersSupport
|
22
|
+
helpers Radriar::Roar::Representers
|
23
|
+
|
24
|
+
Radriar::Representable.representer_namespace = representer_namespace
|
25
|
+
Radriar::Representable.hypermedia = hypermedia
|
26
|
+
|
27
|
+
include Radriar::Roar::KeyTranslation if translate_keys
|
28
|
+
include Radriar::Roar::HAL
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Radriar
|
2
|
+
module Representable
|
3
|
+
mattr_accessor :representer_namespace
|
4
|
+
mattr_accessor :hypermedia
|
5
|
+
|
6
|
+
def self.hypermedia?
|
7
|
+
!!hypermedia
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require "representable/hash"
|
13
|
+
require "roar/representer/json/hal"
|
14
|
+
require "radriar/roar/links"
|
15
|
+
require "radriar/roar/representers"
|
16
|
+
require "radriar/roar/key_translation"
|
17
|
+
require "radriar/roar/hal"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Radriar
|
2
|
+
module Roar
|
3
|
+
module HAL
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
module ::Roar::Representer::JSON::HAL::Resources
|
8
|
+
def compile_fragment(bin, doc)
|
9
|
+
embedded = bin[:embedded]
|
10
|
+
return super unless embedded
|
11
|
+
if Radriar::Representable.hypermedia?
|
12
|
+
super(bin, doc[:_embedded] ||= {})
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'representable'
|
2
|
+
module Radriar
|
3
|
+
module Roar
|
4
|
+
module KeyTranslation
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class KeyTranslatorHash < Hashie::Mash
|
8
|
+
protected
|
9
|
+
def convert_key(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def convert_value(val, duping=false) #:nodoc
|
13
|
+
obj = super
|
14
|
+
obj = self.class.new(obj) if Hashie::Mash === obj
|
15
|
+
obj if Hashie::Mash === obj
|
16
|
+
obj
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize_reader(key)
|
20
|
+
ck = to_underscore(key)
|
21
|
+
custom_writer(ck, self.class.new) unless key?(ck)
|
22
|
+
custom_reader(ck.camelize)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class UnderscoreKeys < KeyTranslatorHash
|
27
|
+
protected
|
28
|
+
def convert_key(key)
|
29
|
+
key.to_s.underscore
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class CamelizeKeys < KeyTranslatorHash
|
34
|
+
protected
|
35
|
+
def convert_key(key)
|
36
|
+
key.to_s.camelize(:lower)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
module Representer
|
42
|
+
def from_hash(data, options={}, binding_builder=::Representable::Hash::PropertyBinding)
|
43
|
+
data = filter_wrap(UnderscoreKeys.new(data), options)
|
44
|
+
update_properties_from(data, options, binding_builder)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_hash(options={}, binding_builder=::Representable::Hash::PropertyBinding)
|
48
|
+
CamelizeKeys.new(super)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
included do
|
53
|
+
::Representable::Hash.prepend(Representer)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Radriar
|
2
|
+
module Roar
|
3
|
+
module Links
|
4
|
+
def add_links(endpoint)
|
5
|
+
links = {}
|
6
|
+
links[:self] = { href: endpoint.request.path }
|
7
|
+
links[:first] = { href: endpoint.first_page }
|
8
|
+
links[:prev] = { href: endpoint.previous_page }
|
9
|
+
links[:next] = { href: endpoint.next_page }
|
10
|
+
links[:last] = { href: endpoint.last_page}
|
11
|
+
links
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Radriar
|
2
|
+
module Roar::Representers
|
3
|
+
include Roar::Links
|
4
|
+
mattr_accessor :hypermedia
|
5
|
+
|
6
|
+
def represent(*args, with: nil, represent: nil, context: nil)
|
7
|
+
representer = find_representer(args, with)
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
if params[:fields].present?
|
11
|
+
options[:include] = params[:fields].split(",").map(&:to_sym)
|
12
|
+
end
|
13
|
+
options.merge!(represent) if represent
|
14
|
+
|
15
|
+
if representer.is_a?(Class)
|
16
|
+
represented = representer.new(*args)
|
17
|
+
elsif args.length > 1
|
18
|
+
raise ArgumentError.new("Can't represent using module with more than one argument")
|
19
|
+
elsif representer.is_a?(Module)
|
20
|
+
represented = args.first.extend(representer)
|
21
|
+
else
|
22
|
+
raise ArgumentError.new("Can't infer, instantiate or extend representer")
|
23
|
+
end
|
24
|
+
|
25
|
+
options[:exclude] = [:links] unless Radriar::Representable.hypermedia?
|
26
|
+
represented.to_hash(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def represent_each(collection, *args, with: nil, represent: nil, context: nil)
|
30
|
+
if Radriar::Representable.hypermedia?
|
31
|
+
result = {}
|
32
|
+
unless collection.empty?
|
33
|
+
result = add_links(context) if context
|
34
|
+
result['total'] = collection.size
|
35
|
+
result['_embedded'] = {
|
36
|
+
collection.first.class.name.pluralize.underscore.to_sym =>
|
37
|
+
represent_collection(collection, *args)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
result
|
41
|
+
else
|
42
|
+
represent_collection(collection, *args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def represent_collection(collection, *args)
|
47
|
+
# TODO: try with roar 1.8
|
48
|
+
# collection.map { |item| represent(item, *args) }
|
49
|
+
collection.map { |item| JSON.parse(represent(item, *args).to_json)}
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def find_representer(args, with)
|
54
|
+
raise ArgumentError.new("nil can't be represented") unless args.first
|
55
|
+
|
56
|
+
unless with
|
57
|
+
klazz = args.first.class.name
|
58
|
+
infered = "#{representer_namespace}::#{klazz}".safe_constantize
|
59
|
+
if infered
|
60
|
+
representer = infered
|
61
|
+
else
|
62
|
+
raise ArgumentError.new(
|
63
|
+
"Can't infer representer, need to specify :with option for class #{klazz}"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if with.is_a?(Symbol)
|
69
|
+
"#{representer_namespace}::#{with.to_s.classify}".constantize
|
70
|
+
else
|
71
|
+
representer
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def representer_namespace
|
76
|
+
Radriar::Representable.representer_namespace
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/radriar.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'radriar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "radriar"
|
8
|
+
spec.version = Radriar::VERSION
|
9
|
+
spec.authors = ["Adrian Perez"]
|
10
|
+
spec.email = ["adrianperez.deb@gmail.com"]
|
11
|
+
spec.summary = %q{Opinionated set of tools for Ruby API development}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/blackxored/radriar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = "~> 2.0"
|
22
|
+
|
23
|
+
spec.add_dependency "activesupport", ">= 3.2"
|
24
|
+
spec.add_dependency "representable", ">= 1.8.0"
|
25
|
+
spec.add_dependency "roar"
|
26
|
+
spec.add_dependency "grape"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.rc1"
|
31
|
+
spec.add_development_dependency "webmock"
|
32
|
+
spec.add_development_dependency "rr"
|
33
|
+
spec.add_development_dependency "grape-bugsnag"
|
34
|
+
spec.add_development_dependency "garner"
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
=begin
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# RSpec filters the backtrace by default so as not to be so noisy.
|
33
|
+
# This causes the full backtrace to be printed when running a single
|
34
|
+
# spec file (e.g. to troubleshoot a particular spec failure).
|
35
|
+
config.full_backtrace = true
|
36
|
+
|
37
|
+
# Use the documentation formatter for detailed output,
|
38
|
+
# unless a formatter has already been configured
|
39
|
+
# (e.g. via a command-line flag).
|
40
|
+
config.default_formatter = 'doc'
|
41
|
+
end
|
42
|
+
|
43
|
+
# Print the 10 slowest examples and example groups at the
|
44
|
+
# end of the spec run, to help surface which specs are running
|
45
|
+
# particularly slow.
|
46
|
+
config.profile_examples = 10
|
47
|
+
|
48
|
+
# Run specs in random order to surface order dependencies. If you find an
|
49
|
+
# order dependency and want to debug it, you can fix the order by providing
|
50
|
+
# the seed, which is printed after each run.
|
51
|
+
# --seed 1234
|
52
|
+
config.order = :random
|
53
|
+
|
54
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
55
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
56
|
+
# test failures related to randomization by passing the same `--seed` value
|
57
|
+
# as the one that triggered the failure.
|
58
|
+
Kernel.srand config.seed
|
59
|
+
|
60
|
+
# rspec-expectations config goes here. You can use an alternate
|
61
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
62
|
+
# assertions if you prefer.
|
63
|
+
config.expect_with :rspec do |expectations|
|
64
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
65
|
+
# For more details, see:
|
66
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
67
|
+
expectations.syntax = :expect
|
68
|
+
end
|
69
|
+
|
70
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
71
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
72
|
+
config.mock_with :rspec do |mocks|
|
73
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
74
|
+
# For more details, see:
|
75
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
76
|
+
mocks.syntax = :expect
|
77
|
+
|
78
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
79
|
+
# a real object. This is generally recommended.
|
80
|
+
mocks.verify_partial_doubles = true
|
81
|
+
end
|
82
|
+
=end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radriar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Perez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: representable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.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.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: roar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: grape
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.0.0.rc1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.0.0.rc1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: grape-bugsnag
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: garner
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: Opinionated set of tools for Ruby API development
|
182
|
+
email:
|
183
|
+
- adrianperez.deb@gmail.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".ruby-version"
|
191
|
+
- Gemfile
|
192
|
+
- LICENSE.txt
|
193
|
+
- README.md
|
194
|
+
- Rakefile
|
195
|
+
- TODO.md
|
196
|
+
- lib/radriar.rb
|
197
|
+
- lib/radriar/api/authentication.rb
|
198
|
+
- lib/radriar/api/context.rb
|
199
|
+
- lib/radriar/api/exception_handling.rb
|
200
|
+
- lib/radriar/api/logging.rb
|
201
|
+
- lib/radriar/api/strong_parameters_support.rb
|
202
|
+
- lib/radriar/bugsnag.rb
|
203
|
+
- lib/radriar/bugsnag/user_info.rb
|
204
|
+
- lib/radriar/grape.rb
|
205
|
+
- lib/radriar/representable.rb
|
206
|
+
- lib/radriar/roar/hal.rb
|
207
|
+
- lib/radriar/roar/key_translation.rb
|
208
|
+
- lib/radriar/roar/links.rb
|
209
|
+
- lib/radriar/roar/representers.rb
|
210
|
+
- lib/radriar/version.rb
|
211
|
+
- radriar.gemspec
|
212
|
+
- spec/spec_helper.rb
|
213
|
+
homepage: https://github.com/blackxored/radriar
|
214
|
+
licenses:
|
215
|
+
- MIT
|
216
|
+
metadata: {}
|
217
|
+
post_install_message:
|
218
|
+
rdoc_options: []
|
219
|
+
require_paths:
|
220
|
+
- lib
|
221
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - "~>"
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: '2.0'
|
226
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">"
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 1.3.1
|
231
|
+
requirements: []
|
232
|
+
rubyforge_project:
|
233
|
+
rubygems_version: 2.2.2
|
234
|
+
signing_key:
|
235
|
+
specification_version: 4
|
236
|
+
summary: Opinionated set of tools for Ruby API development
|
237
|
+
test_files:
|
238
|
+
- spec/spec_helper.rb
|
239
|
+
has_rdoc:
|