class BookingLocations::Api
Public Instance Methods
all()
click to toggle source
# File lib/booking_locations/api.rb, line 12 def all response = open("#{api_uri}/api/v1/booking_locations.json", headers_and_options) JSON.parse(response.read) end
get(id) { |parse| ... }
click to toggle source
# File lib/booking_locations/api.rb, line 5 def get(id) response = open("#{api_uri}/api/v1/booking_locations/#{id}.json", headers_and_options) yield JSON.parse(response.read) rescue OpenURI::HTTPError nil end
Private Instance Methods
api_uri()
click to toggle source
# File lib/booking_locations/api.rb, line 32 def api_uri ENV.fetch('BOOKING_LOCATIONS_API_URI', 'http://localhost:3001') end
bearer_token()
click to toggle source
# File lib/booking_locations/api.rb, line 28 def bearer_token ENV['BOOKING_LOCATIONS_API_BEARER_TOKEN'] end
headers_and_options()
click to toggle source
# File lib/booking_locations/api.rb, line 19 def headers_and_options {}.tap do |hash| hash[:read_timeout] = read_timeout hash[:open_timeout] = open_timeout hash['Authorization'] = "Bearer #{bearer_token}" if bearer_token hash['Accept'] = 'application/json' end end
open_timeout()
click to toggle source
# File lib/booking_locations/api.rb, line 40 def open_timeout ENV.fetch('BOOKING_LOCATIONS_API_OPEN_TIMEOUT', 5).to_i end
read_timeout()
click to toggle source
# File lib/booking_locations/api.rb, line 36 def read_timeout ENV.fetch('BOOKING_LOCATIONS_API_READ_TIMEOUT', 5).to_i end