changed to form configurable, name changed, small clarifications

This commit is contained in:
Judy Ngai 2016-03-24 16:17:33 -04:00
parent c206369fdc
commit 5fb7dd5d88
2 changed files with 17 additions and 5 deletions

View file

@ -1,17 +1,18 @@
module Agents
class QpxAgent < Agent
class GoogleFlightsAgent < Agent
include FormConfigurable
cannot_receive_events!
default_schedule "every_12h"
description <<-MD
The QpxExpressAgent will tell you the minimum airline prices between a pair of cities. The api limit is 50 requests/day.
The GoogleFlightsAgent will tell you the minimum airline prices between a pair of cities. The api limit is 50 requests/day.
Follow their documentation here (https://developers.google.com/qpx-express/v1/prereqs#get-a-google-account) to retrieve an api key.
After you get to the google developer console, created a project, enabled qpx express api then you can choose `api key` credential to be created.
`Origin` and `Destination` requires `airport code`.
The `origin` and `destination` options require an [airport code](http://www.expedia.com/daily/airports/AirportCodes.asp).
All the default options must exist. For `infantInSeatCount`, `infantInLapCount`, `seniorCount`, and `childCount`, leave them to the default value of `0` if its not necessary.
@ -59,6 +60,17 @@ module Agents
}
end
form_configurable :qpx_api_key, type: :string
form_configurable :adultCount
form_configurable :origin
form_configurable :destination
form_configurable :date
form_configurable :childCount
form_configurable :infantInSeatCount
form_configurable :infantInLapCount
form_configurable :seniorCount
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?

View file

@ -1,6 +1,6 @@
require 'rails_helper'
describe Agents::QpxAgent do
describe Agents::GoogleFlightsAgent do
before do
stub_request(:post, "https://www.googleapis.com/qpxExpress/v1/trips/search?key=800deeaf-e285-9d62-bc90-j999c1973cc9").to_return(
@ -22,7 +22,7 @@ describe Agents::QpxAgent do
'solutions'=> 3
}
@checker = Agents::QpxAgent.new(:name => "tectonic", :options => @opts)
@checker = Agents::GoogleFlightsAgent.new(:name => "tectonic", :options => @opts)
@checker.user = users(:bob)
@checker.save!
end