class HelperService::Service

Public Class Methods

new(options) click to toggle source
# File lib/netpay_ecommerce_ruby/helpers/helper_service.rb, line 7
def initialize options
  @endpoint  = options.fetch(:service_name, nil)
  @method    = options.fetch(:method, nil)
  @security  = options.fetch(:security_token, false)
  @host      = options.fetch(:host, nil)
  @body      = options.fetch(:body, nil)
  @token     = options.fetch(:token, nil)
  @transport = options.fetch(:transport_method, nil)
end

Public Instance Methods

delete() click to toggle source
# File lib/netpay_ecommerce_ruby/helpers/helper_service.rb, line 79
def delete
  
end
get() click to toggle source
# File lib/netpay_ecommerce_ruby/helpers/helper_service.rb, line 21
def get
  uri = URI("#{@host}#{@endpoint}#{@body}")
  http = Net::HTTP.new(uri.host, uri.port)

  if uri.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  request = Net::HTTP::Get.new(uri)
  request["authorization"] = @token
  request["Content-Type"] = 'application/json; charset=utf-8'
  request["accept"] = 'application/json'

  response = http.request(request)

  if ("200".."299").to_a.include? response.code
    [JSON.parse(response.body), response.code]
  elsif ("400".."499").to_a.include? response.code
    [JSON.parse(response.body), response.code]
  end
end
post() click to toggle source
# File lib/netpay_ecommerce_ruby/helpers/helper_service.rb, line 44
def post
  url = URI("#{@host}#{@endpoint}")

  http = Net::HTTP.new(url.host, url.port)

  if url.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  request = Net::HTTP::Post.new(url)
  request["Content-Type"] = 'application/json; charset=utf-8'
  request["Accept"] = 'application/json'
  if @security
    request["authorization"] = @token
  end
  if @transport == "json"
    request.body = @body
  else
    if @body.class == Hash
      request.body = @body.to_json
    else
      request.body = @body
    end
  end

  response = http.request(request)
  
  if ("200".."299").to_a.include? response.code
    [JSON.parse(response.body), response.code]
  elsif ("400".."499").to_a.include? response.code
    [JSON.parse(response.body), response.code]
  end
end
send_request() click to toggle source
# File lib/netpay_ecommerce_ruby/helpers/helper_service.rb, line 17
def send_request
  self.send @method
end