module Rufbit

Constants

VERSION

Public Class Methods

API_KEY() click to toggle source
# File lib/rufbit.rb, line 15
def self.API_KEY
    return @@API_KEY
end
API_KEY=(key) click to toggle source
# File lib/rufbit.rb, line 11
def self.API_KEY= (key)
    @@API_KEY = key
end
host() click to toggle source
# File lib/rufbit.rb, line 19
def self.host
  return @@host
end
port() click to toggle source
# File lib/rufbit.rb, line 23
def self.port
  return @@port
end
send(title, data, state) click to toggle source
# File lib/rufbit/notification.rb, line 6
def self.send(title, data, state)
    path = "/v1/notify"

    body ={
        "API_KEY" => Rufbit.API_KEY,
        "title" => title,
        "data" => data,
        "state" => state
    }.to_json

    request = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'})
    request.body = body
    response = Net::HTTP.new(Rufbit.host, Rufbit.port)
    response.ssl_version = :TLSv1  
    response.use_ssl = true
    response.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
    response.start {|http| @res = http.request(request) }
    
    #puts "Response #{@res.code} #{@res.message}: #{@res.body}"

    case @res.code
    when "400"
        raise InvalidRequestError.new(@res), "The request could not be processed properly, often due to missing or invalid parameters"
    when "401"
        raise AuthenticationError.new(@res), "The provided API-Key is invalid or missing"
    when "500"
        raise RufbitError.new(@res), "Something went wrong on our end. Please contact us if you believe this wasn't supposed to happen."
    end

    return JSON::parse @res.body
end