module Uptimr

Constants

VERSION

Attributes

base_url[RW]

Public Class Methods

config() { |self| ... } click to toggle source
# File lib/uptimr.rb, line 16
def self.config
        yield self
end
handle_error(error) click to toggle source
# File lib/uptimr.rb, line 40
def self.handle_error(error)
        raise Uptimr::UptimrError.new(error)
end
parse(raw_json) click to toggle source
# File lib/uptimr.rb, line 32
def self.parse(raw_json)
        begin
                Util.keys_to_sym MultiJson.load(raw_json)
        rescue MultiJson::DecodeError => e
                handle_error("JSON is buggered")
        end
end
request(path, options={}) click to toggle source
# File lib/uptimr.rb, line 20
def self.request(path, options={})
        handle_error "You have not set your API url" if base_url.nil?
        handle_error "Invalid HTTP method" unless %w(get post).include? options[:method].to_s

        options.merge! url: "#{base_url}#{path}"

        puts "About to request: #{options[:url]}"
        response = generate_request(options)

        parse response.body
end

Private Class Methods

generate_request(options) click to toggle source
# File lib/uptimr.rb, line 46
def self.generate_request(options)
        HTTParty.send options[:method], options[:url], options
end