class MeserOngkir::Api

Public Class Methods

new(account_type, main_path, params) click to toggle source
# File lib/meser_ongkir/api.rb, line 7
def initialize(account_type, main_path, params)
  @account_type = account_type
  @main_path = main_path
  @params = params
end

Public Instance Methods

call() click to toggle source
# File lib/meser_ongkir/api.rb, line 13
def call
  url = URI(api_url)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  url.query = URI.encode_www_form(@params) if @params

  request = Net::HTTP::Get.new(url)
  request['key'] = ENV['MESER_ONGKIR_API_KEY']
  http.request(request)
end
read_body() click to toggle source
# File lib/meser_ongkir/api.rb, line 26
def read_body
  call.read_body
end

Private Instance Methods

api_url() click to toggle source
# File lib/meser_ongkir/api.rb, line 32
def api_url
  "https://api.rajaongkir.com/#{@account_type}/#{@main_path}"
end