Class: Transparent::Client
- Inherits:
-
Object
- Object
- Transparent::Client
- Extended by:
- T::Sig
- Defined in:
- lib/transparent/client.rb
Overview
API wrapper/client
Instance Method Summary collapse
- #aggregated ⇒ Object
- #combined ⇒ Object
-
#initialize(latitude:, longitude:, radius_meters:, type:, subtype:, bedrooms: [], bathrooms: [], capacity: [], pool: nil, air_conditioning: nil, kid_friendly: nil, parking: nil, hot_tub: nil, active_days: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(latitude:, longitude:, radius_meters:, type:, subtype:, bedrooms: [], bathrooms: [], capacity: [], pool: nil, air_conditioning: nil, kid_friendly: nil, parking: nil, hot_tub: nil, active_days: nil) ⇒ Client
Returns a new instance of Client.
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 58 59 60 61 62 63 64 65 |
# File 'lib/transparent/client.rb', line 30 def initialize( latitude:, longitude:, radius_meters:, type:, subtype:, bedrooms: [], bathrooms: [], capacity: [], pool: nil, air_conditioning: nil, kid_friendly: nil, parking: nil, hot_tub: nil, active_days: nil ) @latitude = latitude @longitude = longitude @radius_meters = radius_meters @type = type @subtype = subtype @optional_params = { bedrooms: normalise_list(bedrooms), bathrooms: normalise_list(bathrooms), capacity: normalise_list(capacity), pool: normalise_boolean(pool), air_conditioning: normalise_boolean(air_conditioning), kid_friendly: normalise_boolean(kid_friendly), parking: normalise_boolean(parking), hot_tub: normalise_boolean(hot_tub), active_days: active_days }.select do |_key, value| value && !value.to_s.empty? end end |
Instance Method Details
#aggregated ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/transparent/client.rb', line 67 def aggregated aggregated_request.run return { fulfilled: false } if aggregated_response.body.empty? || !aggregated_response.success? { fulfilled: true, data: { adr: aggregated_object['year_average_adr'], occupancy: aggregated_object['year_average_occupancy'] } } end |
#combined ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/transparent/client.rb', line 81 def combined parallel_listings_and_aggregated_requests.run return { fulfilled: false } unless both_responses_are_good? { fulfilled: true, data: { adr: aggregated_object['year_average_adr'], occupancy: aggregated_object['year_average_occupancy'], listings: listings_object.map do |listing| { adr: listing['year_total_revenue'].to_f / listing['active_days'], occupancy: listing['year_total_occupancy'] } end } } end |