Class: Kayak::Session

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

Constant Summary collapse

USER_AGENT =
"Mozilla/5.0 (compatible; RubyKayak/#{Kayak::VERSION::STRING}; http://kayak.rubyforge.org)"
URL =
URI.parse('http://www.kayak.com')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Session

Returns a new instance of Session.



15
16
17
# File 'lib/kayak/session.rb', line 15

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/kayak/session.rb', line 13

def id
  @id
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



13
14
15
# File 'lib/kayak/session.rb', line 13

def last_response
  @last_response
end

Class Method Details

.create(token) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/kayak/session.rb', line 19

def self.create(token)
  response = REXML::Document.new(get('/k/ident/apisession', :token => token))
  if session_id = response.elements['//sid'].text
    Session.new session_id
  else
    raise TokenError, response.elements['//error'].text
  end
end

.get(path, params) ⇒ Object



54
55
56
# File 'lib/kayak/session.rb', line 54

def self.get(path, params)
  make_url(path, params).open('User-Agent' => USER_AGENT).read
end

Instance Method Details

#get(path, params = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/kayak/session.rb', line 45

def get(path, params = {})
  REXML::Document.new(@last_response = self.class.get(path, params))
#   check_error(response)
#   return parse_response(response)
# rescue OpenURI::HTTPError => e
#   check_error(prepare_response(e.io.read))
#   raise
end

#search(s) ⇒ Object

def hotel_search(params)

{:rooms => 1, :guests1 => 1, :minstars => -1}
params.
# :action => 'dohotels'
csc = URI.escape(citystatecountry)
dep_date = URI.escape(dep_date)
ret_date = URI.escape(ret_date)
url = "othercity=#{csc}&checkin_date=#{dep_date}&checkout_date=#{ret_date}&"
return start_search(url)
search params.merge()

end



40
41
42
43
# File 'lib/kayak/session.rb', line 40

def search(s)
  params = s.to_search_params.merge({:basicmode => true, :apimode => 1, :_sid_ => @id})
  SearchResults.new(self, get("/s/apisearch", params).elements['//search/searchid'].text)
end