Sha256: 68bbb55016a3c02498e2daf921d850a098cb09682c06f1fd98ed5b18fb9bd321

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

module Sappy
  class Request
    def self.perform(account, action, parameters)
      new(account, action, parameters).perform
    end

    def initialize(account, action, parameters)
      @account, @action, @parameters = account, action, parameters
    end

    def perform
      response = http.get("#{uri.path}?#{query_string}")
      Responses.for(@action).parse(response.body)
    end

    private
      def uri
        @uri ||= URI("https://siteuptime.com/api/rest/?#{query_string}")
      end

      def query_string
        if @account.authenticated?
          @parameters["AuthKey"] = @account.authkey
        end
        @parameters["method"] = "siteuptime.#{@action}"

        Rack::Utils.build_query(@parameters)
      end

      def http
        http             = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl     = true
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        http
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sappy-0.1.7 lib/sappy/request.rb
sappy-0.1.6 lib/sappy/request.rb