Class: MockSearch
- Inherits:
-
Object
- Object
- MockSearch
- Defined in:
- lib/mock_search.rb
Direct Known Subclasses
MockSearchMultipledestinations, MockSearchMultipleoneway, 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
- #des ⇒ Object
- #digest_md5 ⇒ Object
- #encrypt(key, value) ⇒ 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_disambiguation_airports(city) ⇒ Object
genero una url para ingresar a desambiguacion de aeropuertos.
-
#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(type = "TOTALFARE") ⇒ Object
- #get_results_search_service_streaming(type = "TOTALFARE") ⇒ Object
- #get_ticket_date ⇒ Object
-
#initialize(site, env, cabotage, params = {}) ⇒ MockSearch
constructor
A new instance of MockSearch.
- #paginate(page) ⇒ Object
- #passengers ⇒ Object
- #reset_json ⇒ Object
- #set_from_city(code) ⇒ Object
- #set_header_json(header = {}) ⇒ 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.
13 14 15 16 17 18 |
# File 'lib/mock_search.rb', line 13 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.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def adt @adt end |
#cabotage ⇒ Object (readonly)
Returns the value of attribute cabotage.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def cabotage @cabotage end |
#cnn ⇒ Object (readonly)
Returns the value of attribute cnn.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def cnn @cnn end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def host @host end |
#inf ⇒ Object (readonly)
Returns the value of attribute inf.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def inf @inf end |
#itinerary ⇒ Object (readonly)
Returns the value of attribute itinerary.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def itinerary @itinerary end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
11 12 13 |
# File 'lib/mock_search.rb', line 11 def json @json end |
Instance Method Details
#des ⇒ Object
140 141 142 143 144 |
# File 'lib/mock_search.rb', line 140 def des() up_temp = self.encrypt("RTBLL744", (Time.now.to_f * 1000).to_i.to_s) up_final = self.encrypt("G3N1S*72", digest_md5()+Base64.encode64(up_temp).force_encoding('UTF-8').gsub(/\n/, "")) return ERB::Util.url_encode(Base64.encode64(up_final).force_encoding('UTF-8').gsub(/\n/, "")) end |
#digest_md5 ⇒ Object
129 130 131 |
# File 'lib/mock_search.rb', line 129 def digest_md5() return Digest::MD5.hexdigest(self.generate_url_results_search+"despegar") end |
#encrypt(key, value) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/mock_search.rb', line 133 def encrypt(key,value) des = OpenSSL::Cipher::Cipher.new 'DES-CBC' des.encrypt des.key = key return des.update(value) + des.final 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.
21 22 23 24 |
# File 'lib/mock_search.rb', line 21 def generar_host(site,env) host = YAML.load(File.open("features/data/host.yml")) return host[site][env] end |
#generate_post_alert_url ⇒ Object
40 41 42 |
# File 'lib/mock_search.rb', line 40 def generate_post_alert_url() return @host + "/subscriptions-ui/subscriptions/price-alert-by-month/add" end |
#generate_url_checkout ⇒ Object
124 125 126 127 |
# File 'lib/mock_search.rb', line 124 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
45 46 47 48 49 50 51 |
# File 'lib/mock_search.rb', line 45 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
54 55 56 57 58 59 60 |
# File 'lib/mock_search.rb', line 54 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_disambiguation_airports(city) ⇒ Object
genero una url para ingresar a desambiguacion de aeropuertos
72 73 74 75 76 |
# File 'lib/mock_search.rb', line 72 def generate_url_landing_disambiguation_airports(city) @path = "#{@city_from_1.code}/#{city}/" landing = (@site == "BR" ? "/passagens-aereas/" : "/vuelos/") return @host + landing + @path end |
#generate_url_landing_origin_airport(origin, dest) ⇒ Object
genero la url de resultados de landing para filtrar por aeropuerto origen
63 64 65 66 67 68 69 |
# File 'lib/mock_search.rb', line 63 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
78 79 80 |
# File 'lib/mock_search.rb', line 78 def get_childrens @cnn + @inf end |
#get_results_search_service(type = "TOTALFARE") ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/mock_search.rb', line 95 def get_results_search_service(type="TOTALFARE") set_header_json({"referer"=>self.generate_url_results_search}) set_header_json({"User-Agent"=>"Mozilla\/5.0"}) unless @json @json = HTTParty.get(self.generate_url_results_search_service(type),:headers => @header) end return @json end |
#get_results_search_service_streaming(type = "TOTALFARE") ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/mock_search.rb', line 104 def get_results_search_service_streaming(type="TOTALFARE") set_header_json({"referer"=>self.generate_url_results_search}) set_header_json({"User-Agent"=>"Mozilla\/5.0"}) unless @json @json = HTTParty.get(self.generate_url_results_search_service_streaming(type),:headers => @header) end return @json end |
#get_ticket_date ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mock_search.rb', line 113 def get_ticket_date() @result_hash = {} json = JSON.parse(self.get_results_search_service) @itinerary = json['result']['data']['items'][0] ticket = json['result']['data']['metadata']['ticket'] @result_hash['search_hash'] = ticket['id'] @result_hash['search_version'] = ticket['version'] end |
#paginate(page) ⇒ Object
146 147 148 149 |
# File 'lib/mock_search.rb', line 146 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']['id'])) end |
#passengers ⇒ Object
26 27 28 29 30 31 |
# File 'lib/mock_search.rb', line 26 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 |
#reset_json ⇒ Object
151 152 153 |
# File 'lib/mock_search.rb', line 151 def reset_json @json = nil end |
#set_from_city(code) ⇒ Object
82 83 84 |
# File 'lib/mock_search.rb', line 82 def set_from_city(code) @city_from_1 = MockCity.new(@site,code) end |
#set_header_json(header = {}) ⇒ Object
90 91 92 93 |
# File 'lib/mock_search.rb', line 90 def set_header_json(header={}) @header ||= {} @header.merge!(header) end |