Class: Tvteka::API::APIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/tvteka/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_type, data, response, error) ⇒ APIResponse

Returns a new instance of APIResponse.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tvteka/api.rb', line 50

def initialize(request_type, data, response, error)
  @success = (200...300).include?(response.statusCode)
  
  if request_type == :session
    parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
    @data = Tvteka::Session.new(parsed_data)
  elsif request_type == :session
    parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
    @data = Tvteka::Session.new(parsed_data)
  elsif request_type == :live
    puts data
    parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
    @data = Tvteka::Channel.init_from_array(parsed_data)
  elsif request_type == :live_channel
    parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
    @data = Tvteka::Show.init_from_array(parsed_data)
  else
    @data = NSJSONSerialization.JSONObjectWithData(data, options: 0, error: nil)
  end
    
  @error = error
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



48
49
50
# File 'lib/tvteka/api.rb', line 48

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



48
49
50
# File 'lib/tvteka/api.rb', line 48

def error
  @error
end

#successObject (readonly)

Returns the value of attribute success.



48
49
50
# File 'lib/tvteka/api.rb', line 48

def success
  @success
end

Instance Method Details

#successful?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/tvteka/api.rb', line 73

def successful?
  @success
end