Bridges-Java  3.4.3
Bridges(Java API)
Public Member Functions | Protected Member Functions | Package Attributes | List of all members
bridges.connect.Connector Class Reference

Public Member Functions

void setServer (String server) throws IllegalArgumentException
 
String getServerURL ()
 
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
 Traverse JSON in a type-safe manner. More...
 
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 delete (String url) throws IOException, RateLimitException
 
String prepare (String url)
 
String prepareUSGS (String url)
 

Protected Member Functions

 Connector ()
 
void setServerURL (String server_url)
 

Package Attributes

String server_live = "http://bridges-cs.herokuapp.com"
 
String server_clone = "http://bridges-clone.herokuapp.com"
 
String server_sockets = "http://bridges-sockets.herokuapp.com"
 
String server_games = "http://bridges-games.herokuapp.com"
 
String server_local = "http://127.0.0.1:3000"
 
String server_type = "application"
 
String server_url = "http://bridges-cs.herokuapp.com"
 
String usgs_url = "https://earthquakes-uncc.herokuapp.com/eq"
 
String airline_url = "https://earthquakes-uncc.herokuapp.com/airline"
 
Executor http_connection
 
int pattern_found = 0
 

Constructor & Destructor Documentation

◆ Connector()

bridges.connect.Connector.Connector ( )
protected

Member Function Documentation

◆ asJSONArray()

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

◆ asJSONObject()

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

◆ delete()

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

Send a delete request to the server for the given user and assignment

Parameters
urlsend a delete request using this url

◆ executeHTTPRequest()

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

◆ get()

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

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

[bad]: http://bridgesdata.herokuapp.com/api/songs/find/Bohemian%20Rhapsody NullPointerException

◆ getServerURL()

String bridges.connect.Connector.getServerURL ( )

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

Returns
url of the server

◆ getUSGS()

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

Execute a request of earthquakes to Earthquake server

Parameters
url
Returns
JSON string
Exceptions
RateLimitException
IOException

◆ latlongFormatter()

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 reasons described below

Parameters
text
Returns

◆ post() [1/2]

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.

◆ post() [2/2]

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

◆ prepare()

String bridges.connect.Connector.prepare ( String  url)

Escape the URL and prepend the base URL.

Parameters
urlprepare the request to be sent using this url
Returns
the new url as a String

◆ prepareUSGS()

String bridges.connect.Connector.prepareUSGS ( String  url)
Parameters
urlprepare the request to be sent using this url for earthquake data
Returns
the new url as a String

◆ safeJSONTraverse()

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
original
target

◆ setServer()

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

Set the current server to 'live', 'clone', or 'local', or throw an error; live is the default, clone is used for development/testing and local for use by developers on their local machines

Parameters
serverserver type

◆ setServerURL()

void bridges.connect.Connector.setServerURL ( String  server_url)
protected

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

Parameters
server_urlserver url to be set

◆ trimmLast()

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

Member Data Documentation

◆ airline_url

String bridges.connect.Connector.airline_url = "https://earthquakes-uncc.herokuapp.com/airline"
package

◆ http_connection

Executor bridges.connect.Connector.http_connection
package

◆ pattern_found

int bridges.connect.Connector.pattern_found = 0
package

◆ server_clone

String bridges.connect.Connector.server_clone = "http://bridges-clone.herokuapp.com"
package

◆ server_games

String bridges.connect.Connector.server_games = "http://bridges-games.herokuapp.com"
package

◆ server_live

String bridges.connect.Connector.server_live = "http://bridges-cs.herokuapp.com"
package

◆ server_local

String bridges.connect.Connector.server_local = "http://127.0.0.1:3000"
package

◆ server_sockets

String bridges.connect.Connector.server_sockets = "http://bridges-sockets.herokuapp.com"
package

◆ server_type

String bridges.connect.Connector.server_type = "application"
package

◆ server_url

String bridges.connect.Connector.server_url = "http://bridges-cs.herokuapp.com"
package

◆ usgs_url

String bridges.connect.Connector.usgs_url = "https://earthquakes-uncc.herokuapp.com/eq"
package

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