ruby client to Wego API.
Add this line to your application's Gemfile:
gem 'wego'
And then execute:
$ bundle
Or install it yourself as:
$ gem install wego
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
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.
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
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))
To run integration tests locally, set WEGO_API
environment variable and run:
WEGO_API=yourapikey rspec spec/integration
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request