Modularization 4 - Displaying shares informations #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1 new module
Context
Improve plugin operation and make corrections (#180 ).
Achievments
modules/api/shares.py
Issue : sous-dossier "api" #177, Propriétés de l'application #215
Class name : SharesParser
Purpose : This class only handles the parsing of informations about the shares that feed the plugin. Its send_shares() method takes as argument the content of the API's response to a shares request. This content is processed to build a string using XML tags to show the user basic informations about his application. This method therefore performs many of the tasks previously performed by the write_shares_info() method of the main class Isogeo. The only role of write_shares_info is now to fill a widget of the UI with the string built by SharesParser.
Improvement : The formatting of information about sharing has been removed from the main class Isogeo. The shares request is sent only once, during authentication with the Isogeo API. The asynchronous API of QgsNetworkAccessManager is used to send this shares request at the same time as the first search request. This makes the plugin initialization faster.
Code organization
This pull request concerns the module
modules/api/shares.py
but the modifications made to the modulemodules/api/requester.py
constitute the main contribution of this iteration.The operation of the class ApiRequester of the module
modules/api/requester.py
has been modified to allow two requests to be sent to the Isogeo API simultaneously using the asynchronous API of QgsNetworkAccessManager.2 main changes between #213 and #216:
module/metadata_dispaly.py
).After #213
ApiRequester used QgsNetworkAccessManager.instance() as an attribute so it was using the same instance of QgsNetworkAccessManager as the one used by QGIS and worked that way:
with 4 methods to manage requesting to Isogeo's API:
by emitting 2 signals:
A string is passed to the connected slot (Isogeo's token_result() method). Its value depend on answer's content : 'tokenOk', 'credissue', 'noInternet' or 'authIssue'.
The connected slot acts differently depending on the value of the string received.
The parsed content of the Isogeo's API reply is stored into an ApiRequester's attribute.
The connected slot depend on the context in which the api_get_requests() method was called :
Since #216
ApiRequester inherits from QgsNetworkAccessManager and worked that way:
with 3 methods to manage requesting to Isogeo's API:
by emitting 4 signals:
The parsed content of the Isogeo's API reply is passed as a dictionnary to the connected slot: Isogeo.update_fiedls(result: dict).
The parsed content of the Isogeo's API reply is passed as a dictionnary to the connected slot: MetadataDisplayer.show_complete_md(md: dict).
The parsed content of the Isogeo's API reply is passed as a list to the connected slot: SharesParser.send_share_info(shares: list).
Modules' instantiation
The SharesParser class is instantiated as an attribute of the main class Isogeo during its initialization.
Links between the modules
The method send_shares() of SharesParser is used as a slot connected to the shares_sig signal transmitted by ApiRequester.
At the end of the execution of its method send_shares(), SharesParser emits the signal shares_ready to which is connected the method write_shares_info() of the main class Isogeo.