Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularization 4 - Displaying shares informations #216

Merged
merged 6 commits into from
Aug 23, 2019
Merged

Conversation

SimonSAMPERE
Copy link
Collaborator

@SimonSAMPERE SimonSAMPERE commented Aug 22, 2019

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 module modules/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:

  • ApiRequester inherits from QgsNetworkAccessManager
  • A more sophisticated system of signals and slots to link ApiRequester with the main class Isogeo, SharesParser and MetadataDisplayer (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:

    • api_auth_post_get_token() : to create and send authentication request
    • api_auth_handle_token(answer: object) : to handle Isogeo's API reply to authentication request
    • api_get_requests() : to create and send search request, shares request or details request
    • api_requests_handle_reply(answer: object) : to handle Isogeo's API reply search request, shares request or details request
  • by emitting 2 signals:

    • token_received[str]: Emitted by api_auth_handle_token(answer: object) once Isogeo's API's reply to authentication request is received and parsed.
      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.
    • reply_ready[]: Emitted by api_requests_handle_reply(answer: object) once Isogeo's API's reply to other type of request is received, parsed and validated.
      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 :
      • Isogeo.update_fiedls() for a search request
      • Isogeo.write_shares_info() for a shares request
      • Isogeo.show_md() for a details request

Since #216

ApiRequester inherits from QgsNetworkAccessManager and worked that way:

  • with 3 methods to manage requesting to Isogeo's API:

    • create_request(request_type:str) : to create request using QNetworkRequest with appropriate headers depending on 'request_type' parameter
    • send_request(request_type:str) : to send request returned by create_request(request_type:str) using post() or get() methods inherited from QgsNetworkAccessManager depending on 'request_type' parameter
    • handle_reply(reply:QNetworkReply) : to handle reply from Isogeo's API to any type of request and emit appropriate signal and passing appropriate data depending on the type of request send by send_request(request_type:str)
  • by emitting 4 signals:

    • token_sig[str]: same as after Modularization 3 - interaction with the API #213
    • search_sig[dict]: Emitted by handle_reply(reply:QNetworkReply) once Isogeo's API's reply to search request is received, parsed and validated.
      The parsed content of the Isogeo's API reply is passed as a dictionnary to the connected slot: Isogeo.update_fiedls(result: dict).
    • details_sig[dict]: Emitted by handle_reply(reply:QNetworkReply) once Isogeo's API's reply to details request is received, parsed and validated.
      The parsed content of the Isogeo's API reply is passed as a dictionnary to the connected slot: MetadataDisplayer.show_complete_md(md: dict).
    • shares_sig[list]: Emitted by handle_reply(reply:QNetworkReply) once Isogeo's API's reply to shares type of request is received, parsed and validated.
      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.

#215
#177
Complete reorganization of the code to allow to send shares request to Isogeo's API asynchronously
#177 #215
Adapting Isogeo main class to new signals and slots system of ApiRequester
@SimonSAMPERE SimonSAMPERE added enhancement Amélioration du fonctionnement existant code art Qualité du code source PyQGIS labels Aug 22, 2019
@SimonSAMPERE SimonSAMPERE requested a review from Guts August 22, 2019 16:29
@SimonSAMPERE SimonSAMPERE self-assigned this Aug 22, 2019
@Guts Guts added this to the Version 2 milestone Aug 22, 2019
@Guts Guts merged commit 7929a76 into qgis3 Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code art Qualité du code source enhancement Amélioration du fonctionnement existant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants