Class: MoneyMover::Dwolla::ApiResource

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/money_mover/dwolla/models/api_resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}, client = ApplicationClient.new) ⇒ ApiResource

Returns a new instance of ApiResource.



10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#_embeddedObject

Returns the value of attribute _embedded.



6
7
8
# File 'lib/money_mover/dwolla/models/api_resource.rb', line 6

def _embedded
  @_embedded
end

Returns the value of attribute _links.



6
7
8
# File 'lib/money_mover/dwolla/models/api_resource.rb', line 6

def _links
  @_links
end

#attrsObject (readonly)

Returns the value of attribute attrs.



8
9
10
# File 'lib/money_mover/dwolla/models/api_resource.rb', line 8

def attrs
  @attrs
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/money_mover/dwolla/models/api_resource.rb', line 6

def id
  @id
end

#resource_locationObject (readonly)

Returns the value of attribute resource_location.



8
9
10
# File 'lib/money_mover/dwolla/models/api_resource.rb', line 8

def resource_location
  @resource_location
end

Class Method Details

.fetchObject



20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#destroyObject



48
49
50
51
52
53
54
# 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

#saveObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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