Sha256: 9d21f037582cfd0dacc0337d939a0278ca5727934a6cc5b4d097b79194a33744

Contents?: true

Size: 941 Bytes

Versions: 9

Compression:

Stored size: 941 Bytes

Contents

module Houdini
  Undefined = Class.new(NameError)
  RequestError = Class.new(NameError)
  AuthenticationError = Class.new(NameError)

  class Base
    def self.request(api, params)
      validate_constants
      return ["200", '{success:"true"}'] if HOST == 'test'
      url = URI.parse("http://#{HOST}/api/v0/#{api}/tasks/")
      response, body = Net::HTTP.post_form(url, params)

      raise(AuthenticationError, "invalid api key") if response.code == '403'
      if response.code != "200"
        raise RequestError, "The request to houdini failed with code #{response.code}: #{body}"
      end

      [response, body]
    end

    private

    def self.validate_constants
      raise Undefined, "Houdini::KEY is not defined"  if Houdini::KEY.blank?
      raise Undefined, "Houdini::HOST is not defined" if Houdini::HOST.blank?
      raise Undefined, "Houdini::RAILS_HOST is not defined" if Houdini::RAILS_HOST.blank?
    end
  end


end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
houdini-rails3-0.1.9 lib/houdini_rails/base.rb
houdini-rails3-0.1.8 lib/houdini_rails/base.rb
houdini-rails3-0.1.7 lib/houdini_rails/base.rb
houdini-rails3-0.1.5 lib/houdini_rails/base.rb
houdini-rails3-0.1.4 lib/houdini_rails/base.rb
houdini-rails3-0.1.3 lib/houdini_rails/base.rb
houdini-rails3-0.1.2 lib/houdini_rails/base.rb
houdini-rails3-0.1.0 lib/houdini_rails/base.rb
houdini-rails-0.1.6 lib/houdini-rails/base.rb