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
# app/controllers/api/v1.rb | |
class Api::V1 < Grape::API | |
class Grape::Middleware::Error | |
def error_message(code, text) | |
{ | |
:error => { | |
:code => code, | |
:message => text | |
} |
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
module Api | |
module V1 | |
class StatusesAPI < Api::V1::BaseAPI | |
get '/' do | |
statuses = Status.all | |
detailed_statuses = DetailedStatus.all | |
present statuses, with: Api::V1::StatusEntity, type: :full | |
present detailed_statuses, with: Api::V1::StatusDetailedEntity | |
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
# app/presenters/api/v1/base_entity.rb | |
module Api | |
module V1 | |
module BaseEntity < Grape::Entity | |
format_with(:unix_timestamp) { |dt| dt.to_time.to_i } | |
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
# app/controllers/api/v1/base_api.rb | |
class Api::V1::BaseAPI < Grape::API | |
class AccessDenied < ArgumentError; end | |
class InvalidToken < ArgumentError; end | |
Grape::Endpoint.class_eval do | |
def abilities | |
@abilities ||= Six.new | |
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
# app/helpers/api/v1/city_helper.rb | |
module Api::V1::CityHelper | |
def resource_city | |
@resource_city ||= ::City.find(params[:city_id] || params[:id]) | |
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
# app/controllers/api/v1/cities/places_api.rb | |
class Api::V1::Cities::PlacesAPI < Api::V1::BaseAPI | |
namespace 'cities/:city_id' do | |
resource :places do | |
helpers ::Api::V1::CityHelper | |
params do | |
requires :city_id, :type => Integer | |
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
# app/controllers/api/v1/cities_api.rb | |
class Api::V1::CitiesAPI < Api::V1::BaseAPI | |
resource :cities do | |
params do | |
optional :term, :type => String | |
end | |
get '/' do | |
cities = ::City.ordered_by_name_asc |
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
# app/controllers/api/v1.rb | |
class Api::V1 < Grape::API | |
format :json | |
content_type :json, 'application/json; charset=utf-8' | |
version 'v1' | |
mount CitiesAPI | |
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
# app/controllers/api.rb | |
class Api < Grape::API | |
mount ::Api::V1 | |
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
-end | |
+end | |
\ No newline at end of file |