-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added round trip option to google flight agent #1384
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ class GoogleFlightsAgent < Agent | |
|
||
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 @@ def default_options | |
'infantInSeatCount' => 0, | ||
'infantInLapCount'=> 0, | ||
'seniorCount'=> 0, | ||
'returned_date' => '2016-04-18', | ||
'roundtrip' => true, | ||
'solutions'=> 3 | ||
} | ||
end | ||
|
@@ -69,8 +73,10 @@ def default_options | |
form_configurable :infantInSeatCount | ||
form_configurable :infantInLapCount | ||
form_configurable :seniorCount | ||
form_configurable :roundtrip, type: :boolean | ||
form_configurable :returned_date, type: :string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 @@ def validate_options | |
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
YYYY-MM-DD
?"Make sure
date
andreturned_date
are in the formatYYYY-MM-DD
."