added round trip option to google flight agent

This commit is contained in:
Judy Ngai 2016-03-28 15:24:28 -04:00
parent 16c0505a0a
commit d465cbffb5
2 changed files with 27 additions and 3 deletions

View file

@ -16,7 +16,9 @@ module Agents
All the default options must exist. For `infantInSeatCount`, `infantInLapCount`, `seniorCount`, and `childCount`, leave them to the default value of `0` if its not necessary.
Make sure `date` is in this type of date format `YYYY-MO-DAY`.
Make sure `date` and `returned_date` is in this type of date format `YYYY-MO-DAY`.
You can choose one way ticket only by setting `roundtrip` to `false`.
You can limit the number of `solutions` returned back. The first solution is the lowest priced ticket.
MD
@ -56,6 +58,8 @@ module Agents
'infantInSeatCount' => 0,
'infantInLapCount'=> 0,
'seniorCount'=> 0,
'returned_date' => '2016-04-18',
'roundtrip' => true,
'solutions'=> 3
}
end
@ -69,8 +73,10 @@ module Agents
form_configurable :infantInSeatCount
form_configurable :infantInLapCount
form_configurable :seniorCount
form_configurable :roundtrip, type: :boolean
form_configurable :returned_date, type: :string
form_configurable :solutions
def validate_options
errors.add(:base, "You need a qpx api key") unless options['qpx_api_key'].present?
errors.add(:base, "Adult Count must exist") unless options['adultCount'].present?
@ -82,14 +88,26 @@ module Agents
errors.add(:base, "Infant In Lap Count") unless options['infantInLapCount'].present?
errors.add(:base, "Senior Count must exist") unless options['seniorCount'].present?
errors.add(:base, "Solutions must exist") unless options['solutions'].present?
errors.add(:base, "Returned Date must exist") if options["returned_date"].blank? && boolify(options['roundtrip'])
end
def working?
!recent_error_logs?
end
def round_trip?
boolify(interpolated['roundtrip'])
end
def post_params
if round_trip?
post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[ {:origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }, {:origin=> interpolated["destination"].to_s , :destination=> interpolated["origin"].to_s , :date=> interpolated["returned_date"].to_s } ], :solutions=> interpolated["solutions"]}}
else
post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[{:kind=>"qpxexpress#sliceInput", :origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }], :solutions=> interpolated["solutions"]}}
end
end
def check
post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[{:kind=>"qpxexpress#sliceInput", :origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }], :solutions=> interpolated["solutions"]}}
body = JSON.generate(post_params)
request = HTTParty.post(event_url, :body => body, :headers => {"Content-Type" => "application/json"})
events = JSON.parse request.body

View file

@ -87,6 +87,12 @@ describe Agents::GoogleFlightsAgent do
@checker.options['solutions'] = nil
expect(@checker).not_to be_valid
end
it "should require Returned Date" do
@checker.options['roundtrip'] = true
@checker.options['returned_date'] = nil
expect(@checker).not_to be_valid
end
end
describe '#check' do