class MoneyMover::Dwolla::Customer

Constants

COMPANY_TYPES

Attributes

address1[RW]
address2[RW]
businessClassification[RW]
businessName[RW]
businessType[RW]
city[RW]
created[RW]
dateOfBirth[RW]
doingBusinessAs[RW]
ein[RW]
email[RW]
firstName[RW]
ipAddress[RW]
lastName[RW]
phone[RW]
postalCode[RW]
ssn[RW]
state[RW]
status[RW]
type[RW]
website[RW]

Public Class Methods

find(id) click to toggle source
# File lib/money_mover/dwolla/models/customer.rb, line 28
def self.find(id)
  client = ApplicationClient.new

  response = client.get fetch_endpoint(id)

  if response.success?
    new response.body
  else
    raise 'Customer Not Found'
    #puts "error: #{response.body}"
  end
end

Private Class Methods

fetch_endpoint(id) click to toggle source
# File lib/money_mover/dwolla/models/customer.rb, line 74
def self.fetch_endpoint(id)
  "/customers/#{id}"
end

Public Instance Methods

save() click to toggle source
# File lib/money_mover/dwolla/models/customer.rb, line 41
def save
  return false unless valid?

  if @id
    response = @client.post self.class.fetch_endpoint(@id), create_params
    add_errors_from response unless response.success?
  else
    response = @client.post create_endpoint, create_params

    if response.success?
      @resource_location = response.resource_location
      @id = response.resource_id
    else
      add_errors_from response
    end
  end

  errors.empty?
end

Private Instance Methods

create_endpoint() click to toggle source
# File lib/money_mover/dwolla/models/customer.rb, line 78
def create_endpoint
  "/customers"
end
website_with_protocol() click to toggle source

dwolla doesnt accept urls without a scheme

# File lib/money_mover/dwolla/models/customer.rb, line 64
def website_with_protocol
  return nil unless website.present?

  if website =~ %r{^https?://}
    website
  else
    "http://#{website}"
  end
end