From 5fb7dd5d8834cc9e3623766d720474f016f01d55 Mon Sep 17 00:00:00 2001 From: Judy Ngai Date: Thu, 24 Mar 2016 16:17:33 -0400 Subject: [PATCH] changed to form configurable, name changed, small clarifications --- .../{qpx_agent.rb => google_flights_agent.rb} | 18 +++++++++++++++--- .../{qpx_spec.rb => google_flights_spec.rb} | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) rename app/models/agents/{qpx_agent.rb => google_flights_agent.rb} (83%) rename spec/models/agents/{qpx_spec.rb => google_flights_spec.rb} (95%) diff --git a/app/models/agents/qpx_agent.rb b/app/models/agents/google_flights_agent.rb similarity index 83% rename from app/models/agents/qpx_agent.rb rename to app/models/agents/google_flights_agent.rb index 18be49b8..75e41a7e 100644 --- a/app/models/agents/qpx_agent.rb +++ b/app/models/agents/google_flights_agent.rb @@ -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? diff --git a/spec/models/agents/qpx_spec.rb b/spec/models/agents/google_flights_spec.rb similarity index 95% rename from spec/models/agents/qpx_spec.rb rename to spec/models/agents/google_flights_spec.rb index d6bb2a28..fee00738 100644 --- a/spec/models/agents/qpx_spec.rb +++ b/spec/models/agents/google_flights_spec.rb @@ -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