Class: MyanimelistClient::UserResponse
- Inherits:
-
Object
- Object
- MyanimelistClient::UserResponse
- Defined in:
- lib/myanimelist_client/user_response.rb
Overview
This class represents a User. It is returned by #verify_credentials.
UserResponse
is responsible for parsing and wraping the XML (or any error message) from the API.
Instance Attribute Summary collapse
-
#id ⇒ String?
Return the MyAnimeList ID of the current account.
-
#raw ⇒ String?
Returns the raw response from the API.
-
#username ⇒ String?
Returns the MyAnimeList username of the current account.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns
true
if an error occured. -
#initialize(raw_xml) ⇒ UserResponse
constructor
A new instance of UserResponse.
-
#ok? ⇒ Boolean
Returns
true
if no error occured.
Constructor Details
#initialize(raw_xml) ⇒ UserResponse
Returns a new instance of UserResponse.
37 38 39 40 41 42 43 |
# File 'lib/myanimelist_client/user_response.rb', line 37 def initialize raw_xml @raw = raw_xml parsed_xml = Nokogiri::XML raw_xml @id = parsed_xml.at_css('id')&.content @username = parsed_xml.at_css('username')&.content end |
Instance Attribute Details
#id ⇒ String?
Return the MyAnimeList ID of the current account.
33 34 35 |
# File 'lib/myanimelist_client/user_response.rb', line 33 def id @id end |
#raw ⇒ String?
Returns the raw response from the API. Or the raw error message.
33 34 35 |
# File 'lib/myanimelist_client/user_response.rb', line 33 def raw @raw end |
#username ⇒ String?
Returns the MyAnimeList username of the current account.
33 34 35 |
# File 'lib/myanimelist_client/user_response.rb', line 33 def username @username end |
Instance Method Details
#error? ⇒ Boolean
Returns true
if an error occured.
46 47 48 |
# File 'lib/myanimelist_client/user_response.rb', line 46 def error? @raw.nil? || @id.nil? || @username.nil? end |
#ok? ⇒ Boolean
Returns true
if no error occured.
51 52 53 |
# File 'lib/myanimelist_client/user_response.rb', line 51 def ok? not error? end |