class OkraSDK

Attributes

production[RW]
public_key[RW]
secret_key[RW]
url[RW]

Public Class Methods

new(public_key=nil, secret_key=nil, production=false) click to toggle source

method to initialize Okra object

# File lib/okra_sdk.rb, line 26
def initialize(public_key=nil, secret_key=nil, production=false)
    @public_key = public_key
    @secret_key = secret_key
    @production = production

    okra_sandbox_url = BASE_ENDPOINTS::OKRA_SANDBOX_URL
    okra_live_url = BASE_ENDPOINTS::OKRA_LIVE_URL

    #set okra url to sandbox or live if we are in production or development

    if production ==false
        @url = okra_sandbox_url
    else
        @url = okra_live_url
end

def base_url
    return url
end

#check if we set our public, secret keys to the environment variable

if (public_key.nil?)
    @public_key = ENV['OKRA_PUBLIC_KEY']
else
    @public_key = public_key
end

if (secret_key.nil?)
    @secret_key = ENV['OKRA_SECRET_KEY']
else
    @secret_key = secret_key
end

warn "Warning: To ensure your okra api keys are safe, It is best to always set your keys in the environment variable"

#raise this error if no public key is passed

unless !@public_key.nil?

    raise OkraBadKeyError, "No public key supplied and couldn't find any in environment variables. Make sure to set public key as an environment variable OKRA_PUBLIC_KEY"
end

  #raise this error if no secret key is passed

  unless !@secret_key.nil?

    raise OkraBadKeyError, "No secret key supplied and couldn't find any in environment variables. Make sure to set secret key as an environment variable OKRA_SECRET_KEY"
  end

end

Public Instance Methods

base_url() click to toggle source
# File lib/okra_sdk.rb, line 42
def base_url
    return url
end