Sha256: 1f57ff99bdb0b6da97a32d34bb24ed84eea0e2595b25c869ae8c44ba52d6f830

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

require 'httparty'

module SgDeliverySlotChecker
  module Stores
    class Fairprice

      def initialize(postal_code:)
        @postal_code = postal_code
      end

      def available?
        if store_id
          get_availability(store: store_id)
        else
          false
        end
      end

      private

      attr_reader :postal_code

      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

      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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sg_delivery_slot_checker-0.2.0 lib/sg_delivery_slot_checker/stores/fairprice.rb
sg_delivery_slot_checker-0.1.0 lib/sg_delivery_slot_checker/stores/fairprice.rb