class SgDeliverySlotChecker::Stores::Fairprice

Attributes

postal_code[R]

Public Class Methods

new(postal_code:) click to toggle source
# File lib/sg_delivery_slot_checker/stores/fairprice.rb, line 7
def initialize(postal_code:)
  @postal_code = postal_code
end

Public Instance Methods

available?() click to toggle source
# File lib/sg_delivery_slot_checker/stores/fairprice.rb, line 11
def available?
  if store_id
    get_availability(store: store_id)
  else
    false
  end
end

Private Instance Methods

get_availability(store:) click to toggle source
# File lib/sg_delivery_slot_checker/stores/fairprice.rb, line 28
def get_availability(store:)
  response = HTTParty.get("https://website-api.omni.fairprice.com.sg/api/slot-availability?address[pincode]=\"#{postal_code}\"&storeId=#{store}")
  response.parsed_response&.dig("data", "available")
end
store_id() click to toggle source
# File lib/sg_delivery_slot_checker/stores/fairprice.rb, line 23
def store_id
  response = HTTParty.get("https://website-api.omni.fairprice.com.sg/api/serviceable-area?city=Singapore&pincode=\"#{postal_code}\"")
  response.parsed_response&.dig("data", "store", "id")
end