class Whereby::Api

Constants

API_VERSION
BASE_URL

Public Instance Methods

create_meeting(**options) click to toggle source

POST /v1/meetings/

# File lib/whereby/api.rb, line 17
def create_meeting(**options)
  Meeting.new(whereby_request(:post, 'meetings', options))
end
delete_meeting(id) click to toggle source

DELETE /v1/meetings/:id

# File lib/whereby/api.rb, line 22
def delete_meeting(id)
  whereby_request(:delete, "meetings/#{id}")
end
meeting(id) click to toggle source

GET /v1/meetings/:id

# File lib/whereby/api.rb, line 12
def meeting(id)
  Meeting.new(whereby_request(:get, "meetings/#{id}"))
end

Private Instance Methods

body(options) click to toggle source
# File lib/whereby/api.rb, line 41
def body(options)
  Hash[options.map { |k, v| [k.to_s.whereby_lower_camelize, v] }].to_json
end
error(code) click to toggle source
# File lib/whereby/api.rb, line 52
def error(code)
  return 'Access token is missing or invalid' if code == 401
  return 'The requested resource does not exist' if code == 404

  "The API resulted in an unknown status code: #{code}"
end
headers() click to toggle source
# File lib/whereby/api.rb, line 45
def headers
  {
      'Content-type' => 'application/json',
      'Authorization' => "Bearer #{Whereby.api_key}"
  }
end
whereby_request(method, url, options = {}) click to toggle source
# File lib/whereby/api.rb, line 28
def whereby_request(method, url, options = {})
  url = "#{BASE_URL}/#{url}"
  result = HTTParty.send(method, url, { headers: headers, body: body(options) })

  if [200, 201].include? result.code
    JSON.parse(result.body)
  elsif result.code == 204
    true
  else
    raise WherebyError.new error(result.code)
  end
end