Sha256: e2e3f99651d06b66d74bcb86a26db8c0631df2ecf01ff368796ef02281afc730

Contents?: true

Size: 925 Bytes

Versions: 4

Compression:

Stored size: 925 Bytes

Contents

module GetResponse
  class Api

    def initialize
      @path_parts = []
    end

    def method_missing(method, *args)
      @path_parts << method.to_s.gsub("_", "-").downcase
      @path_parts << args if args.length > 0
      @path_parts.flatten!
      self
    end

    def create(params = {})
      resp = GetResponse::Request.post(path, params)
      Response.new(resp)
    ensure
      reset
    end

    def update(params)
      resp = GetResponse::Request.post(path, params)
      Response.new(resp)
    ensure
      reset
    end

    def retrieve(params = {})
      resp = GetResponse::Request.get(path, params)
      Response.new(resp)
    ensure
      reset
    end

    def delete
      resp = GetResponse::Request.delete(path, params)
      Response.new(resp)
    ensure
      reset
    end

    private

    def path
      @path_parts.join('/')
    end

    def reset
      @path_parts = []
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
get_response-0.1.2 lib/get_response/api.rb
get_response-0.1.1 lib/get_response/api.rb
get_response-0.1.0 lib/get_response/api.rb
getresponse_ruby-0.1.0 lib/get_response/api.rb