lib/wialon.rb
def call(action, args)
    # Set local variable with base url
    url = self.base_api_url

    # Set params
    params = {'svc': action.to_s.sub('_', '/'), 'params': JSON.generate(args), 'sid': self.sid}
    
    # Replacing global params with local params
    all_params = self.default_params.replace(params)

    if self.debug
      puts "========="
      puts "Query URL: #{url} - Params: #{all_params}"
      puts "========="
      puts "#{url}&svc=#{action.to_s.sub('_', '/')}&params=#{JSON.generate(args)}&sid=#{self.sid}"
      puts "========="
    end

    uri = URI.parse(url)
    
    # Curl request
    request = Net::HTTP::Post.new(uri)

    request.set_form_data(
      "svc" => action.to_s.sub('_', '/'),
      "params" => JSON.generate(args),
      "sid" => self.sid
    )

    req_options = { use_ssl: (uri.scheme == "https") }

    response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
      http.request(request)
    end

    response = JSON.parse(response.body, symbolize_names: true)

    if response.class == Hash
      if !response[:error].nil?
        return {
          status: 400,
          reason: parse_errors(response[:error]),
          result: response
        }
      end
    end

    return {
      status: 200,
      result: response
    }
  end
# RemoteAPI request performer
# action: RemoteAPI command name
# args: JSON string with request parameters
RemoteAPI request performer
action: RemoteAPI command name
args: JSON string with request parameters
RemoteAPI request performer action : RemoteAPI command name args : JSON string with request parameters
def call(action, args)
    url = self.base_api_url
    params = {'svc': action.to_s.sub('_', '/'), 'params': JSON.generate(args), 'sid': self.sid}
    all_params = self.default_params.replace(params)
    if self.debug
      puts "========="
      puts "Query URL: #{url} - Params: #{all_params}"
      puts "========="
      puts "#{url}&svc=#{action.to_s.sub('_', '/')}&params=#{JSON.generate(args)}&sid=#{self.sid}"
      puts "========="
    end
    uri = URI.parse(url)
    request = Net::HTTP::Post.new(uri)
    request.set_form_data(
      "svc" => action.to_s.sub('_', '/'),
      "params" => JSON.generate(args),
      "sid" => self.sid
    )
    req_options = { use_ssl: (uri.scheme == "https") }
    response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
      http.request(request)
    end
    response = JSON.parse(response.body, symbolize_names: true)
    if response.class == Hash
      if !response[:error].nil?
        return {
          status: 400,
          reason: parse_errors(response[:error]),
          result: response
        }
      end
    end
    return {
      status: 200,
      result: response
    }
  end
def call ( action , args ) url = self . base_api_url params = { 'svc' : action . to_s . sub ( '_' , '/' ) , 'params' : JSON . generate ( args ) , 'sid' : self . sid } all_params = self . default_params . replace ( params ) if self . debug puts "=========" puts "Query URL: #{url} - Params: #{all_params}" puts "=========" puts "#{url}&svc=#{action.to_s.sub('_', '/')}&params=#{JSON.generate(args)}&sid=#{self.sid}" puts "=========" end uri = URI . parse ( url ) request = Net :: HTTP :: Post . new ( uri ) request . set_form_data ( "svc" => action . to_s . sub ( '_' , '/' ) , "params" => JSON . generate ( args ) , "sid" => self . sid ) req_options = { use_ssl : ( uri . scheme == "https" ) } response = Net :: HTTP . start ( uri . hostname , uri . port , req_options ) do | http | http . request ( request ) end response = JSON . parse ( response . body , symbolize_names : true ) if response . class == Hash if ! response [ :error ] . nil? return { status : 400 , reason : parse_errors ( response [ :error ] ) , result : response } end end return { status : 200 , result : response } end
RemoteAPI request performer
action: RemoteAPI command name
args: JSON string with request parameters
RemoteAPI request performer action : RemoteAPI command name args : JSON string with request parameters
# Set local variable with base url # Set params # Replacing global params with local params # Curl request
action
args