Class: Ean3::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Hotels
Defined in:
lib/ean3/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hotels

#getAlternateProperties, #getAvaliabillity, #getCancel, #getGeoLocation, #getInformation, #getItinerary, #getList, #getPaymentInfo, #getPing, #getReservation, #getRules

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ean3/client.rb', line 9

def initialize options={}
  @cid = options[:cid].nil? ? default_cid : options[:cid]
  @apikey = options[:apikey]
  @secret = options[:secret]
  @minorRev = options[:minorRev]
  @locale = options[:locale]
  @currencyCode = options[:currencyCode]
  @customerSessionId = options[:customerSessionId]
  @customerIpAddress = options[:customerIpAddress]
  @customerUserAgent = options[:customerUserAgent]
  @debug = options[:debug]
  #@sig =
  @ssl = options[:ssl]
end

Instance Attribute Details

#apikeyObject (readonly)

Returns the value of attribute apikey.



7
8
9
# File 'lib/ean3/client.rb', line 7

def apikey
  @apikey
end

#cidObject (readonly)

Returns the value of attribute cid.



7
8
9
# File 'lib/ean3/client.rb', line 7

def cid
  @cid
end

#secretObject (readonly)

Returns the value of attribute secret.



7
8
9
# File 'lib/ean3/client.rb', line 7

def secret
  @secret
end

Instance Method Details

#api_urlObject



28
29
30
31
32
33
34
35
# File 'lib/ean3/client.rb', line 28

def api_url
  version = api_version()
  if @ssl
    "https://book.api.ean.com/ean-services/rs/hotel/#{version}/"
  else
    "http://api.ean.com/ean-services/rs/hotel/#{version}/"
  end
end

#api_versionObject



24
25
26
# File 'lib/ean3/client.rb', line 24

def api_version
  'v3'
end

#connectionObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ean3/client.rb', line 50

def connection
  params = {}
  params[:cid] = @cid
  params[:apikey] = @apikey
  params[:secret] = @secret
  params[:minorRev] = @minorRev
  params[:locale] = @locale
  params[:currencyCode] = @currencyCode
  params[:customerSessionId] = @customerSessionId
  params[:customerIpAddress] = @customerIpAddress
  params[:customerUserAgent] = @customerUserAgent
  @connection ||= Faraday::Connection.new(:url => api_url, :ssl => @ssl, :sig => sig, :params => params, :headers => default_headers) do |builder|
    builder.use Faraday::Request::Multipart
    builder.use Faraday::Request::UrlEncoded

    if @debug
      builder.use Faraday::Response::Logger
    end

    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson

    builder.adapter Faraday.default_adapter

    builder.request :multipart
    builder.request :url_encoded
    builder.request :json
  end
end

#default_cidObject



37
38
39
# File 'lib/ean3/client.rb', line 37

def default_cid
  '55505'
end

#return_error_or_body(response, response_body) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/ean3/client.rb', line 80

def return_error_or_body(response, response_body)
  if response.success?
      response_body
  else
      raise Ean::APIError.new(response.headers, response.body)
  end
end

#sigObject



45
46
47
48
# File 'lib/ean3/client.rb', line 45

def sig
  # apikey + secret + timestamp -> md5 key
  ''
end

#sslObject



41
42
43
# File 'lib/ean3/client.rb', line 41

def ssl
  @ssl
end