Class: Mangadex::Api::Response

Inherits:
MangadexObject show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/mangadex/api/response.rb

Defined Under Namespace

Classes: Collection, Error

Instance Attribute Summary collapse

Attributes included from Internal::WithAttributes

#attributes, #id, #related_type, #relationships, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MangadexObject

#eq?, #hash, #initialize, #inspect

Constructor Details

This class inherits a constructor from Mangadex::MangadexObject

Instance Attribute Details

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/mangadex/api/response.rb', line 8

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/mangadex/api/response.rb', line 8

def errors
  @errors
end

#limitObject

Returns the value of attribute limit.



9
10
11
# File 'lib/mangadex/api/response.rb', line 9

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



9
10
11
# File 'lib/mangadex/api/response.rb', line 9

def offset
  @offset
end

#raw_dataObject

Returns the value of attribute raw_data.



10
11
12
# File 'lib/mangadex/api/response.rb', line 10

def raw_data
  @raw_data
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/mangadex/api/response.rb', line 8

def response
  @response
end

#resultObject

Returns the value of attribute result.



8
9
10
# File 'lib/mangadex/api/response.rb', line 8

def result
  @result
end

#totalObject

Returns the value of attribute total.



9
10
11
# File 'lib/mangadex/api/response.rb', line 9

def total
  @total
end

Class Method Details

.attributes_to_inspectObject



12
13
14
# File 'lib/mangadex/api/response.rb', line 12

def self.attributes_to_inspect
  i(result errors limit offset total data)
end

.coerce(data) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mangadex/api/response.rb', line 32

def self.coerce(data)
  if data['errors']
    coerce_errors(data)
  elsif data['response'] == 'entity'
    coerce_entity(data)
  elsif data['response'] == 'collection'
    coerce_collection(data)
  else
    data
  end
end

Instance Method Details

#as_jsonObject



51
52
53
# File 'lib/mangadex/api/response.rb', line 51

def as_json(*)
  Hash(raw_data)
end

#errored?(status = nil) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/mangadex/api/response.rb', line 44

def errored?(status=nil)
  errored = Array(errors).any?
  return errored if status.nil?

  errors.select { |error| error.status.to_s == status.to_s }.any?
end