Class: Keymaker::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, faraday_response) ⇒ Response

Returns a new instance of Response.



9
10
11
12
# File 'lib/keymaker/response.rb', line 9

def initialize(service, faraday_response)
  self.service = service
  self.faraday_response = faraday_response
end

Instance Attribute Details

#faraday_responseObject

Returns the value of attribute faraday_response.



7
8
9
# File 'lib/keymaker/response.rb', line 7

def faraday_response
  @faraday_response
end

#requestObject

Returns the value of attribute request.



5
6
7
# File 'lib/keymaker/response.rb', line 5

def request
  @request
end

#serviceObject

Returns the value of attribute service.



6
7
8
# File 'lib/keymaker/response.rb', line 6

def service
  @service
end

Instance Method Details

#bodyObject



14
15
16
# File 'lib/keymaker/response.rb', line 14

def body
  faraday_response.body || {}
end

#neo4j_idObject



22
23
24
# File 'lib/keymaker/response.rb', line 22

def neo4j_id
  body["self"] && body["self"][/\d+$/].to_i
end

#on_errorObject



37
38
39
40
41
42
# File 'lib/keymaker/response.rb', line 37

def on_error
  unless success?
    yield self
  end
  self
end

#on_successObject



26
27
28
29
30
31
# File 'lib/keymaker/response.rb', line 26

def on_success
  if success?
    yield self
  end
  self
end

#statusObject



18
19
20
# File 'lib/keymaker/response.rb', line 18

def status
  faraday_response.status
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  (200..299).include?(status)
end