Sha256: b470c599f7b1db45fd002f3eb86bae4a0dd417da08907183bdd8f50dcb25359c

Contents?: true

Size: 810 Bytes

Versions: 3

Compression:

Stored size: 810 Bytes

Contents

module LucidHttp
  class Response
    attr_reader :base_url
    attr_reader :path

    def initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {})
      @base_url  = base_url
      @path      = path
      @formatter = LucidHttp::Formatter.for(formatter)
      @follower  = LucidHttp::Follower.for(follower).client
      @verb      = verb
      @form      = form

      @response = @follower.send(@verb, url, params: form)
    end

    def body
      @formatter.call(@response.body.to_s)
    end

    def status
      @response.status.to_s
    end

    def content_type
      @response.content_type.mime_type
    end

    def url
      "#{base_url}#{path}"
    end

    def error
      body.split("\n").first || "No error found"
    end

    def verb
      @verb.to_s.upcase
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lucid_http-1.2.1 lib/lucid_http/response.rb
lucid_http-1.2.0 lib/lucid_http/response.rb
lucid_http-1.1.1 lib/lucid_http/response.rb