Class: BookingApi::HttpService

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

Instance Method Summary collapse

Constructor Details

#initializeHttpService

Returns a new instance of HttpService.



3
4
5
6
# File 'lib/booking_api/http_service.rb', line 3

def initialize
  @auth_username = BookingApi.username
  @auth_password = BookingApi.password
end

Instance Method Details

#connectionObject



8
9
10
11
12
13
14
15
16
# File 'lib/booking_api/http_service.rb', line 8

def connection
  @connection ||= begin
    Faraday.new(:url => 'https://distribution-xml.booking.com') do |faraday|
      faraday.basic_auth @auth_username, @auth_password
      faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
      faraday.response :json, :content_type => /\bjson$/
    end
  end
end

#request_post(url, data) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/booking_api/http_service.rb', line 18

def request_post(url, data)
  connection.post do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.body = data.to_json
  end
end