Sha256: 99fbad4bc8a67366753862fc071ee6e1a7f23e1478c722691bd3e34022a541bc

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

class URL
  
  # Handlers for making requests for the URL. To create your own you need to follow the following conventions:
  # 1. You must define the get, post, and delete instance methods
  # 2. These methods should return a {Response} object
  # 
  # To create a {Response} object:
  #   hsh = {
  #     :code => resp.code,
  #     :time => resp.time,
  #     :body => resp.body,
  #     :response => resp,
  #     :url => url.to_s
  #   }
  #   Response.new(hsh)
  class RequestHandler
    attr_reader :url
    def initialize(url)
      @url = url
    end
    
    def get(args={})
      raise Exception, "You need to implement #{self.class}#get"
    end
    
    def post(args={})
      raise Exception, "You need to implement #{self.class}#post"
    end
    
    def delete(args={})
      raise Exception, "You need to implement #{self.class}#delete"
    end

    def put(args={})
      raise Exception, "You need to implement #{self.class}#put"
    end
  end
  
  class JSONHandler
    attr_reader :str
    def initialize(str)
      @str = str
    end
    
    def parse
      raise Exception, "You need to implement #{self.class}#parse"
    end
    
  end
  
end

Dir[File.join(File.dirname(__FILE__),'handlers','*.rb')].each {|f| require f}

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/url-0.3.2/lib/url/handlers.rb
url-0.3.2 lib/url/handlers.rb
url-0.3.1 lib/url/handlers.rb
url-0.3.0 lib/url/handlers.rb