class Infobeep::Client

Constants

API_BASE_URL

Public Class Methods

new(username, password) click to toggle source
# File lib/infobeep/client.rb, line 10
def initialize(username, password)
  @username = username
  @password = password
end

Public Instance Methods

authentication_headers() click to toggle source
# File lib/infobeep/client.rb, line 31
def authentication_headers
  auth_string = ::Base64.encode64("#{@username}:#{@password}").strip
  {'Authorization': "Basic #{auth_string}"}
end
client_headers() click to toggle source
# File lib/infobeep/client.rb, line 36
def client_headers
  hsh = {
      'User-Agent': "Infobeep-#{Infobeep::VERSION}",
      'Content-Type': 'application/json',
      'accept': 'application/json'
  }
  hsh.merge!(authentication_headers)
  hsh
end
send_request(sms_request) click to toggle source
# File lib/infobeep/client.rb, line 15
def send_request(sms_request)
  url = API_BASE_URL + sms_request.route
  method = sms_request.http_method
  headers = client_headers.merge(sms_request.headers)
  payload = sms_request.payload

  begin
    response = RestClient::Request.execute(method: method, url: url, payload: payload, headers: headers)
  rescue RestClient::ExceptionWithResponse => err
    raise err
  end

  response_hash = JSON.parse(response.body)
  sms_request.response_class.new(response_hash)
end