Skip to content

Instantly share code, notes, and snippets.

@Timrael
Created April 16, 2013 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Timrael/5394468 to your computer and use it in GitHub Desktop.
Save Timrael/5394468 to your computer and use it in GitHub Desktop.
module HotelsApi
class Search
include NanoApi::Model
HOTELSCOMBINED_MAP = {
:search => :destination,
:file_name => :fileName,
:checkin => :depart_date,
:checkout => :return_date,
:rooms => :rooms,
:persons => :adults,
:label => :label
}
attribute :destination_name
attribute :file_name
attribute(:depart_date) {Date.current}
attribute(:return_date) {Date.current + 6.days}
attribute :rooms, in: (1..6), default: 1
attribute :adults, in: (1..9), default: 1
attribute :children, in: (0..5), default: 1
attribute :infants, in: (0..5), default: 1
attribute :label
URL = 'http://nano.aviasales.ru/hotel_clicks?%s'
def link
URL % hotelscombined_params.to_query
end
private
def hotelscombined_params
HOTELSCOMBINED_MAP.each_with_object({}) do |(name, value), result|
result[value] = send(name) if send(name).present?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment