Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/client/client.rb
Overview
Base class for 3taps API client classes.
Direct Known Subclasses
GeocoderClient, PostingClient, ReferenceClient, SearchClient, StatusClient
Constant Summary collapse
- DEFAULT_URL =
'http://3taps.net'
- DEFAULT_API_PORT =
80
- TIMEOUT =
15
Instance Method Summary collapse
-
#execute_get(path, params = nil) ⇒ Object
Executes GET request on URL and port with
path
andparams
parameters. -
#execute_post(path, params = nil) ⇒ Object
Executes POST request on URL and port with
path
andparams
parameters. -
#initialize(baseUrl = DEFAULT_URL, port = DEFAULT_API_PORT) ⇒ Client
constructor
Initializes Client class with
baseUrl
andport
parameters.
Constructor Details
#initialize(baseUrl = DEFAULT_URL, port = DEFAULT_API_PORT) ⇒ Client
10 11 12 13 |
# File 'lib/client/client.rb', line 10 def initialize(baseUrl = DEFAULT_URL, port = DEFAULT_API_PORT) @baseURL = baseUrl @port = port end |
Instance Method Details
#execute_get(path, params = nil) ⇒ Object
Executes GET request on URL and port with path
and params
parameters. Example:
execute_get("/search", "data=data")
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/client/client.rb', line 19 def execute_get( path, params = nil ) address = params.nil? ? path : path + '?' + params request = Curl::Easy.new("#{@baseURL}:#{@port}" + address) begin request.perform rescue "Some Error with Request." end request.body_str end |
#execute_post(path, params = nil) ⇒ Object
Executes POST request on URL and port with path
and params
parameters. Example:
execute_post("search", "data=data")
34 35 36 37 38 39 |
# File 'lib/client/client.rb', line 34 def execute_post( path, params = nil ) c = Curl::Easy.new("#{@baseURL}:#{@port}/#{path}") param, data = params.split("=",2) c.http_post(param.to_s + '=' + c.escape(data.to_s)) c.body_str end |