lib/InKomerce_API_v1.rb
# make a call to the InKomerce API
make a call to the InKomerce API
make a call to the InKomerce API
def call(call, method = :get, params = false)
      url = URI.parse(@api_endpoint + call)
      send_xml = params.is_a?(Hash) && params.delete(:send_xml)
      send_format = send_xml ? 'xml' : 'json'
      case method
      when :get
        url.query = params.keys.map { |key| "#{key}=#{params[key]}"}.join('&') if params.is_a?(Hash)
        path = url.path
        path += '?' + url.query if url.query
        p "INKAPI:GET #{path}"
        call = Net::HTTP::Get.new(path)
      when :post
        p "INKAPI:POST #{url.path}"
        call = Net::HTTP::Post.new(url.path, {'Content-Type' => "application/#{send_format}", 'User-Agent' => 'InKomerce API Ruby SDK'})
        p send_format
        if params
          call.body = send_xml ? params.to_xml : params.to_json
        end
      when :put
        p "INKAPI:PUT #{url.path}"
        call = Net::HTTP::Put.new(url.path, {'Content-Type' => "application/#{send_format}", 'User-Agent' => 'InKomerce API Ruby SDK'})
        if params
          call.body = send_xml ? params.to_xml : params.to_json
        end
      when :delete
        url.query = params.keys.map { |key| "#{key}=#{params[key]}"}.join('&') if params.is_a?(Hash)
        path = url.path
        path += '?' + url.query if url.query
        p "INKAPI:DELETE #{path}"
        call = Net::HTTP::Delete.new(path)
      end
      if @token
        call.add_field('authorization',"Bearer token=#{@token}")
      end
      response = Net::HTTP.start(url.host, url.port, use_ssl: (url.scheme=='https')) {
        |http| http.request(call)
      }
      symbolize_return_record_keys(JSON.parse(response.body))
    end
def call ( call , method = :get , params = false ) url = URI . parse ( @api_endpoint + call ) send_xml = params . is_a? ( Hash ) && params . delete ( :send_xml ) send_format = send_xml ? 'xml' : 'json' case method when :get url . query = params . keys . map { | key | "#{key}=#{params[key]}" } . join ( '&' ) if params . is_a? ( Hash ) path = url . path path += '?' + url . query if url . query p "INKAPI:GET #{path}" call = Net :: HTTP :: Get . new ( path ) when :post p "INKAPI:POST #{url.path}" call = Net :: HTTP :: Post . new ( url . path , { 'Content-Type' => "application/#{send_format}" , 'User-Agent' => 'InKomerce API Ruby SDK' } ) p send_format if params call . body = send_xml ? params . to_xml : params . to_json end when :put p "INKAPI:PUT #{url.path}" call = Net :: HTTP :: Put . new ( url . path , { 'Content-Type' => "application/#{send_format}" , 'User-Agent' => 'InKomerce API Ruby SDK' } ) if params call . body = send_xml ? params . to_xml : params . to_json end when :delete url . query = params . keys . map { | key | "#{key}=#{params[key]}" } . join ( '&' ) if params . is_a? ( Hash ) path = url . path path += '?' + url . query if url . query p "INKAPI:DELETE #{path}" call = Net :: HTTP :: Delete . new ( path ) end if @token call . add_field ( 'authorization' , "Bearer token=#{@token}" ) end response = Net :: HTTP . start ( url . host , url . port , use_ssl : ( url . scheme == 'https' ) ) { | http | http . request ( call ) } symbolize_return_record_keys ( JSON . parse ( response . body ) ) end
make a call to the InKomerce API
make a call to the InKomerce API
# get the url # create the request object # returns JSON response as ruby hash
call
<not_specific>
method
<not_specific>
params
<not_specific>