Class: AFMotion::HTTPResult

Inherits:
Object
  • Object
show all
Defined in:
lib/afmotion/http_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_or_task, responseObject, error) ⇒ HTTPResult

Returns a new instance of HTTPResult.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/afmotion/http_result.rb', line 5

def initialize(operation_or_task, responseObject, error)
  if defined?(NSURLSessionTask) && operation_or_task.is_a?(NSURLSessionTask) ||
    # cluser class ugh
    operation_or_task.class.to_s.include?("Task")
    self.task = operation_or_task
  else
    self.operation = operation_or_task
  end
  self.object = responseObject
  self.error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/afmotion/http_result.rb', line 3

def error
  @error
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/afmotion/http_result.rb', line 3

def object
  @object
end

#operationObject

Returns the value of attribute operation.



3
4
5
# File 'lib/afmotion/http_result.rb', line 3

def operation
  @operation
end

#taskObject

Returns the value of attribute task.



3
4
5
# File 'lib/afmotion/http_result.rb', line 3

def task
  @task
end

Instance Method Details

#bodyObject



33
34
35
36
37
38
39
40
# File 'lib/afmotion/http_result.rb', line 33

def body
  if task && task.currentRequest
    raise "Cannot call result.body of a task"
  end
  if operation && operation.responseString
    operation.responseString
  end
end

#failure?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/afmotion/http_result.rb', line 21

def failure?
  !!error
end

#status_codeObject



25
26
27
28
29
30
31
# File 'lib/afmotion/http_result.rb', line 25

def status_code
  if self.operation
    self.operation.response.statusCode
  else
    self.task.response.statusCode
  end
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/afmotion/http_result.rb', line 17

def success?
  !failure?
end