Module: Nineflats::Requests::ClassMethods
- Defined in:
- lib/nineflats-api/requests.rb
Instance Method Summary collapse
- #place(slug, options = {}) ⇒ Object
- #place_calendar(place_slug, year, month) ⇒ Object
- #place_photos(place_slug) ⇒ Object
- #place_prices(place_slug) ⇒ Object
- #place_reviews(place_slug) ⇒ Object
- #places(search_options) ⇒ Object
- #user(user_id) ⇒ Object
- #user_bookings(user_id) ⇒ Object
- #user_favorites(user_id) ⇒ Object
Instance Method Details
#place(slug, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nineflats-api/requests.rb', line 36 def place(slug, ={}) params = {:client_id => consumer.key} params[:lang] = [:language] if [:language] url = "/api/v1/places/#{slug}?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}" response = if client.access_token client.access_token.request(:get, url) else consumer.request(:get, url) end Nineflats::Place.new(JSON.parse(response.body)) end |
#place_calendar(place_slug, year, month) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/nineflats-api/requests.rb', line 48 def place_calendar(place_slug, year, month) response = consumer.request(:get, "/api/v1/places/#{place_slug}/calendar/#{year}/#{month}?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}") json = JSON.parse(response.body) if json["calendar"] Calendar.new(json['calendar']) else raise Nineflats::Error.new(json['error']) end end |
#place_photos(place_slug) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nineflats-api/requests.rb', line 80 def place_photos(place_slug) response = consumer.request(:get, "/api/v1/places/#{place_slug}/photos?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}") json = JSON.parse(response.body) if json["place_photos"] json["place_photos"].collect do |photo_hash| Photo.new(photo_hash) end else raise Nineflats::Error.new(json['error']) end end |
#place_prices(place_slug) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/nineflats-api/requests.rb', line 58 def place_prices(place_slug) response = consumer.request(:get, "/api/v1/places/#{place_slug}/prices?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}") json = JSON.parse(response.body) if json["place_prices"] Prices.new(json['place_prices']) else raise Nineflats::Error.new(json['error']) end end |
#place_reviews(place_slug) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nineflats-api/requests.rb', line 68 def place_reviews(place_slug) response = consumer.request(:get, "/api/v1/places/#{place_slug}/reviews?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}") json = JSON.parse(response.body) if json["reviews"] json["reviews"].collect do |review_hash| Review.new(review_hash) end else raise Nineflats::Error.new(json['error']) end end |
#places(search_options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nineflats-api/requests.rb', line 9 def places() response = if [:url] consumer.request(:get, [:url]) else consumer.request(:get, "/api/v1/places?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key, :search => })}") end json = JSON.parse(response.body) if json["places"] places = json["places"].collect do |place_hash| Place.new(place_hash) 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 else raise Nineflats::Error.new(json['error']) end end |
#user(user_id) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/nineflats-api/requests.rb', line 92 def user(user_id) url = "/api/v1/users/#{user_id}?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}" response = if client.access_token client.access_token.request(:get, url) else consumer.request(:get, url) end Nineflats::User.new(JSON.parse(response.body)) end |
#user_bookings(user_id) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/nineflats-api/requests.rb', line 114 def user_bookings(user_id) raise Nineflats::NotAuthenticatedException.new("User is not authenticated yet!") unless Client.client. params = {:client_id => consumer.key} response = client.access_token.request(:get, "/api/v1/users/#{user_id}/bookings?#{Nineflats::QueryStringNormalizer.normalize(params)}") json = JSON.parse(response.body) if json && json["bookings"] json["bookings"].collect do |booking_hash| Booking.new(booking_hash) end else raise Nineflats::Error.new(json['error']) end end |
#user_favorites(user_id) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/nineflats-api/requests.rb', line 102 def user_favorites(user_id) response = consumer.request(:get, "/api/v1/users/#{user_id}/favorites?#{Nineflats::QueryStringNormalizer.normalize({:client_id => consumer.key})}") json = JSON.parse(response.body) if json["places"] json["places"].collect do |place_hash| Place.new(place_hash) end else raise Nineflats::Error.new(json['error']) end end |