Class: BookingApi::HttpService
- Inherits:
-
Object
- Object
- BookingApi::HttpService
- Defined in:
- lib/booking_api/http_service.rb
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize ⇒ HttpService
constructor
A new instance of HttpService.
- #request_post(url, data) ⇒ Object
Constructor Details
#initialize ⇒ HttpService
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
#connection ⇒ Object
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 |