Bridges-Java-2.3.3  2.3.3
Bridges(JavaAPI)
Public Member Functions | Protected Member Functions | List of all members
bridges.connect.Connector Class Reference

Public Member Functions

void setServer (String server) throws IllegalArgumentException
 
String getServerURL ()
 
void setServerURL (String server_url)
 
String latlongFormatter (String text)
 
String trimmLast (String text)
 
JSONObject asJSONObject (String text) throws IOException
 
JSONArray asJSONArray (String text) throws IOException
 
Object safeJSONTraverse (String sequence, Object original, Class<?> target) throws IOException
 
String executeHTTPRequest (Request request) throws ClientProtocolException, IOException, RateLimitException
 
String get (String url) throws RateLimitException, IOException
 
String getUSGS (String url) throws RateLimitException, IOException
 
String post (String url, Map< String, String > arguments) throws IOException, RateLimitException
 
String post (String url, String data) throws IOException, RateLimitException
 
String prepare (String url)
 
String prepareUSGS (String url)
 

Protected Member Functions

 Connector ()
 

Constructor & Destructor Documentation

bridges.connect.Connector.Connector ( )
protected

Member Function Documentation

JSONArray bridges.connect.Connector.asJSONArray ( String  text) throws IOException

Decode a String containing JSON into a JSON Array, or throw an error.

Parameters
textThe JSON Array as a string
Returns
a non-null JSONArray
JSONObject bridges.connect.Connector.asJSONObject ( String  text) throws IOException

Decode a String containing JSON into a JSON Object, or throw an error.

Parameters
textThe input JSON text
Returns
A non-null JSON object
String bridges.connect.Connector.executeHTTPRequest ( Request  request) throws ClientProtocolException, IOException, RateLimitException

Execute an Apache Fluent Request. Decorates HTTP error tracebacks with urls and server {"error": "..."} responses. Throws an IOException with URL if the server returns an empty response. Returns server response if the status code is >= 400 but can still throw other exceptions if JSON parsing fails when formatting server JSON response

Parameters
request
Returns
the requested string from the server
Exceptions
ClientProtocolException
IOException
RateLimitException
String bridges.connect.Connector.get ( String  url) throws RateLimitException, IOException

Execute a simple GET request relative to the server root. Omit the leading http://hostname, but include the leading /:

[bad]: http://myserver:9183/api/followgraph/user/sean NullPointerException

String bridges.connect.Connector.getServerURL ( )

Get the current base URL for the DataFormatters server (with no ending/)

Returns
String bridges.connect.Connector.getUSGS ( String  url) throws RateLimitException, IOException

Execute a request of earthquakes to https://earthquakes-uncc.herokuapp.com/eq/

Parameters
url
Returns
JSON string
Exceptions
RateLimitException
IOException
String bridges.connect.Connector.latlongFormatter ( String  text)

This reformats the coordinates in Earthwuake tweet such that there will be no arrays present when casting to the JSONObject. for the resons described below Mihai

Parameters
text
Returns
String bridges.connect.Connector.post ( String  url,
Map< String, String >  arguments 
) throws IOException, RateLimitException

Execute a simple POST request with relative paths, taking a Scala Map() of request parameters.

String bridges.connect.Connector.post ( String  url,
String  data 
) throws IOException, RateLimitException
String bridges.connect.Connector.prepare ( String  url)

Escape the URL and prepend the base URL.

Returns
the new url as a String
String bridges.connect.Connector.prepareUSGS ( String  url)
Object bridges.connect.Connector.safeJSONTraverse ( String  sequence,
Object  original,
Class<?>  target 
) throws IOException

Traverse JSON in a type-safe manner. This is somewhat complicated, but comes with the advantage that the debugging reports are far clearer when you know the whole path you are searching for.

Use this syntax: [ number ] to access an array element, ["quoted string"] to get an object attribute

Parameters
sequence
o
void bridges.connect.Connector.setServer ( String  server) throws IllegalArgumentException

Set the current DataFormatters server to live, clone, or local, or throw an error;

Parameters
server
void bridges.connect.Connector.setServerURL ( String  server_url)

Set the current base URL for the DataFormatters server (with no ending /)

Parameters
server_url
String bridges.connect.Connector.trimmLast ( String  text)

Trimm the end of the earthquake data: ,"products":{"String":[]}

Important: future implementations could combine the above in one single method with a hash table for different patters Mihai

Parameters
text
Returns

The documentation for this class was generated from the following file: