Skip to content

Latest commit

 

History

History
115 lines (80 loc) · 2.62 KB

README.md

File metadata and controls

115 lines (80 loc) · 2.62 KB

Wego Build Status

ruby client to Wego API.

Installation

Add this line to your application's Gemfile:

gem 'wego'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wego

Basic Example

require 'wego'

Wego.configure do |config|
  config.api_key = 'yourapikey'
end

puts Wego::Flights.usage

search = Wego::Flights.search({
  :from_location => 'LAX',
  :to_location   => 'SFO',
  :trip_type     => 'roundTrip',
  :cabin_class   => 'Economy',
  :inbound_date  => '2010-06-26',
  :outbound_date => '2010-06-23',
  :num_adults    => 1,
  :ts_code       => 'a7557'
})

search.itineraries.each do |i|
  puts i.origin_country_code
  puts i.destination_country_code
  puts i.price.amount + i.price.currency_code
  puts i.booking_url

  i.outbound_segments.each do |s|
    puts s.flight_number.designator
    puts s.duration_in_min
  end
end

Flight Results Fetch Interval

By default, this gem follows Wego's recommended polling interval:

Wego recommends API consumers to do at least 10 polling with 5 seconds interval.

To change this, configure your own Wego::Flights::Client:

client = Wego::Flights::Client.new(:pull_wait => 4.0, :pull_count => 2)
client.search({...})

This gem polls for results using a periodic EventMachine timer. It is Fiber aware and can be used with em-synchrony.

Logging

A ruby Logger can be configured to see intermediate steps:

logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG

Wego.configure do |config|
  config.logger = logger
end

Caching

An ActiveSupport compatible cache store can be used to cache results. See this blog post for an introduction to cache stores.

# share same cache as Rails
Wego::Flights::Client.new(:cache => Rails.cache)

# generic usage
Wego::Flights::Client.new(:cache => ActiveSupport::Cache.lookup_store(:memory_store))

Development

To run integration tests locally, set WEGO_API environment variable and run:

WEGO_API=yourapikey rspec spec/integration

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request