Skip to content

Commit

Permalink
Using Get method for family client
Browse files Browse the repository at this point in the history
As P2N do not gather families correctly since last summer. It seems that it is due to the use of post method in client request (in oposite of the EPO documentation). So this is a quick and dirty hack to make P2N working.
Comments are welcome and needed
  • Loading branch information
Patent2net committed Sep 30, 2019
1 parent f731ce3 commit 1b4eb25
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
33 changes: 30 additions & 3 deletions epo_ops/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ def _post(self, url, data, extra_headers=None, params=None):
return self.request.post(
url, data=data, headers=headers, params=params
)

def _get(self, url, data, extra_headers=None, params=None):
headers = {
'Accept': self.accept_type,
'Content-Type': 'text/plain'
}
headers.update(extra_headers or {})
return self.request.get(
url, data=data, headers=headers, params=params
)
def _make_request(self, url, data, extra_headers=None, params=None):
extra_headers = extra_headers or {}
token = 'Bearer {0}'.format(self.access_token.token)
Expand All @@ -81,7 +89,17 @@ def _make_request(self, url, data, extra_headers=None, params=None):
response = self._check_for_exceeded_quota(response)
response.raise_for_status()
return response
def _make_request2(self, url, data, extra_headers=None, params=None):
extra_headers = extra_headers or {}
token = 'Bearer {0}'.format(self.access_token.token)
extra_headers['Authorization'] = token

response = self._get(url, data, extra_headers, params)
response = self._check_for_expired_token(response)
response = self._check_for_exceeded_quota(response)
response.raise_for_status()
return response

def _make_request_url(
self, service, reference_type, input, endpoint, constituents
):
Expand All @@ -101,7 +119,13 @@ def _service_request(
path, reference_type, input, endpoint, constituents
)
return self._make_request(url, input.as_api_input())

def _service_request2(
self, path, reference_type, input, endpoint, constituents
):
url = self._make_request_url(
path, reference_type, input, endpoint, constituents
)
return self._make_request2(url, input.as_api_input())
def _search_request(self, path, cql, range, constituents=None):
url = self._make_request_url(path, None, None, None, constituents)
return self._make_request(
Expand Down Expand Up @@ -129,7 +153,10 @@ def family(self, reference_type, input, endpoint=None, constituents=None):
return self._service_request(
self.__family_path__, reference_type, input, endpoint, constituents
)

def family2(self, reference_type, input, endpoint=None, constituents=None):
return self._service_request2(
self.__family_path__, reference_type, input, endpoint, constituents
)
def image(self, path, range=1, document_format='application/tiff'):
return self._image_request(
path, range, document_format
Expand Down
31 changes: 30 additions & 1 deletion epo_ops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def __init__(self, number, country_code=None, kind_code=None, date=None):


class Docdb(BaseInput):
def __init__(self, number, country_code, kind_code=None, date=None):
def __init__(self, number, country_code, kind_code, date=None):
if not all([country_code, kind_code]):
raise MissingRequiredValue(
'number, country_code, and kind_code must be present'
)
super(Docdb, self).__init__(number, country_code, kind_code, date)


Expand Down Expand Up @@ -101,3 +105,28 @@ def post(self, url, data=None, **kwargs):

self.reset_env()
return response

def get(self, url, data=None, **kwargs):
self.reset_env()

for mw in self.middlewares:
url, data, kwargs = mw.process_request(
self.env, url, data, **kwargs
)

# Either get response from cache environment or request from upstream
# Remark:
# bool(<Response [200]>) is True
# bool(<Response [404]>) is False
if self.env['response'] is not None:
response = self.env['response']
else:
url = url.replace('epodoc', 'epodoc/'+data)

response = requests.get(url, **kwargs)

for mw in reversed(self.middlewares):
response = mw.process_response(self.env, response)

self.reset_env()
return response

0 comments on commit 1b4eb25

Please sign in to comment.