class RoomTinyManager::Fetcher

Constants

ACCESS_TOKEN
HOST_ROOM_END_POINT
ROOMS_END_POINT

FIXME: I added my access_token Can be more general, that some one use the gem can set their access token

Public Class Methods

new(properties_input) click to toggle source
# File lib/room_tiny_manager.rb, line 20
def initialize(properties_input)
  @properties = parse_input(properties_input)
end

Public Instance Methods

get_properties() click to toggle source
# File lib/room_tiny_manager.rb, line 24
def get_properties
  @properties
end
post_a_room() click to toggle source

Post new room to the following end_point “api.roomorama.com/v1.0/host/rooms.json

# File lib/room_tiny_manager.rb, line 29
def post_a_room
  raw_result = RestClient.get(HOST_ROOM_END_POINT, { params: @properties.first.merge(access_token: ACCESS_TOKEN) })
  JSON.parse(raw_result)
end

Private Instance Methods

parse_input(properties) click to toggle source

def self.room_by_city(city=nil)

raise "Missing argument: city" if city.nil?
raw_result = RestClient.get(ROOMS_END_POINT, { params: {access_token: ACCESS_TOKEN, destination: city } })
JSON.parse(raw_result)

end

# File lib/room_tiny_manager.rb, line 41
def parse_input(properties)
  properties = JSON.parse(properties)["properties"]

  rooms = []
  properties.each do |property|
    map_p = {
      address: property["property_address"],
      apartment_number: property["apartment_no"],
      postal_code: property["zip_code"],
      city: property["town"],
      country: property["country"],
      description: property["property_description"],
      number_of_bedrooms: property["bedrooms_no"],
      max_guests: property["max_people"],
      internal_id: property["source_id"]
    }
    rooms << map_p
  end
  
  rooms
end