Sha256: 2b759e294b768a413af52db73e95267d793d82709ad0815e3450af7b110c8eaf

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# typed: true

module BungieSdk::Destiny2
  # Represents vendors in Destiny 2
  class Vendor < ApiAgent
    # Signifies if the definition request has failed
    sig { returns T::Boolean }
    attr_reader :failed_definition

    # Vendor id
    sig { returns Integer }
    def id
      data['vendorData']['vendorHash']
    end

    # Vendor name
    sig { returns String }
    def name
      definition['displayProperties']['name'] rescue ''
    end

    # Vendor sales
    sig { returns T::Array[Hash] }
    def sales
      data['sales']['saleItems'].values
    end

    # Request for vendor's definition
    sig { returns Typhoeus::Request }
    def definition_request
      request = vendor_definition(data['vendorData']['vendorHash'])
      request.on_success do |response|
        response           = process_response(response)
        data['definition'] = response.body
      end

      request.on_failure {|_| @failed_definition = true }

      request
    end

    # Vendor definition
    sig { returns Hash }
    def definition
      return {} if @failed_definition

      if data['definition'].nil?
        definition_request.run
      end

      data['definition']
    end

    # Vendor items
    sig { returns T::Array[Item] }
    def items
      sales.map {|sale| Item.new(sale) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bungie_sdk-0.1.2 lib/bungie_sdk/vendor.rb