Class: LucidHttp::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_http/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {}) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
# File 'lib/lucid_http/response.rb', line 6

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

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



3
4
5
# File 'lib/lucid_http/response.rb', line 3

def base_url
  @base_url
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/lucid_http/response.rb', line 4

def path
  @path
end

Instance Method Details

#bodyObject



17
18
19
# File 'lib/lucid_http/response.rb', line 17

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

#content_typeObject



25
26
27
# File 'lib/lucid_http/response.rb', line 25

def content_type
  @response.content_type.mime_type
end

#errorObject



33
34
35
# File 'lib/lucid_http/response.rb', line 33

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

#statusObject



21
22
23
# File 'lib/lucid_http/response.rb', line 21

def status
  @response.status.to_s
end

#urlObject



29
30
31
# File 'lib/lucid_http/response.rb', line 29

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

#verbObject



37
38
39
# File 'lib/lucid_http/response.rb', line 37

def verb
  @verb.to_s.upcase
end