Class: Plagiarism::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



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

def initialize(response)
  @response = response
  @doc = Nokogiri::XML(response.body) if @response.ok?
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



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

def doc
  @doc
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#bodyObject

Return the body of the response



28
29
30
# File 'lib/plagiarism/response.rb', line 28

def body
  @response ? @response.response.body : nil
end

#error?Boolean

Return true if the API call did not succeed

Returns:

  • (Boolean)


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

def error?
  not success?
end

#status_codeObject

Return the HTTP status code from the response



34
35
36
# File 'lib/plagiarism/response.rb', line 34

def status_code
  @response ? @response.response.code : nil
end

#success?Boolean

Return true if the API call succeeded

Returns:

  • (Boolean)


16
17
18
# File 'lib/plagiarism/response.rb', line 16

def success?
  @response.ok? && @doc.css("error").text == ""
end