Class: Gecko::Http::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gecko/http.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Result

Returns a new instance of Result.



40
41
42
# File 'lib/gecko/http.rb', line 40

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



37
38
39
# File 'lib/gecko/http.rb', line 37

def response
  @response
end

#response_envObject

Returns the value of attribute response_env.



38
39
40
# File 'lib/gecko/http.rb', line 38

def response_env
  @response_env
end

Instance Method Details

#errorObject



67
68
69
# File 'lib/gecko/http.rb', line 67

def error
  Error.new(self.fetch(:error), self.response.status)
end

#error?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/gecko/http.rb', line 63

def error?
  self.fetch(:success) != true
end

#fetch(*keys) ⇒ Object



71
72
73
74
75
76
# File 'lib/gecko/http.rb', line 71

def fetch(*keys)
  keys.inject(self.response_body) do |body_hash, key|
    break unless body_hash
    body_hash.fetch(key, nil)
  end
end

#http_200?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/gecko/http.rb', line 59

def http_200?
  self.response.status == 200
end

#on_complete(&block) ⇒ Object



44
45
46
47
48
49
# File 'lib/gecko/http.rb', line 44

def on_complete(&block)
  self.response.on_complete do |env|
    self.response_env = env
    block.call(self.success?, self)
  end
end

#response_bodyObject



51
52
53
# File 'lib/gecko/http.rb', line 51

def response_body
  self.response.body
end

#success?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gecko/http.rb', line 55

def success?
  self.http_200? && !self.error?
end