forked from hpyhacking/peatio
-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split named_params, rename not_enough_funds error to insufficient_bal…
…ance (#2075) * Split named_params and rename not_enough_funds error to insufficient_balance * Remove Currency.enabled.codes from desc. Remoe tralling whitespaces * Rename: errors.rb exception_handlers.rb. Update specs. rescue_from :all
- Loading branch information
Maksym
authored and
Yaroslav Savchuk
committed
Feb 18, 2019
1 parent
ab19e94
commit efdeb43
Showing
23 changed files
with
147 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module API::V2 | ||
module Account | ||
class Mount < Grape::API | ||
include NewExceptionsHandlers | ||
|
||
before { authenticate! } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# encoding: UTF-8 | ||
# frozen_string_literal: true | ||
|
||
module API::V2 | ||
module ExceptionHandlers | ||
def self.included(base) | ||
base.instance_eval do | ||
rescue_from Grape::Exceptions::ValidationErrors do |e| | ||
errors_array = e.full_messages.map do |err| | ||
err.split.last | ||
end | ||
error!({ errors: errors_array }, 422) | ||
end | ||
|
||
rescue_from Peatio::Auth::Error do |e| | ||
report_exception(e) | ||
error!({ errors: ['jwt.decode_and_verify'] }, 401) | ||
end | ||
|
||
rescue_from ActiveRecord::RecordNotFound do |_e| | ||
error!({ errors: ['record.not_found'] }, 404) | ||
end | ||
|
||
rescue_from :all do |e| | ||
report_exception(e) | ||
error!({ errors: ['server.internal_error'] }, 500) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# encoding: UTF-8 | ||
# frozen_string_literal: true | ||
|
||
module API | ||
module V2 | ||
module Market | ||
module NamedParams | ||
extend ::Grape::API::Helpers | ||
|
||
params :currency do | ||
requires :currency, | ||
type: String, | ||
values: { value: -> { Currency.enabled.pluck(:id) }, message: 'account.currency.doesnt_exist' }, | ||
desc: 'The currency code.' | ||
end | ||
|
||
params :market do | ||
requires :market, | ||
type: String, | ||
values: { value: -> { ::Market.enabled.ids }, message: 'market.market.doesnt_exist' }, | ||
desc: -> { V2::Entities::Market.documentation[:id] } | ||
end | ||
|
||
params :order do | ||
requires :side, | ||
type: String, | ||
values: { value: %w(sell buy), message: 'market.order.invalid_side' }, | ||
desc: -> { V2::Entities::Order.documentation[:side] } | ||
requires :volume, | ||
type: { value: BigDecimal, message: 'market.order.non_decimal_volume' }, | ||
values: { value: -> (v){ v.try(:positive?) }, message: 'market.order.non_positive_volume' }, | ||
desc: -> { V2::Entities::Order.documentation[:volume] } | ||
optional :ord_type, | ||
type: String, | ||
values: { value: -> { Order::TYPES}, message: 'market.order.invalid_type' }, | ||
default: 'limit', | ||
desc: -> { V2::Entities::Order.documentation[:type] } | ||
given ord_type: ->(val) { val == 'limit' } do | ||
requires :price, | ||
type: { value: BigDecimal, message: 'market.order.non_decimal_price' }, | ||
values: { value: -> (p){ p.try(:positive?) }, message: 'market.order.non_positive_price' }, | ||
desc: -> { V2::Entities::Order.documentation[:price] } | ||
end | ||
end | ||
|
||
params :order_id do | ||
requires :id, | ||
type: { value: Integer, message: 'market.order.non_integer_id' }, | ||
allow_blank: { value: false, message: 'market.order.empty_id' }, | ||
desc: -> { V2::Entities::Order.documentation[:id] } | ||
end | ||
|
||
params :trade_filters do | ||
optional :limit, | ||
type: { value: Integer, message: 'market.trade.non_integer_limit' }, | ||
values: { value: 1..1000, message: 'market.trade.invalid_limit' }, | ||
default: 100, | ||
desc: 'Limit the number of returned trades. Default to 100.' | ||
optional :page, | ||
type: { value: Integer, message: 'market.trade.non_integer_page' }, | ||
allow_blank: { value: false, message: 'market.trade.empty_page' }, | ||
default: 1, | ||
desc: 'Specify the page of paginated results.' | ||
optional :timestamp, | ||
type: { value: Integer, message: 'market.trade.non_integer_timestamp' }, | ||
allow_blank: { value: false, message: 'market.trade.empty_timestamp' }, | ||
desc: "An integer represents the seconds elapsed since Unix epoch."\ | ||
"If set, only trades executed before the time will be returned." | ||
optional :order_by, | ||
type: String, | ||
values: { value: %w(asc desc), message: 'market.trade.invalid_order_by' }, | ||
default: 'desc', | ||
desc: "If set, returned trades will be sorted in specific order, default to 'desc'." | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.