Class: MockSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adtObject (readonly)

Returns the value of attribute adt.



11
12
13
# File 'lib/mock_search.rb', line 11

def adt
  @adt
end

#cabotageObject (readonly)

Returns the value of attribute cabotage.



11
12
13
# File 'lib/mock_search.rb', line 11

def cabotage
  @cabotage
end

#cnnObject (readonly)

Returns the value of attribute cnn.



11
12
13
# File 'lib/mock_search.rb', line 11

def cnn
  @cnn
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/mock_search.rb', line 11

def host
  @host
end

#infObject (readonly)

Returns the value of attribute inf.



11
12
13
# File 'lib/mock_search.rb', line 11

def inf
  @inf
end

#itineraryObject (readonly)

Returns the value of attribute itinerary.



11
12
13
# File 'lib/mock_search.rb', line 11

def itinerary
  @itinerary
end

#jsonObject (readonly)

Returns the value of attribute json.



11
12
13
# File 'lib/mock_search.rb', line 11

def json
  @json
end

Instance Method Details

#desObject



108
109
110
111
112
# File 'lib/mock_search.rb', line 108

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_md5Object



97
98
99
# File 'lib/mock_search.rb', line 97

def digest_md5()
  return Digest::MD5.hexdigest(self.generate_url_results_search+"despegar")
end

#encrypt(key, value) ⇒ Object



101
102
103
104
105
106
# File 'lib/mock_search.rb', line 101

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_urlObject



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_checkoutObject



92
93
94
95
# File 'lib/mock_search.rb', line 92

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

#get_childrensObject



44
45
46
# File 'lib/mock_search.rb', line 44

def get_childrens
  @cnn + @inf
end

#get_results_search_service(type = "TOTALFARE") ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/mock_search.rb', line 61

def get_results_search_service(type="TOTALFARE")
  set_header_json({"referer"=>self.generate_url_results_search})
  set_header_json({"User-Agent"=>"Mozilla\/5.0"})
  set_header_json({"XDESP-TEST"=>"true"})
  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



71
72
73
74
75
76
77
78
79
# File 'lib/mock_search.rb', line 71

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"})
  set_header_json({"XDESP-TEST"=>"true"})
  unless @json
    @json = HTTParty.get(self.generate_url_results_search_service_streaming(type),:headers => @header)
  end  
  return @json
end

#get_ticket_dateObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/mock_search.rb', line 81

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



114
115
116
117
# File 'lib/mock_search.rb', line 114

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

#passengersObject



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_jsonObject



119
120
121
# File 'lib/mock_search.rb', line 119

def reset_json
  @json = nil
end

#set_from_city(code) ⇒ Object



48
49
50
# File 'lib/mock_search.rb', line 48

def set_from_city(code)
  @city_from_1 = MockCity.new(@site,code)
end

#set_header_json(header = {}) ⇒ Object



56
57
58
59
# File 'lib/mock_search.rb', line 56

def set_header_json(header={})
  @header ||= {} 
  @header.merge!(header)
end

#set_to_city(code) ⇒ Object



52
53
54
# File 'lib/mock_search.rb', line 52

def set_to_city(code)
  @city_to_1 = MockCity.new(@site,code)
end

#to_city_change(site) ⇒ Object



33
34
35
36
37
38
# File 'lib/mock_search.rb', line 33

def to_city_change(site)
	unless site == @site
		@city_to_1 = MockCity.new(site)
		@path    = @path.gsub(/^...\/...\//,"#{@city_from_1.code}/#{@city_to_1.code}/")
	end	
end