Class: Nineflats::Place

Inherits:
Base
  • Object
show all
Defined in:
lib/nineflats-api/place.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_url, client_app_key, client_app_key=, object_link

Constructor Details

#initialize(json) ⇒ Place

Returns a new instance of Place.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nineflats-api/place.rb', line 14

def initialize(json)
  place = json.first[1]
  
  @name                          = place["name"]
  @city                          = place["city"]
  @currency                      = place["currency"]
  @slug                          = place["slug"]
  @zipcode                       = place["zipcode"]
  @number_of_beds                = place["number_of_beds"]
  @number_of_bedrooms            = place["number_of_bedrooms"]
  @number_of_bathrooms           = place["number_of_bathrooms"]
  @charge_per_extra_person       = place["charge_per_extra_person"]
  @content_language              = place["content_language"]
  @minimum_nights                = place["minimum_nights"]
  @maximum_nights                = place["maximum_nights"]
  @bed_type                      = place["bed_type"]
  @size                          = place["size"]
  @house_rules                   = place["house_rules"]
  @pets_around                   = place["pets_around"]
  @bathroom_type                 = place["bathroom_type"]
  @cleaning_fee                  = place["cleaning_fee"]
  @charge_per_extra_person_limit = place["charge_per_extra_person_limit"]
  @favorites_count               = place["favorites_count"]
  @amenities_list                = place["amenities_list"]
  @featured_photo_url            = place["featured_photo_url"]
  @price                         = place["price"]
  @country                       = place["country"]
  @category                      = place["category"]
  @place_type                    = place["place_type"]
  @lat                           = place["lat"]
  @lng                           = place["lng"]
  @district                      = place["district"]
  @description                   = place["description"]

  @host = User.new({"user" => place["host"]})

  @self_url                   = Nineflats::Base.object_link("self", place["links"])
  @full_url                   = Nineflats::Base.object_link("full", place["links"])
  @photos_url                 = Nineflats::Base.object_link("photos", place["links"])
  @prices_url                 = Nineflats::Base.object_link("prices", place["links"])
  @reviews_url                = Nineflats::Base.object_link("reviews", place["links"])
  @calendar_current_month_url = Nineflats::Base.object_link("calendar: current month", place["links"])
  @calendar_next_month_url    = Nineflats::Base.object_link("calendar: next month", place["links"])
end

Instance Attribute Details

#amenities_listObject

Returns the value of attribute amenities_list.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def amenities_list
  @amenities_list
end

#bathroom_typeObject

Returns the value of attribute bathroom_type.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def bathroom_type
  @bathroom_type
end

#bed_typeObject

Returns the value of attribute bed_type.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def bed_type
  @bed_type
end

#calendar_current_month_urlObject

Returns the value of attribute calendar_current_month_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def calendar_current_month_url
  @calendar_current_month_url
end

#calendar_next_month_urlObject

Returns the value of attribute calendar_next_month_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def calendar_next_month_url
  @calendar_next_month_url
end

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def category
  @category
end

#charge_per_extra_personObject

Returns the value of attribute charge_per_extra_person.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def charge_per_extra_person
  @charge_per_extra_person
end

#charge_per_extra_person_limitObject

Returns the value of attribute charge_per_extra_person_limit.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def charge_per_extra_person_limit
  @charge_per_extra_person_limit
end

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def city
  @city
end

#cleaning_feeObject

Returns the value of attribute cleaning_fee.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def cleaning_fee
  @cleaning_fee
end

#content_languageObject

Returns the value of attribute content_language.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def content_language
  @content_language
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def country
  @country
end

#currencyObject

Returns the value of attribute currency.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def description
  @description
end

#districtObject

Returns the value of attribute district.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def district
  @district
end

#favorites_countObject

Returns the value of attribute favorites_count.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def favorites_count
  @favorites_count
end

Returns the value of attribute featured_photo_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def featured_photo_url
  @featured_photo_url
end

