Sha256: 2f729efaafb89d6c2e9536a0bdb5336b6da37dcd86005b3e9459017c61b2c6b9

Contents?: true

Size: 659 Bytes

Versions: 1

Compression:

Stored size: 659 Bytes

Contents

require 'httparty'
require 'hashie'

module SgDeliverySlotChecker
  module Stores
    class ColdStorage

      def initialize(postal_code:)
        @postal_code = postal_code
      end

      def available?
        get_availability
      end

      private

      attr_reader :postal_code

      def get_availability
        response = HTTParty.post('https://coldstorage.com.sg/checkout/cart/checkdelivery',
          body: {
            'postal_code': postal_code
          }
        )
        slots = response.parsed_response
        slots.extend Hashie::Extensions::DeepFind
        slots.deep_find_all("available").any?(true)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sg_delivery_slot_checker-0.2.0 lib/sg_delivery_slot_checker/stores/cold_storage.rb