Class: MockSearch
- Inherits:
-
Object
- Object
- MockSearch
- Defined in:
- lib/mock_search.rb
Direct Known Subclasses
MockSearchMultipledestinations, MockSearchOneway, MockSearchRoundtrip
Instance Attribute Summary collapse
-
#adt ⇒ Object
readonly
Returns the value of attribute adt.
-
#cabotage ⇒ Object
readonly
Returns the value of attribute cabotage.
-
#cnn ⇒ Object
readonly
Returns the value of attribute cnn.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#inf ⇒ Object
readonly
Returns the value of attribute inf.
-
#itinerary ⇒ Object
readonly
Returns the value of attribute itinerary.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #digest_md5 ⇒ Object
-
#generar_host(site, env) ⇒ Object
genero el host de la url a la cual nos vamos a conectar, se genera a partir del pais y ambiente enviados como parametros.
- #generate_post_alert_url ⇒ Object
- #generate_url_checkout ⇒ Object
-
#generate_url_landing_airline(code, dest) ⇒ Object
genero la url de resultados de landing para filtrar por aerolinea.
-
#generate_url_landing_arrival_airport(dest) ⇒ Object
genero la url de resultados de landing para filtrar por aeropuerto destino.
-
#generate_url_landing_origin_airport(origin, dest) ⇒ Object
genero la url de resultados de landing para filtrar por aeropuerto origen.
- #get_childrens ⇒ Object
- #get_results_search_service ⇒ Object
- #get_ticket_date ⇒ Object
-
#initialize(site, env, cabotage, params = {}) ⇒ MockSearch
constructor
A new instance of MockSearch.
- #paginate(page) ⇒ Object
- #passengers ⇒ Object
- #set_from_city(code) ⇒ Object
- #set_to_city(code) ⇒ Object
- #to_city_change(site) ⇒ Object
Constructor Details
#initialize(site, env, cabotage, params = {}) ⇒ MockSearch
Returns a new instance of MockSearch.
11 12 13 14 15 16 |
# File 'lib/mock_search.rb', line 11 def initialize(site,env,cabotage,params={}) @site = site @host = generar_host(site,env) @cabotage = (cabotage=='true') @json = nil end |
Instance Attribute Details
#adt ⇒ Object (readonly)
Returns the value of attribute adt.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def adt @adt end |
#cabotage ⇒ Object (readonly)
Returns the value of attribute cabotage.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def cabotage @cabotage end |
#cnn ⇒ Object (readonly)
Returns the value of attribute cnn.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def cnn @cnn end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def host @host end |
#inf ⇒ Object (readonly)
Returns the value of attribute inf.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def inf @inf end |
#itinerary ⇒ Object (readonly)
Returns the value of attribute itinerary.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def itinerary @itinerary end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
9 10 11 |
# File 'lib/mock_search.rb', line 9 def json @json end |
Instance Method Details
#digest_md5 ⇒ Object
104 105 106 |
# File 'lib/mock_search.rb', line 104 def digest_md5() return Digest::MD5.hexdigest(self.generate_url_results_search+"despegar") end |
#generar_host(site, env) ⇒ Object
genero el host de la url a la cual nos vamos a conectar, se genera a partir del pais y ambiente enviados como parametros.
19 20 21 22 |
# File 'lib/mock_search.rb', line 19 def generar_host(site,env) host = YAML.load(File.open("features/data/host.yml")) return host[site][env] end |
#generate_post_alert_url ⇒ Object
38 39 40 |
# File 'lib/mock_search.rb', line 38 def generate_post_alert_url() return @host + "/subscriptions-ui/subscriptions/price-alert-by-month/add" end |
#generate_url_checkout ⇒ Object
99 100 101 102 |
# File 'lib/mock_search.rb', line 99 def generate_url_checkout() self.get_ticket_date() return @host.gsub('http','https') + "/book/flights/checkout/#{@result_hash['search_hash']}/#{@result_hash['search_version']}/#{@result_hash['itinerary_hash']}/" end |
#generate_url_landing_airline(code, dest) ⇒ Object
genero la url de resultados de landing para filtrar por aerolinea
43 44 45 46 47 48 49 |
# File 'lib/mock_search.rb', line 43 def generate_url_landing_airline(code,dest) path = case @site when "BR" then "/passagens-aereas/companhiasaerea" else "/vuelos/aerolinea" end return @host + path + "/#{dest}/#{code}/vuelos" end |
#generate_url_landing_arrival_airport(dest) ⇒ Object
genero la url de resultados de landing para filtrar por aeropuerto destino
52 53 54 55 56 57 58 |
# File 'lib/mock_search.rb', line 52 def generate_url_landing_arrival_airport(dest) path = case @site when "BR" then "/passagens-aereas/aeroporto" else "/vuelos/aeropuerto" end return @host + path + "/#{dest}/vuelos" end |
#generate_url_landing_origin_airport(origin, dest) ⇒ Object
genero la url de resultados de landing para filtrar por aeropuerto origen
61 62 63 64 65 66 67 |
# File 'lib/mock_search.rb', line 61 def generate_url_landing_origin_airport(origin,dest) path = case @site when "BR" then "/passagens-aereas/aeroporto" else "/vuelos/aeropuerto" end return @host + path + "/#{origin}/#{dest}/vuelos" end |
#get_childrens ⇒ Object
69 70 71 |
# File 'lib/mock_search.rb', line 69 def get_childrens @cnn + @inf end |
#get_results_search_service ⇒ Object
81 82 83 84 85 86 |
# File 'lib/mock_search.rb', line 81 def get_results_search_service unless @json @json = HTTParty.get(self.generate_url_results_search_service,:headers => {"referer" => self.generate_url_results_search}) end return @json end |
#get_ticket_date ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mock_search.rb', line 88 def get_ticket_date() @result_hash = {} json = self.get_results_search_service @itinerary = json['result']['data']['items'][0] ticket = json['result']['data']['metadata']['ticket'] @result_hash['search_hash'] = ticket['hash'] @result_hash['search_version'] = ticket['version'] end |
#paginate(page) ⇒ Object
108 109 110 111 |
# File 'lib/mock_search.rb', line 108 def paginate(page) json = self.get_results_search_service return HTTParty.get(self.generate_url_results_search_paginate_service(page,json['result']['data']['metadata']['ticket']['hash'])) end |
#passengers ⇒ Object
24 25 26 27 28 29 |
# File 'lib/mock_search.rb', line 24 def passengers() @adt = [1,2,3][rand(3)] @cnn = [0,1,2][rand(@adt)] @inf = [0,1,2][rand(@adt-@cnn)] return "#{@adt}/#{@cnn}/#{@inf}" end |
#set_from_city(code) ⇒ Object
73 74 75 |
# File 'lib/mock_search.rb', line 73 def set_from_city(code) @city_from_1 = MockCity.new(@site,code) end |