Skip to content

Commit

Permalink
Use grape entities instead of Roar
Browse files Browse the repository at this point in the history
Grape entities works better with Garner for caching. It also makes it easier to prevent keys whose values is an empty array from being returned, although not in a DRY way currently.
  • Loading branch information
monfresh committed Sep 10, 2013
1 parent 6363e11 commit fdb54f7
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 416 deletions.
2 changes: 1 addition & 1 deletion app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def valid_api_token?
}.to_json, 400)
end

mount Ohana::Locations
mount Ohana::API
Grape::Endpoint.send :include, LinkHeader
add_swagger_documentation markdown: true, hide_documentation_path: true,
hide_format: true, api_version: 'v1'
Expand Down
29 changes: 29 additions & 0 deletions app/api/entities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Entities
class Location < Grape::Entity
expose :id, :unless => lambda { |o,_| o.id.blank? }
expose :accessibility, :unless => lambda { |o,_| o.accessibility.blank? }
expose :ask_for, :unless => lambda { |o,_| o.ask_for.blank? }
expose :coordinates, :unless => lambda { |o,_| o.coordinates.blank? }
expose :description, :unless => lambda { |o,_| o.description.blank? }
expose :emails, :unless => lambda { |o,_| o.emails.blank? }
expose :faxes, :unless => lambda { |o,_| o.faxes.blank? }
expose :hours, :unless => lambda { |o,_| o.hours.blank? }
expose :kind, :unless => lambda { |o,_| o.kind.blank? }
expose :languages, :unless => lambda { |o,_| o.languages.blank? }
expose :name, :unless => lambda { |o,_| o.name.blank? }
expose :phones, :unless => lambda { |o,_| o.phones.blank? }
expose :short_desc, :unless => lambda { |o,_| o.short_desc.blank? }
expose :transportation, :unless => lambda { |o,_| o.transportation.blank? }
expose :urls, :unless => lambda { |o,_| o.urls.blank? }

expose :address, :using => Address::Entity, :unless => lambda { |o,_| o.address.blank? }
expose :mail_address, :using => MailAddress::Entity, :unless => lambda { |o,_| o.mail_address.blank? }
expose :contacts, :using => Contact::Entity, :unless => lambda { |o,_| o.contacts.blank? }
expose :updated_at
expose :organization, :using => Organization::Entity
expose :services, :using => Service::Entity, :unless => lambda { |o,_| o.services.blank? }
expose :url, :unless => lambda { |o,_| o.url.blank? }
expose :other_locations, :unless => lambda { |o,_| o.other_locations.blank? }
end

end
Loading

0 comments on commit fdb54f7

Please sign in to comment.