Sha256: d2e0251b8759cb15e541be2c6dabedba622bb557fabf8846cf8e1f708af539ec

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

require 'quick_travel/adapter'
require 'quick_travel/bed_requirement'
require 'quick_travel/passenger_price_break'
require 'quick_travel/product_type'

module QuickTravel
  class Resource < Adapter
    self.api_base = '/resources'

    def sub_resources
      Resource.find_all!('/resources.json', parent_resource_id: @id)
    end

    def self.all_with_price(opts)
      cache_key = GenerateCacheKey.new(name, opts).call
      find_all!("/api/resources/index_with_price.json", opts.merge(cache: cache_key))
    end

    def product_type
      QuickTravel::ProductType.find(product_type_id)
    end

    def bed_requirements
      @_bed_requirements ||= Array.wrap(@bed_requirements).map do |bed_requirement|
        BedRequirement.new(bed_requirement)
      end
    end

    private

    class GenerateCacheKey
      def initialize(resource_name, opts)
        @resource_name = resource_name
        @opts = opts
      end

      def call
        "#{@resource_name}.all_with_price-attrs?#{cache_params.to_param}"
      end

      private

      def cache_params
        { date: Date.current }.merge(@opts.symbolize_keys)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
quicktravel_client-3.6.1 lib/quick_travel/resource.rb
quicktravel_client-3.6.0 lib/quick_travel/resource.rb
quicktravel_client-3.5.0 lib/quick_travel/resource.rb
quicktravel_client-3.4.0 lib/quick_travel/resource.rb
quicktravel_client-3.3.0 lib/quick_travel/resource.rb
quicktravel_client-3.2.0 lib/quick_travel/resource.rb
quicktravel_client-3.1.0 lib/quick_travel/resource.rb
quicktravel_client-3.0.0 lib/quick_travel/resource.rb
quicktravel_client-2.9.0 lib/quick_travel/resource.rb
quicktravel_client-2.8.0 lib/quick_travel/resource.rb
quicktravel_client-2.7.0 lib/quick_travel/resource.rb
quicktravel_client-2.6.0 lib/quick_travel/resource.rb
quicktravel_client-2.5.0 lib/quick_travel/resource.rb
quicktravel_client-2.4.1 lib/quick_travel/resource.rb
quicktravel_client-2.4.0 lib/quick_travel/resource.rb
quicktravel_client-2.3.1 lib/quick_travel/resource.rb
quicktravel_client-2.3.0 lib/quick_travel/resource.rb