Class: Manabu::ContactTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/manabu/contact_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ContactTypes

Returns a new instance of ContactTypes.



5
6
7
8
# File 'lib/manabu/contact_types.rb', line 5

def initialize(client)
  @client = client
  @contact_types = {}
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/manabu/contact_types.rb', line 3

def client
  @client
end

Instance Method Details

#allObject



17
18
19
20
21
22
23
24
# File 'lib/manabu/contact_types.rb', line 17

def all
  return @contact_types unless @contact_types.empty?

  response = @client.get("/contact_types")
  @contact_types = response[:contact_types].each_with_object({}) do |type, obj|
    obj[type[:name]] = type[:id]
  end
end

#register(name) ⇒ Object



10
11
12
13
14
15
# File 'lib/manabu/contact_types.rb', line 10

def register(name)
  response = @client.post("/contact_types", name: name)
  response[:id]
rescue
  nil
end