duffelhq / duffel-api-ruby

Ruby client library for the Duffel API
https://duffel.com/docs
MIT License
6 stars 6 forks source link

How to access methods/variables inside a "DuffelAPI::Resources::Offer:" object returned by the client? #91

Closed 34code closed 1 year ago

34code commented 1 year ago
offer_request = client.offer_requests.create(params: {
      cabin_class: flight_class,
      passengers: [{
        age: age
      }],
      slices: [{
        origin: @origin,
        destination: @destination,
        departure_date: departure_date,
      }],
      return_offers: false
    })

    Rails.logger.info("Created #{flight_class}-class offer request: #{offer_request.id}")
    offers = client.offers.all(params: { offer_request_id: offer_request.id, sort: "total_amount"})
    first_seven_offers = offers.first(7)

Now, how can I get the price out of the first_seven_offers?

ulissesalmeida commented 1 year ago

Hi @34code , you should do something like:

first_seven_offers.each do |offer|
  puts "Offer price: #{offer.total_currency} #{offer.total_amount}"
end

You can take a look in the list of attributes here: https://github.com/duffelhq/duffel-api-ruby/blob/main/lib/duffel_api/resources/offer.rb#L7-L26

The docs of what each attribute means you can find here: https://duffel.com/docs/api/v1/offers/schema#offers-schema-total-amount

Have a great day!