class Client
Base class for 3taps API client classes.
Constants
- DEFAULT_API_PORT
- DEFAULT_URL
- TIMEOUT
Public Class Methods
new(baseUrl = DEFAULT_URL, port = DEFAULT_API_PORT)
click to toggle source
Initializes Client
class with baseUrl
and port
parameters. By default DEFAULT_URL
and DEFAULT_API_PORT
are used. Examples:
Client.new Client.new("http://3taps.com", 8080)
# File lib/client/client.rb, line 10 def initialize(baseUrl = DEFAULT_URL, port = DEFAULT_API_PORT) @baseURL = baseUrl @port = port end
Public Instance Methods
execute_get( path, params = nil )
click to toggle source
Executes GET request on URL and port with path
and params
parameters. Example:
execute_get("/search", "data=data")
# 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 )
click to toggle source
Executes POST request on URL and port with path
and params
parameters. Example:
execute_post("search", "data=data")
# 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
Private Instance Methods
decode(data)
click to toggle source
# File lib/client/client.rb, line 43 def decode(data) ActiveSupport::JSON.decode(data) end