Class: BloomRemit2::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/bloom_remit2/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, deleted_at = nil, deleted: false) ⇒ Agent

Returns a new instance of Agent.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bloom_remit2/agent.rb', line 72

def initialize(
  id,
  name,
  deleted_at=nil,
  deleted: false
)
  @id = id
  @name = name
  @deleted_at = deleted_at
  @deleted = deleted
end

Instance Attribute Details

#deletedObject (readonly)

Returns the value of attribute deleted.



70
71
72
# File 'lib/bloom_remit2/agent.rb', line 70

def deleted
  @deleted
end

#deleted_atObject (readonly)

Returns the value of attribute deleted_at.



70
71
72
# File 'lib/bloom_remit2/agent.rb', line 70

def deleted_at
  @deleted_at
end

#idObject (readonly)

Returns the value of attribute id.



70
71
72
# File 'lib/bloom_remit2/agent.rb', line 70

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



70
71
72
# File 'lib/bloom_remit2/agent.rb', line 70

def name
  @name
end

Class Method Details

.create(name) ⇒ Object

Create a new agent under this partner

Parameters:

  • name (String)

    agent name



29
30
31
32
33
34
35
# File 'lib/bloom_remit2/agent.rb', line 29

def create(name)
  agent = Client.post(path, { agent: { name: name }}).with_indifferent_access
  new(
    agent[:id],
    agent[:name]
  )
end

.delete(agent_id) ⇒ Object

Delete an agent belonging to this partner

Parameters:

  • agent_id (String)

    agent uuid to delete



52
53
54
55
56
57
58
59
60
61
# File 'lib/bloom_remit2/agent.rb', line 52

def delete(agent_id)
  message = Client.delete("#{path}/#{agent_id}").with_indifferent_access
  if message[:success] == "We've successfully deleted that agent."
    new(
      agent_id,
      nil,
      deleted: true
    )
  end
end

.listObject

Show a list of agents belonging to this partner



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bloom_remit2/agent.rb', line 5

def list
  agents = Client.get(path)
  agents.map do |agent|
    agent = agent.with_indifferent_access
    new(
      agent[:id],
      agent[:name],
      agent[:deleted_at]
    )
  end
end

.retrieve(id) ⇒ Object

Show an agent belonging to this partner

Parameters:

  • id (String)

    agent uuid to retrieve details for



19
20
21
22
23
24
25
# File 'lib/bloom_remit2/agent.rb', line 19

def retrieve(id)
  agent = Client.get("#{path}/#{id}").with_indifferent_access
  new(
    agent[:id],
    agent[:name]
  )
end