source: ndgCommon/trunk/ndg/common/src/clients/http/httpsearchclient.py @ 4990

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/src/clients/http/httpsearchclient.py@5883
Revision 4990, 1.8 KB checked in by cbyrom, 11 years ago (diff)

Split out the remaining code in DocumentRetrieve? into a new clients
package - providing simple http clients:

generichttpclient - which allows simple GET requests on urls
httpsearchclient - which implements the search interface (partially) - allowing the getNDGDoc method using RESTful interfaces
vocabserverclient - which allows lookup of vocab search terms.

Remove DocumentRetrieve? and associated code + add new test suite for
new package.

Line 
1'''
2A simple http client to retrieve remote ndg docs via http
3
4@author: Calum Byrom, Tessella Feb 09
5'''
6import logging
7from ndg.common.src.lib.utilities import openURLWithProxy
8from ndg.common.src.clients.interfacesearchclient import InterfaceSearchClient
9from generichttpclient import GenericHTTPClient
10
11class HTTPSearchClient(GenericHTTPClient, InterfaceSearchClient):
12    '''
13    Provides a get method to obtain an xml document from a remote NDG repository
14    '''
15    def __init__(self, remoteHost, proxyServer = None):
16        '''
17        Constructor for search client
18        @param remoteHost: host to contact
19        @keyword proxyServer: dict with proxy server details in 
20        '''
21        super(HTTPSearchClient, self).__init__(proxyServer = proxyServer)
22        self.remoteHost=remoteHost
23
24       
25    def getNDGDoc(self, providerID, docType, localID, **kw):
26        '''
27        Retrieve the document represented by an ndgURI
28        @param providerID: ID of the provider of the metadata
29        @param docType: document type - see ndgObject for valid types
30        @param localID: local ID of the ndg document to retrieve
31        @return document matching the ndgURI
32        '''
33        #TODO what about security? Probably means we need to get the headers of our responses sorted ...
34        url='%s/retrieve/%s__%s__%s'%(self.remoteHost, providerID, docType,localID)
35        logging.debug("Retrieving NDG doc from url, '%s'" %url)
36       
37        return self.readURL(url)
38
39
40    def search(self, term, start=1, howmany=20, target='All',
41               scope=None, bbox=None, dateRange=None, geoSearchType='overlaps'):
42        raise NotImplementedError("Full search is not available to simple http client.")
43
44    def getDocs(self, documents, format='original'):
45        raise NotImplementedError("Get Docs is not available to simple http client.")
46
47
Note: See TracBrowser for help on using the repository browser.