Skip to content

Commit

Permalink
Merge pull request #568 from robertatakenaka/corrige_api_publication_…
Browse files Browse the repository at this point in the history
…para_obter_novo_token

Corrige api publication para obter novo token quando o atual está expirado
  • Loading branch information
robertatakenaka authored Nov 12, 2024
2 parents ec86267 + 674be81 commit c945247
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions publication/api/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def publish_article(article_proc, api_data, journal_pid=None):
order=order,
article_url=data.get("xml"),
)
ret = api.post_data(data, kwargs)
ret["payload"] = data
return ret
return api.post_data(data, kwargs)


class ArticlePayload:
Expand Down
4 changes: 1 addition & 3 deletions publication/api/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def publish_issue(issue_proc, api_data):
builder = IssuePayload(data)
build_issue(builder, journal_id, issue, issue_id)
api = PublicationAPI(**api_data)
response = api.post_data(data, {"journal_id": journal_id})
response["payload"] = data
return response
return api.post_data(data, {"journal_id": journal_id})


class IssuePayload:
Expand Down
4 changes: 1 addition & 3 deletions publication/api/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def publish_journal(journal_proc, api_data):
)

api = PublicationAPI(**api_data)
response = api.post_data(payload)
response["payload"] = payload
return response
return api.post_data(payload)


class JournalPayload:
Expand Down
16 changes: 10 additions & 6 deletions publication/api/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,32 @@ def post_data(self, payload, kwargs=None):
# logging.info(f"payload={payload}")
response = None
try:
try:
if not self.token:
self.get_token()
response = self._post_data(payload, self.token, kwargs)
except Exception as e:
if not self.token:
self.get_token()
response = self._post_data(payload, self.token, kwargs)
response = self.format_response(response, payload)
if not response.get("result"):
self.get_token()
response = self._post_data(payload, self.token, kwargs)
return self.format_response(response, payload)
return response
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
response = {
"post_data_url": self.post_data_url,
"payload": payload,
"payload": json.dumps(payload),
"traceback": traceback.format_tb(exc_traceback),
"error": str(e),
"error_type": str(type(e)),
}
return response

def format_response(self, response, payload):
if response.get("id") and response["id"] != "None":
response["result"] = "OK"
elif response.get("failed") is False:
response["result"] = "OK"
response["payload"] = json.dumps(payload)
return response or {}

def get_token(self):
Expand Down

0 comments on commit c945247

Please sign in to comment.