#full_urlObject

Returns the value of attribute full_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def full_url
  @full_url
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def host
  @host
end

#house_rulesObject

Returns the value of attribute house_rules.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def house_rules
  @house_rules
end

#latObject

Returns the value of attribute lat.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def lng
  @lng
end

#maximum_nightsObject

Returns the value of attribute maximum_nights.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def maximum_nights
  @maximum_nights
end

#minimum_nightsObject

Returns the value of attribute minimum_nights.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def minimum_nights
  @minimum_nights
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def name
  @name
end

#number_of_bathroomsObject

Returns the value of attribute number_of_bathrooms.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def number_of_bathrooms
  @number_of_bathrooms
end

#number_of_bedroomsObject

Returns the value of attribute number_of_bedrooms.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def number_of_bedrooms
  @number_of_bedrooms
end

#number_of_bedsObject

Returns the value of attribute number_of_beds.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def number_of_beds
  @number_of_beds
end

#pets_aroundObject

Returns the value of attribute pets_around.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def pets_around
  @pets_around
end

#photosObject

Returns the value of attribute photos.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def photos
  @photos
end

#photos_urlObject

Returns the value of attribute photos_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def photos_url
  @photos_url
end

#place_typeObject

Returns the value of attribute place_type.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def place_type
  @place_type
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def price
  @price
end

#pricesObject

Returns the value of attribute prices.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def prices
  @prices
end

#prices_urlObject

Returns the value of attribute prices_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def prices_url
  @prices_url
end

#reviewsObject

Returns the value of attribute reviews.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def reviews
  @reviews
end

#reviews_urlObject

Returns the value of attribute reviews_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def reviews_url
  @reviews_url
end

#self_urlObject

Returns the value of attribute self_url.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def self_url
  @self_url
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def size
  @size
end

#slugObject

Returns the value of attribute slug.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def slug
  @slug
end

#zipcodeObject

Returns the value of attribute zipcode.



3
4
5
# File 'lib/nineflats-api/place.rb', line 3

def zipcode
  @zipcode
end

Class Method Details

.api_call(slug, lang) ⇒ Object



133
134
135
# File 'lib/nineflats-api/place.rb', line 133

def self.api_call(slug, lang)
  base_url + "/places/#{slug}?client_id=#{Nineflats::Base.client_app_key}&lang=#{lang}"
end

.fetch(slug, lang) ⇒ Object



91
92
93
# File 'lib/nineflats-api/place.rb', line 91

def self.fetch(slug, lang)
  Place.new(Helpers.get_data(Place.api_call(slug, lang)))
end

.search(params = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nineflats-api/place.rb', line 59

def self.search(params = nil)
  params ||= {}
  
  queries = params.collect do |key, value|
    "&search[#{key}]=#{value}"
  end
  
  search_url = base_url + "/places?client_id=#{Nineflats::Base.client_app_key}" + queries.join
  
  Place.search_result(search_url)
end

.search_result(search_url) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/nineflats-api/place.rb', line 71

def self.search_result(search_url)
  json = Helpers.get_data(search_url)
  
  places = json["places"].collect do |place_json|
    Place.new(place_json)
  end
  
  result = Nineflats::PaginatedArray.new(places)
  
  result.total_entries = json["total_entries"]
  result.total_pages   = json["total_pages"]
  result.current_page  = json["current_page"]
  result.per_page      = json["per_page"]
  
  result.self_url      = Nineflats::Base.object_link("self", json["links"])
  result.full_url      = Nineflats::Base.object_link("full", json["links"])
  result.next_page_url = Nineflats::Base.object_link("next_page", json["links"])
  result
end

Instance Method Details

#calendar(year, month) ⇒ Object



127
128
129
130
131
# File 'lib/nineflats-api/place.rb', line 127

def calendar(year, month)
  json = Helpers.get_data(Calendar.api_call(slug, year, month))

  Calendar.new(json) if json && json["calendar"]
end