hamtramck-mi-listings

node v10.24.1
version: 1.0.0
endpointsharetweet
1️⃣FILTER: RESULTS BY PROPERTY TYPE ⇨ Only return houses. ⇅GET /?filter[propertyType]=[house|apartment] ⏎ /?filter[propertyType]=house 2️⃣UNIQUE ID: GET A PROPERTY BY ITS IDENTIFIER ⇨ Get an Airbnb property with ID 28386050 ⇅GET /properties/:propertyId?platform=[airbnbPropertyId|homeawayPropertyId] ⏎ /properties/28386050 ...or... ⏎ /properties/28386050?platform=airbnbPropertyId ⇨ Get a Homeaway peroperty by ID "1727480vb" ⏎ /properties/1727480vb?platform=homeawayPropertyId 3️⃣ORDER BY: SORTED PROPERTY RESULTS ⇨ Fetch properties sorted by revenue, ADR (Average Daily Rate), and OCC (occupancy rate), in descending order. ⇅GET /?orderBy=property.attributeName&orderBy=property.attributeName ⏎ /?orderBy=revenue&orderBy=adr&orderBy=occ&orders=desc&orders=desc&orders=desc 4️⃣FIELDS: ONLY USE THE DATA YOU NEED ⇨ Fetch a single property by ID including its area info, but without any additional "technical" data. ⇅GET /?fields=[listingsLimited,meta,properties,requestInfo,properties,listingsReturned,areaInfo] ⏎ /properties/28386050?fields=areaInfo&fields=properties
const camelcaseKeys = require('camelcase-keys') const find = require('lodash.find') const get = require('lodash.get') const keysIn = require('lodash.keysin') const lodashOrderBy = require('lodash.orderby') const pick = require('lodash.pick') const querystring = require('querystring') const toInteger = require('lodash.tointeger') const {url, URL} = require('url')
const hamtramckData = { "listings_limited":false, "meta": {}, "request_info":{ "currency":"usd" }, "properties":[ { "airbnb_property_id":28386050, "rating":9.7, "property_type":"Apartment", "bathrooms":1.0, "title":"Hip Eclectic Flat Minutes From Downtown", "occ":0.848101, "bedrooms":2, "accommodates":4, "adr":56.6175, "revenue":15174, "reviews":93, "homeaway_property_id":null, "longitude":-83.05052, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39362, "m_homeaway_property_id":null, "days_available":316, "id":10971574, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":28386050, "homeaway_property_id":null } }, { "airbnb_property_id":24405602, "rating":9.9, "property_type":"Apartment", "bathrooms":1.0, "title":"Stylish 2 Bedroom w/ Dreamy Balcony", "occ":0.498403, "bedrooms":2, "accommodates":4, "adr":101.154, "revenue":15780, "reviews":65, "homeaway_property_id":null, "longitude":-83.05578, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39547, "m_homeaway_property_id":null, "days_available":313, "id":9187948, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":24405602, "homeaway_property_id":null } }, { "airbnb_property_id":22798143, "rating":10.0, "property_type":"House", "bathrooms":1.0, "title":"Clean cozy rooms in Hamtramck", "occ":0.2, "bedrooms":1, "accommodates":1, "adr":60.0, "revenue":1080, "reviews":5, "homeaway_property_id":null, "longitude":-83.06258, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.4003, "m_homeaway_property_id":null, "days_available":90, "id":9451806, "room_type":"Private room", "platforms":{ "airbnb_property_id":22798143, "homeaway_property_id":null } }, { "airbnb_property_id":20775515, "rating":7.3, "property_type":"Apartment", "bathrooms":1.0, "title":"New studio apt. near downtown 3", "occ":0.0989011, "bedrooms":0, "accommodates":2, "adr":95.5556, "revenue":860, "reviews":6, "homeaway_property_id":null, "longitude":-83.05312, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38995, "m_homeaway_property_id":null, "days_available":91, "id":7341397, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20775515, "homeaway_property_id":null } }, { "airbnb_property_id":24131460, "rating":9.9, "property_type":"Apartment", "bathrooms":1.0, "title":"Handsome & Private Flat! Central! Off St. Parking", "occ":0.791907, "bedrooms":1, "accommodates":2, "adr":60.7372, "revenue":8321, "reviews":40, "homeaway_property_id":null, "longitude":-83.06655, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39202, "m_homeaway_property_id":null, "days_available":173, "id":11206540, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":24131460, "homeaway_property_id":null } }, { "airbnb_property_id":36524914, "rating":10.0, "property_type":"House", "bathrooms":1.0, "title":"Beautiful & Spacious Home in Unique Hamtramck", "occ":0.516129, "bedrooms":3, "accommodates":5, "adr":94.75, "revenue":1516, "reviews":4, "homeaway_property_id":null, "longitude":-83.05026, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40607, "m_homeaway_property_id":null, "days_available":31, "id":14426706, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":36524914, "homeaway_property_id":null } }, { "airbnb_property_id":29611523, "rating":null, "property_type":"Loft", "bathrooms":1.0, "title":"Hamtramck Premier Photo Live in Loft", "occ":0.147541, "bedrooms":1, "accommodates":4, "adr":193.0, "revenue":1737, "reviews":0, "homeaway_property_id":null, "longitude":-83.06026, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40026, "m_homeaway_property_id":null, "days_available":61, "id":11390188, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":29611523, "homeaway_property_id":null } }, { "airbnb_property_id":19595268, "rating":null, "property_type":"Apartment", "bathrooms":1.0, "title":"Queen bed suite .", "occ":0.0322581, "bedrooms":0, "accommodates":2, "adr":40.0, "revenue":40, "reviews":0, "homeaway_property_id":null, "longitude":-83.05245, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39019, "m_homeaway_property_id":null, "days_available":31, "id":6723081, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":19595268, "homeaway_property_id":null } }, { "airbnb_property_id":33155140, "rating":10.0, "property_type":"Apartment", "bathrooms":1.0, "title":"One bedroom apartment", "occ":0.56, "bedrooms":1, "accommodates":4, "adr":125.0, "revenue":1750, "reviews":4, "homeaway_property_id":null, "longitude":-83.06138, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39846, "m_homeaway_property_id":null, "days_available":25, "id":13534254, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":33155140, "homeaway_property_id":null } }, { "airbnb_property_id":8282763, "rating":9.1, "property_type":"Apartment", "bathrooms":1.0, "title":"Mid Century Artist space. Retreat.", "occ":0.330769, "bedrooms":2, "accommodates":4, "adr":102.395, "revenue":4403, "reviews":40, "homeaway_property_id":null, "longitude":-83.04985, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39473, "m_homeaway_property_id":null, "days_available":130, "id":1002344, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":8282763, "homeaway_property_id":null } }, { "airbnb_property_id":20775333, "rating":9.5, "property_type":"Room in boutique hotel", "bathrooms":1.0, "title":"Modern studio in Hamtramck. Queen bed 2", "occ":0.168776, "bedrooms":0, "accommodates":2, "adr":85.0, "revenue":3400, "reviews":21, "homeaway_property_id":null, "longitude":-83.05316, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38851, "m_homeaway_property_id":null, "days_available":237, "id":7342474, "room_type":"Private room", "platforms":{ "airbnb_property_id":20775333, "homeaway_property_id":null } }, { "airbnb_property_id":2348834, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Spacious 1st Fl Apartment Hamtramck", "occ":0.687861, "bedrooms":2, "accommodates":4, "adr":82.3571, "revenue":19601, "reviews":291, "homeaway_property_id":null, "longitude":-83.06299, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39909, "m_homeaway_property_id":null, "days_available":346, "id":17621, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":2348834, "homeaway_property_id":null } }, { "airbnb_property_id":2989657, "rating":9.1, "property_type":"Apartment", "bathrooms":1.0, "title":"New studio apt. near downtown, Queen bed", "occ":0.0900621, "bedrooms":0, "accommodates":2, "adr":87.4138, "revenue":2535, "reviews":51, "homeaway_property_id":null, "longitude":-83.05394, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38884, "m_homeaway_property_id":null, "days_available":322, "id":35188, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":2989657, "homeaway_property_id":null } }, { "airbnb_property_id":28134635, "rating":9.4, "property_type":"Apartment", "bathrooms":1.0, "title":"Bright Spacious Flat Near Everything", "occ":0.910638, "bedrooms":2, "accommodates":6, "adr":62.5374, "revenue":13383, "reviews":33, "homeaway_property_id":null, "longitude":-83.06181, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39154, "m_homeaway_property_id":null, "days_available":235, "id":10841327, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":28134635, "homeaway_property_id":null } }, { "airbnb_property_id":103660506, "rating":0.0, "property_type":"House", "bathrooms":1.0, "title":"Beautifully designed warm and cozy Detroit artist hideaway!", "occ":0.625, "bedrooms":2, "accommodates":4, "adr":79.0, "revenue":1185, "reviews":0, "homeaway_property_id":"1727480vb", "longitude":-83.0645252, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.4036141, "m_homeaway_property_id":null, "days_available":24, "id":103660506, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":null, "homeaway_property_id":"1727480vb" } }, { "airbnb_property_id":8596005, "rating":10.0, "property_type":"House", "bathrooms":1.0, "title":"5-star luxury bed&bath in our home, near Detroit", "occ":0.523121, "bedrooms":1, "accommodates":4, "adr":83.0608, "revenue":15034, "reviews":143, "homeaway_property_id":null, "longitude":-83.05525, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39783, "m_homeaway_property_id":null, "days_available":346, "id":1100596, "room_type":"Private room", "platforms":{ "airbnb_property_id":8596005, "homeaway_property_id":null } }, { "airbnb_property_id":2486669, "rating":9.7, "property_type":"Apartment", "bathrooms":1.0, "title":"Upper Studio in Hamtramck", "occ":0.674912, "bedrooms":0, "accommodates":4, "adr":78.877, "revenue":15066, "reviews":250, "homeaway_property_id":null, "longitude":-83.06462, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39973, "m_homeaway_property_id":null, "days_available":283, "id":17568, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":2486669, "homeaway_property_id":null } }, { "airbnb_property_id":20503505, "rating":9.4, "property_type":"Apartment", "bathrooms":1.0, "title":"Artistic, Elegant and Light Filled!", "occ":0.609756, "bedrooms":2, "accommodates":6, "adr":111.45, "revenue":19504, "reviews":95, "homeaway_property_id":null, "longitude":-83.0553, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39932, "m_homeaway_property_id":null, "days_available":287, "id":7260890, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20503505, "homeaway_property_id":null } }, { "airbnb_property_id":34788449, "rating":9.9, "property_type":"House", "bathrooms":1.0, "title":"CHILL AF ENTIRE FLAT IN HAMTRAMCK No Cleaning Fee", "occ":0.888889, "bedrooms":1, "accommodates":4, "adr":76.45, "revenue":6116, "reviews":30, "homeaway_property_id":null, "longitude":-83.05969, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39355, "m_homeaway_property_id":null, "days_available":90, "id":13510372, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":34788449, "homeaway_property_id":null } }, { "airbnb_property_id":11550283, "rating":9.0, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern studio in Hamtramck, queen bed", "occ":0.156977, "bedrooms":0, "accommodates":2, "adr":85.5556, "revenue":2310, "reviews":31, "homeaway_property_id":null, "longitude":-83.05421, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.3889, "m_homeaway_property_id":null, "days_available":172, "id":1936607, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":11550283, "homeaway_property_id":null } }, { "airbnb_property_id":20755322, "rating":10.0, "property_type":"Apartment", "bathrooms":1.0, "title":"studio apt , queen", "occ":0.0721649, "bedrooms":0, "accommodates":2, "adr":81.5714, "revenue":571, "reviews":4, "homeaway_property_id":null, "longitude":-83.05236, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.3905, "m_homeaway_property_id":null, "days_available":97, "id":7342435, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20755322, "homeaway_property_id":null } }, { "airbnb_property_id":12156581, "rating":9.8, "property_type":"House", "bathrooms":1.0, "title":"Upper 2 bedroom", "occ":0.507143, "bedrooms":2, "accommodates":4, "adr":77.6268, "revenue":11023, "reviews":35, "homeaway_property_id":null, "longitude":-83.06105, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39912, "m_homeaway_property_id":null, "days_available":280, "id":2125337, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":12156581, "homeaway_property_id":null } }, { "airbnb_property_id":3185603, "rating":8.8, "property_type":"House", "bathrooms":1.0, "title":"Cozy Room Hamtramck Music/Art space", "occ":0.320652, "bedrooms":1, "accommodates":1, "adr":30.4461, "revenue":1796, "reviews":33, "homeaway_property_id":null, "longitude":-83.0699, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40481, "m_homeaway_property_id":null, "days_available":184, "id":17658, "room_type":"Private room", "platforms":{ "airbnb_property_id":3185603, "homeaway_property_id":null } }, { "airbnb_property_id":33220190, "rating":null, "property_type":"Bed and breakfast", "bathrooms":1.0, "title":"The Ham Burger House", "occ":0.258065, "bedrooms":1, "accommodates":1, "adr":54.375, "revenue":870, "reviews":0, "homeaway_property_id":null, "longitude":-83.06292, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40143, "m_homeaway_property_id":null, "days_available":62, "id":12849678, "room_type":"Private room", "platforms":{ "airbnb_property_id":33220190, "homeaway_property_id":null } }, { "airbnb_property_id":28055170, "rating":9.9, "property_type":"Apartment", "bathrooms":1.0, "title":"Hamtramck - Cozy, Light Filled 2 Bedroom Upper", "occ":0.700348, "bedrooms":2, "accommodates":3, "adr":80.9254, "revenue":16266, "reviews":20, "homeaway_property_id":null, "longitude":-83.06894, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39796, "m_homeaway_property_id":null, "days_available":287, "id":10898572, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":28055170, "homeaway_property_id":null } }, { "airbnb_property_id":4995116, "rating":9.7, "property_type":"House", "bathrooms":1.0, "title":"2 bedrooms", "occ":0.368644, "bedrooms":2, "accommodates":5, "adr":88.3095, "revenue":7683, "reviews":65, "homeaway_property_id":null, "longitude":-83.06474, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40578, "m_homeaway_property_id":null, "days_available":236, "id":17643, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":4995116, "homeaway_property_id":null } }, { "airbnb_property_id":21136947, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Quirky friendly home", "occ":0.648148, "bedrooms":2, "accommodates":4, "adr":56.5071, "revenue":7911, "reviews":38, "homeaway_property_id":null, "longitude":-83.06447, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40356, "m_homeaway_property_id":null, "days_available":216, "id":7386911, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":21136947, "homeaway_property_id":null } }, { "airbnb_property_id":6335682, "rating":9.9, "property_type":"Loft", "bathrooms":1.0, "title":"Beautiful Flat In Unique Hamtramck", "occ":0.576389, "bedrooms":1, "accommodates":3, "adr":97.741, "revenue":16225, "reviews":256, "homeaway_property_id":null, "longitude":-83.05672, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40035, "m_homeaway_property_id":null, "days_available":288, "id":32962, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":6335682, "homeaway_property_id":null } }, { "airbnb_property_id":9395082, "rating":9.4, "property_type":"Apartment", "bathrooms":1.0, "title":"Cozy Home in The Heart of Hamtramck!", "occ":0.541667, "bedrooms":2, "accommodates":5, "adr":102.59, "revenue":13337, "reviews":112, "homeaway_property_id":null, "longitude":-83.05454, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.3983, "m_homeaway_property_id":null, "days_available":240, "id":4959889, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":9395082, "homeaway_property_id":null } }, { "airbnb_property_id":3380575, "rating":8.9, "property_type":"House", "bathrooms":1.5, "title":"Large bedroom in arts / music house", "occ":0.185185, "bedrooms":1, "accommodates":2, "adr":30.3667, "revenue":456, "reviews":14, "homeaway_property_id":null, "longitude":-83.07128, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40348, "m_homeaway_property_id":null, "days_available":81, "id":17700, "room_type":"Private room", "platforms":{ "airbnb_property_id":3380575, "homeaway_property_id":null } }, { "airbnb_property_id":21233032, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern studio in Hamtramck, queen bed", "occ":0.218391, "bedrooms":0, "accommodates":2, "adr":81.8421, "revenue":1555, "reviews":15, "homeaway_property_id":null, "longitude":-83.05228, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38984, "m_homeaway_property_id":null, "days_available":87, "id":7494231, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":21233032, "homeaway_property_id":null } }, { "airbnb_property_id":21456866, "rating":9.7, "property_type":"House", "bathrooms":1.0, "title":"Beautifully designed warm and cozy artist hideaway", "occ":0.607029, "bedrooms":2, "accommodates":4, "adr":90.7053, "revenue":17234, "reviews":144, "homeaway_property_id":null, "longitude":-83.0642, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40264, "m_homeaway_property_id":null, "days_available":313, "id":7954621, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":21456866, "homeaway_property_id":null } }, { "airbnb_property_id":9423393, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Spacious 2nd Fl Apartment Hamtramck", "occ":0.786301, "bedrooms":2, "accommodates":4, "adr":81.6005, "revenue":23419, "reviews":133, "homeaway_property_id":null, "longitude":-83.06428, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39975, "m_homeaway_property_id":null, "days_available":365, "id":1439829, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":9423393, "homeaway_property_id":null } }, { "airbnb_property_id":20775969, "rating":9.1, "property_type":"Loft", "bathrooms":1.0, "title":"3 bedroom flat in safe neighborhood", "occ":0.239583, "bedrooms":3, "accommodates":6, "adr":142.174, "revenue":3270, "reviews":7, "homeaway_property_id":null, "longitude":-83.04966, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40433, "m_homeaway_property_id":null, "days_available":96, "id":7199990, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20775969, "homeaway_property_id":null } }, { "airbnb_property_id":10274492, "rating":9.6, "property_type":"House", "bathrooms":1.0, "title":"Private Beautiful 2Bd House in Hamtramck", "occ":0.601719, "bedrooms":2, "accommodates":6, "adr":106.378, "revenue":22339, "reviews":126, "homeaway_property_id":null, "longitude":-83.06777, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.4032, "m_homeaway_property_id":null, "days_available":349, "id":2039274, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":10274492, "homeaway_property_id":null } }, { "airbnb_property_id":34774621, "rating":9.0, "property_type":"House", "bathrooms":1.0, "title":"Large Private Bedroom in Relaxed Neighborhood", "occ":0.663866, "bedrooms":1, "accommodates":2, "adr":36.962, "revenue":2920, "reviews":8, "homeaway_property_id":null, "longitude":-83.06881, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40065, "m_homeaway_property_id":null, "days_available":119, "id":13478092, "room_type":"Private room", "platforms":{ "airbnb_property_id":34774621, "homeaway_property_id":null } }, { "airbnb_property_id":36834759, "rating":null, "property_type":"House", "bathrooms":1.0, "title":"Private Bedroom | Music Equipment", "occ":0.833333, "bedrooms":1, "accommodates":2, "adr":30.5, "revenue":305, "reviews":0, "homeaway_property_id":null, "longitude":-83.06805, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40047, "m_homeaway_property_id":null, "days_available":12, "id":14324032, "room_type":"Private room", "platforms":{ "airbnb_property_id":36834759, "homeaway_property_id":null } }, { "airbnb_property_id":13007367, "rating":9.2, "property_type":"Apartment", "bathrooms":1.0, "title":"3 bedroom flat in safe neighborhood", "occ":0.176, "bedrooms":3, "accommodates":6, "adr":174.545, "revenue":7680, "reviews":15, "homeaway_property_id":null, "longitude":-83.05052, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40279, "m_homeaway_property_id":null, "days_available":250, "id":2685951, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":13007367, "homeaway_property_id":null } }, { "airbnb_property_id":18457633, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Hamtramck Surf Shack!", "occ":0.902597, "bedrooms":1, "accommodates":5, "adr":78.9892, "revenue":21959, "reviews":316, "homeaway_property_id":null, "longitude":-83.05879, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39722, "m_homeaway_property_id":null, "days_available":308, "id":5885285, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":18457633, "homeaway_property_id":null } }, { "airbnb_property_id":25067993, "rating":9.8, "property_type":"Apartment", "bathrooms":1.0, "title":"Charming 2 Bedroom in Art & Culture Neighborhood", "occ":0.461095, "bedrooms":2, "accommodates":4, "adr":101.977, "revenue":16316, "reviews":65, "homeaway_property_id":null, "longitude":-83.05379, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39613, "m_homeaway_property_id":null, "days_available":347, "id":9506427, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":25067993, "homeaway_property_id":null } }, { "airbnb_property_id":20692034, "rating":10.0, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern loft in safe neighborhood", "occ":0.252336, "bedrooms":0, "accommodates":3, "adr":104.167, "revenue":5625, "reviews":12, "homeaway_property_id":null, "longitude":-83.05084, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40328, "m_homeaway_property_id":null, "days_available":214, "id":7200483, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20692034, "homeaway_property_id":null } }, { "airbnb_property_id":7049578, "rating":9.4, "property_type":"House", "bathrooms":1.0, "title":"Banglatown Bungalo", "occ":0.687805, "bedrooms":3, "accommodates":6, "adr":50.5887, "revenue":7133, "reviews":89, "homeaway_property_id":null, "longitude":-83.0607, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.41254, "m_homeaway_property_id":null, "days_available":205, "id":1017733, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":7049578, "homeaway_property_id":null } }, { "airbnb_property_id":6184673, "rating":9.7, "property_type":"House", "bathrooms":1.0, "title":"Bedroom in lower 3bd flat.", "occ":0.347015, "bedrooms":1, "accommodates":1, "adr":28.0358, "revenue":2607, "reviews":59, "homeaway_property_id":null, "longitude":-83.06393, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40279, "m_homeaway_property_id":null, "days_available":268, "id":33228, "room_type":"Private room", "platforms":{ "airbnb_property_id":6184673, "homeaway_property_id":null } }, { "airbnb_property_id":9411908, "rating":9.7, "property_type":"House", "bathrooms":1.0, "title":"1 bedroom in 3 bedroom flat.", "occ":0.366438, "bedrooms":1, "accommodates":2, "adr":30.6106, "revenue":3275, "reviews":44, "homeaway_property_id":null, "longitude":-83.06381, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40287, "m_homeaway_property_id":null, "days_available":292, "id":1437302, "room_type":"Private room", "platforms":{ "airbnb_property_id":9411908, "homeaway_property_id":null } }, { "airbnb_property_id":34748444, "rating":9.3, "property_type":"Apartment", "bathrooms":1.0, "title":"Cute apartment room in Hamtramck", "occ":0.387387, "bedrooms":1, "accommodates":2, "adr":47.0233, "revenue":2022, "reviews":3, "homeaway_property_id":null, "longitude":-83.06329, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39547, "m_homeaway_property_id":null, "days_available":111, "id":13540307, "room_type":"Private room", "platforms":{ "airbnb_property_id":34748444, "homeaway_property_id":null } }, { "airbnb_property_id":6453038, "rating":9.6, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern loft in safe neighborhood", "occ":0.202703, "bedrooms":0, "accommodates":3, "adr":119.667, "revenue":3590, "reviews":42, "homeaway_property_id":null, "longitude":-83.0502, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40424, "m_homeaway_property_id":null, "days_available":148, "id":17599, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":6453038, "homeaway_property_id":null } }, { "airbnb_property_id":3534553, "rating":9.0, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern studio in Hamtramck, queen bed", "occ":0.126016, "bedrooms":1, "accommodates":2, "adr":91.9355, "revenue":2850, "reviews":21, "homeaway_property_id":null, "longitude":-83.05265, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38829, "m_homeaway_property_id":null, "days_available":246, "id":34539, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":3534553, "homeaway_property_id":null } }, { "airbnb_property_id":26893643, "rating":9.9, "property_type":"House", "bathrooms":1.0, "title":"Stylish, Bright Upper Flat!", "occ":0.954751, "bedrooms":1, "accommodates":2, "adr":68.1374, "revenue":14377, "reviews":32, "homeaway_property_id":null, "longitude":-83.05093, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40123, "m_homeaway_property_id":null, "days_available":221, "id":10321483, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":26893643, "homeaway_property_id":null } }, { "airbnb_property_id":14014078, "rating":8.9, "property_type":"Apartment", "bathrooms":1.0, "title":"Modern studio in Hamtramck. Queen bed", "occ":0.398876, "bedrooms":0, "accommodates":2, "adr":81.338, "revenue":5775, "reviews":16, "homeaway_property_id":null, "longitude":-83.0532, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39057, "m_homeaway_property_id":null, "days_available":178, "id":3241008, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":14014078, "homeaway_property_id":null } }, { "airbnb_property_id":2936308, "rating":9.2, "property_type":"Apartment", "bathrooms":1.0, "title":"New studio apt. near downtown. Queen bed", "occ":0.0845588, "bedrooms":0, "accommodates":2, "adr":85.6522, "revenue":1970, "reviews":62, "homeaway_property_id":null, "longitude":-83.05313, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38922, "m_homeaway_property_id":null, "days_available":272, "id":35722, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":2936308, "homeaway_property_id":null } }, { "airbnb_property_id":20802549, "rating":9.2, "property_type":"Apartment", "bathrooms":1.0, "title":"New studio apt. near downtown. Queen bed", "occ":0.236364, "bedrooms":0, "accommodates":2, "adr":84.7692, "revenue":2204, "reviews":12, "homeaway_property_id":null, "longitude":-83.0515, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.38856, "m_homeaway_property_id":null, "days_available":110, "id":7253415, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":20802549, "homeaway_property_id":null } }, { "airbnb_property_id":31623482, "rating":9.6, "property_type":"Condominium", "bathrooms":1.0, "title":"Stay @ cozy local landmark Hamtramck Disneyland!", "occ":0.982759, "bedrooms":2, "accommodates":4, "adr":35.6316, "revenue":2031, "reviews":5, "homeaway_property_id":null, "longitude":-83.05752, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40832, "m_homeaway_property_id":null, "days_available":58, "id":13290345, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":31623482, "homeaway_property_id":null } }, { "airbnb_property_id":19541343, "rating":9.4, "property_type":"Apartment", "bathrooms":1.0, "title":"Hamtramck Vintage Apartment", "occ":0.557377, "bedrooms":1, "accommodates":2, "adr":85.6176, "revenue":11644, "reviews":52, "homeaway_property_id":null, "longitude":-83.05468, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39425, "m_homeaway_property_id":null, "days_available":244, "id":7824407, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":19541343, "homeaway_property_id":null } }, { "airbnb_property_id":35180723, "rating":9.5, "property_type":"House", "bathrooms":1.0, "title":"Two Bedroom Duplex Unit on Tranquil Street :)", "occ":0.755556, "bedrooms":2, "accommodates":5, "adr":77.4559, "revenue":5267, "reviews":8, "homeaway_property_id":null, "longitude":-83.06656, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40032, "m_homeaway_property_id":null, "days_available":90, "id":13685618, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":35180723, "homeaway_property_id":null } }, { "airbnb_property_id":17125460, "rating":9.4, "property_type":"House", "bathrooms":1.0, "title":"Historical Hamtramck Haven", "occ":0.356846, "bedrooms":1, "accommodates":1, "adr":40.093, "revenue":3448, "reviews":25, "homeaway_property_id":null, "longitude":-83.0604, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39783, "m_homeaway_property_id":null, "days_available":241, "id":5200214, "room_type":"Private room", "platforms":{ "airbnb_property_id":17125460, "homeaway_property_id":null } }, { "airbnb_property_id":27577367, "rating":9.2, "property_type":"Apartment", "bathrooms":1.0, "title":"Eclectic Casita Near Everything", "occ":0.896996, "bedrooms":1, "accommodates":4, "adr":55.0327, "revenue":11502, "reviews":43, "homeaway_property_id":null, "longitude":-83.06181, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39294, "m_homeaway_property_id":null, "days_available":233, "id":10585640, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":27577367, "homeaway_property_id":null } }, { "airbnb_property_id":30935776, "rating":9.5, "property_type":"Apartment", "bathrooms":1.0, "title":"Large/Bright 2 bedroom in the Heart of Hamtramck", "occ":0.726908, "bedrooms":2, "accommodates":4, "adr":75.2284, "revenue":13616, "reviews":53, "homeaway_property_id":null, "longitude":-83.06256, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.39938, "m_homeaway_property_id":null, "days_available":249, "id":11931919, "room_type":"Entire home/apt", "platforms":{ "airbnb_property_id":30935776, "homeaway_property_id":null } }, { "airbnb_property_id":36564912, "rating":null, "property_type":"House", "bathrooms":1.0, "title":"Yvonne\u2019s place", "occ":0.283333, "bedrooms":1, "accommodates":2, "adr":60.0, "revenue":1020, "reviews":0, "homeaway_property_id":null, "longitude":-83.06494, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.42356, "m_homeaway_property_id":null, "days_available":60, "id":14356110, "room_type":"Private room", "platforms":{ "airbnb_property_id":36564912, "homeaway_property_id":null } }, { "airbnb_property_id":34775846, "rating":9.0, "property_type":"House", "bathrooms":1.0, "title":"Comfy Bedroom on Tranquil Street :)", "occ":0.595041, "bedrooms":1, "accommodates":2, "adr":44.2639, "revenue":3187, "reviews":6, "homeaway_property_id":null, "longitude":-83.06815, "regions":{ "zipcode_ids":[ 8219 ] }, "latitude":42.40145, "m_homeaway_property_id":null, "days_available":121, "id":13520090, "room_type":"Private room", "platforms":{ "airbnb_property_id":34775846, "homeaway_property_id":null } } ], "listings_returned":59, "area_info":{ "geom":{ "code":{ "country":"us", "state":"michigan", "city":"hamtramck" }, "name":{ "country":"United States", "state":"Michigan", "city":"Hamtramck" }, "id":{ "country":1, "state":24, "city":67501 } } } }
const listings = { data: hamtramckData, toString() { const data = camelcaseKeys(hamtramckData, { 'deep': true }) return JSON.stringify(data) }, valueOf() { return JSON.parse(this.toString()) } }
const filterByPropertyType = (listings, propertyType) => listings.properties.filter((property) => property.propertyType === propertyType) const filterByType = (properties, type) => properties.filter((property) => property.propertyType.toLowerCase() === type.toLowerCase())
const listingPaths = keysIn(JSON.parse(listings.toString())) const pickFields = (req, listings, paths = listingPaths) => { let { fields } = req.query if (fields) { return pick(listings, fields) } else { return listings } }
const orderPropertiesBy = (properties, iteratees = ['revenue', 'occ'], orders = ['desc', 'desc']) => orderBy(properties, iteratees, orders)
const findBy = (properties, attrName, attrValue) => properties.find((property) => get(property, attrName) === attrValue)
const createMeta = (req) => { const { auth, hash, host, hostname, method, port, slashes } = req const protocol = 'https:' const base = `${protocol}//${hostname}/` return { auth, hash, host, hostname, method, port, protocol, slashes, uri: new URL(req.originalUrl, base) } }
const platforms = { 'airbnb': 'airbnbPropertyId', 'homeaway': 'homeawayPropertyId' } const getPlatform = (req) => get(req.query, 'platform', platforms.airbnb) const isPlatformAirbnb = (req) => getPlatform(req) === platforms.airbnb const getPropertyId = (req) => { let propertyId = get(req.params, 'propertyId', null) if (isPlatformAirbnb(req)) { propertyId = toInteger(propertyId) } return propertyId } const getByPropertyId = (req, listings) => { let body = listings.valueOf() const propertyId = getPropertyId(req) if (propertyId) { const platform = getPlatform(req) const property = findBy(body.properties, platform, propertyId) console.log(property, propertyId, platform) if (property) { body.properties = [property] } } return body }
const getListings = (req, paginationInfo) => { let body = listings.valueOf() Object.assign(body.meta, createMeta(req)) body = getByPropertyId(req, listings) const ONE = 1 if (body.properties.length !== ONE) { const { filter, orderBy, orders } = req.query if (filter) { if (filter.propertyType) { body.properties = filterByType(body.properties, filter.propertyType) } } if (orderBy) { body.properties = lodashOrderBy(body.properties, orderBy, orders) } // if (req.query.limit) { // const begin = paginationInfo.perPage * req.query.limit // const end = req.query.limit // body.properties = body.properties.slice(begin, end) // } } body.listingsReturned = body.properties.length return pickFields(req, body) }
const paginate = require('paginate-array') const getPaginationOpts = (req) => { return { perPage: req.query.limit || 100, pageNumber: 1, prefix: 'x-listings' } } const createPaginationInfo = (listings, req) => { const { pageNumber, perPage } = getPaginationOpts(req) return paginate (listings.properties, [ null, pageNumber, perPage ]) } const setPaginationHeaders = (response, paginationInfo, req) => { const { prefix, perPage } = getPaginationOpts(req) const currentPage = isNaN(paginationInfo.currentPage) ? 1 : paginationInfo.currentPage response.setHeader(`${prefix}-current-page`, currentPage) response.setHeader(`${prefix}-per-page`, perPage) response.setHeader(`${prefix}-total-pages`, paginationInfo.totalPages) response.setHeader(`${prefix}-total`, paginationInfo.total) return response }
const setResponseHeaders = (response, data, req) => { const paginationInfo = createPaginationInfo(data, req) setPaginationHeaders(response, paginationInfo, req) response.setHeader('content-type', 'application/json') return paginationInfo }
const express = require('@runkit/runkit/express-endpoint/1.0.0') const app = express(module.exports) app.get('/', (req, res) => { const body = getListings(req) setResponseHeaders(res, body, req) res.send(JSON.stringify(body)) }) app.get('/properties/:propertyId', (req, res) => { const body = getListings(req) setResponseHeaders(res, body, req) res.send(JSON.stringify(body)) })
Loading…

no comments

    sign in to comment