JAL-3026 implements simple REST client
[jalview.git] / src / jalview / javascript / web / ClientResponse.java
1 package jalview.javascript.web;
2
3 import java.net.URI;
4
5 public class ClientResponse
6 {
7   
8   private String response;
9   private String encoding;
10
11   public ClientResponse(String response, String encoding) 
12   {
13     this.response = response;
14     this.encoding = encoding;
15   }
16
17   public String getEntity(Class<?> c)
18   {  
19     
20     // c will be String.class
21     
22     return response;
23   }
24
25   // https://www.ebi.ac.uk/pdbe/search/pdb/select?wt=json&fl=pdb_id,title,experimental_method,resolution&rows=500&start=0&q=(text:q93xj9_soltu)+AND+molecule_sequence:%5B%27%27+TO+*%5D+AND+status:REL&sort=overall_quality+desc
26   
27 //{
28 //"responseHeader":{
29 //  "status":0,
30 //  "QTime":0,
31 //  "params":{
32 //    "q":"(text:q93xj9_soltu) AND molecule_sequence:['' TO *] AND status:REL",
33 //    "fl":"pdb_id,title,experimental_method,resolution",
34 //    "start":"0",
35 //    "sort":"overall_quality desc",
36 //    "rows":"500",
37 //    "wt":"json"}},
38 //"response":{"numFound":1,"start":0,"docs":[
39 //    {
40 //      "experimental_method":["X-ray diffraction"],
41 //      "pdb_id":"4zhp",
42 //      "resolution":2.46,
43 //      "title":"The crystal structure of Potato ferredoxin I with 2Fe-2S cluster"}]
44 //}}
45 //
46
47   public int getStatus()
48   {
49     // note, we could get the actual response. I am just assuming it is 200 or 400
50     return (response != null && (response.startsWith("{") == encoding.equals("application/json"))
51             ? 200 : 400);
52   }
53
54 }