class GiftRocket::Account

Public Class Methods

config_file() click to toggle source
# File lib/gift_rocket/account.rb, line 25
def self.config_file
  path = defined?(Rails) ? Rails.root : Dir.getwd
  File.join(path, 'config/gift_rocket.yml')
end
new(options = {}) click to toggle source
# File lib/gift_rocket/account.rb, line 9
def initialize(options = {})
  data = File.exist?(self.class.config_file) ? YAML.load_file(self.class.config_file) : {}

  @api_key          = options[:api_key] || ENV['GIFT_ROCKET_API_KEY'] || data['api_key']
  @payment_source   = options[:payment_source] || data['payment_source'] || 'card'
  @sender_name      = options[:sender_name] || data['sender_name']

  raise GiftRocket::Error::MissingApiKey.new('api_key not specified') if @api_key.nil?
  raise GiftRocket::Error::MissingSenderName.new('sender_name not specified') if (@sender_name.nil? || @sender_name.empty?)
  raise GiftRocket::Error::InvalidPaymentSource.new('payment_source is not valid') unless ['card','ach','invoice'].include?(@payment_source)
end

Public Instance Methods

params() click to toggle source
# File lib/gift_rocket/account.rb, line 30
def params
  {'api_key' => @api_key, 'payment_source' => @payment_source, 'gift[sender_name]' => @sender_name}
end
send(gift, recipient) click to toggle source
# File lib/gift_rocket/account.rb, line 21
def send(gift, recipient)
  GiftRocket.send(gift, self, recipient)
end