module Pingity
Constants
- API_VERSION
- API_VERSION_FOR_URI
- VERSION
Constants ============================================================¶ ↑
Public Class Methods
api_method?(method)
click to toggle source
# File lib/pingity.rb, line 45 def self.api_method?(method) ApiMethods.instance_methods.include?(method) end
api_version()
click to toggle source
# File lib/pingity.rb, line 41 def self.api_version API_VERSION end
config(options = nil) { |config| ... }
click to toggle source
Module Methods =======================================================¶ ↑
# File lib/pingity.rb, line 20 def self.config(options = nil) @config = nil if (options) @config ||= Pingity::Config.new(options) yield(@config) if (block_given?) @config end
Also aliased as: configure
configured?()
click to toggle source
# File lib/pingity.rb, line 33 def self.configured? self.config.valid? end
version()
click to toggle source
# File lib/pingity.rb, line 37 def self.version VERSION end
Protected Class Methods
api_call(method, options)
click to toggle source
# File lib/pingity.rb, line 52 def self.api_call(method, options) payload = JSON.dump(options.merge(:api_key => Pingity.config.api_key)) uri = URI("http://#{Pingity.config.api}/api/#{API_VERSION_FOR_URI}/#{method}.json") response = nil if (Pingity.config.verbose) puts "Request:\n\t#{payload}" end case (Pingity.config.transport) when :curb else Net::HTTP.start(uri.host, uri.port) do |http| http_response = http.post( uri.path, payload, 'Content-Type' => 'application/json' ) begin response = JSON.load(http_response.body) end end end puts response.inspect if (Pingity.config.verbose) response rescue SocketError => e case (e.to_s) when /nodename nor servname provided/ raise Pingity::Exceptions::NetworkError, "Hostname #{Pingity.config.api.inspect} could not be resolved, adjust 'api' configuration parameter or check DNS." else raise Pingity::Exceptions::NetworkError, "#{e}" end end