Class: MediawikiApi::Response
- Inherits:
-
Object
- Object
- MediawikiApi::Response
- Extended by:
- Forwardable
- Defined in:
- lib/mediawiki_api/response.rb
Overview
Provides access to a parsed MediaWiki API responses.
Some types of responses, depending on the action, contain a level or two of addition structure (an envelope) above the actual payload. The #data method provides a way of easily getting at it.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Accessor for root response object values.
-
#data ⇒ Object
The main payload from the parsed response, removed from its envelope.
-
#errors ⇒ Array
Set of error messages from the response.
-
#initialize(response, envelope = []) ⇒ Response
constructor
Constructs a new response.
-
#warnings ⇒ Array
Set of warning messages from the response.
-
#warnings? ⇒ true, false
Whether the response contains warnings.
Constructor Details
#initialize(response, envelope = []) ⇒ Response
Constructs a new response.
26 27 28 29 |
# File 'lib/mediawiki_api/response.rb', line 26 def initialize(response, envelope = []) @response = response @envelope = envelope end |
Instance Method Details
#[](key) ⇒ Object
Accessor for root response object values.
37 38 39 |
# File 'lib/mediawiki_api/response.rb', line 37 def [](key) response_object[key] end |
#data ⇒ Object
The main payload from the parsed response, removed from its envelope.
45 46 47 48 49 50 51 52 |
# File 'lib/mediawiki_api/response.rb', line 45 def data case response_object when Hash open_envelope(response_object) else response_object end end |
#errors ⇒ Array
Set of error messages from the response.
58 59 60 |
# File 'lib/mediawiki_api/response.rb', line 58 def errors flatten_resp('errors') end |
#warnings ⇒ Array
Set of warning messages from the response.
66 67 68 |
# File 'lib/mediawiki_api/response.rb', line 66 def warnings flatten_resp('warnings') end |
#warnings? ⇒ true, false
Whether the response contains warnings.
74 75 76 |
# File 'lib/mediawiki_api/response.rb', line 74 def warnings? !warnings.empty? end |