class MoneyMover::Dwolla::ApiResource

Attributes

_embedded[RW]
attrs[R]
id[RW]
resource_location[R]

Public Class Methods

fetch() click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 20
def self.fetch
  client = ApplicationClient.new

  response = client.get fetch_endpoint

  if response.success?
    new response.body
  else
    #raise 'Customer Not Found'
    #puts "error: #{response.body}"
  end
end
new(attrs = {}, client = ApplicationClient.new) click to toggle source
Calls superclass method
# File lib/money_mover/dwolla/models/api_resource.rb, line 10
def initialize(attrs = {}, client = ApplicationClient.new)
  @attrs = attrs
  @id = attrs[:id]
  @resource_location = attrs[:resource_location]
  @_links = attrs[:_links]
  @client = client

  super attrs
end

Public Instance Methods

destroy() click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 48
def destroy
  response = @client.delete resource_endpoint

  add_errors_from response unless response.success?

  errors.empty?
end
save() click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 33
def save
  return false unless valid?

  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

  errors.empty?
end

Private Instance Methods

add_errors_from(model) click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 58
def add_errors_from(model)
  model.errors.each do |key, messages|
    errors.add key, messages
  end
end
create_params() click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 68
def create_params
  {}
end
resource_endpoint() click to toggle source
# File lib/money_mover/dwolla/models/api_resource.rb, line 64
def resource_endpoint
  "#{create_endpoint}/#{id}"
end