Class: Closeio::Rails::CustomField

Inherits:
Base
  • Object
show all
Defined in:
app/models/closeio/rails/custom_field.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#attributes

Class Method Details

.allObject



5
6
7
8
9
# File 'app/models/closeio/rails/custom_field.rb', line 5

def self.all
  Closeio::Rails.configuration.client.list_custom_fields.collect do |field|
    self.new(field)
  end
end

.create(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/models/closeio/rails/custom_field.rb', line 15

def self.create(params)
  response = Closeio::Rails.configuration.client.create_custom_field(params)
  if response.has_key?('field-errors')
    raise Closeio::Error, "#{response['field-errors']['name']}"
  elsif response.has_key?('error')
    raise Closeio::Error, "#{response['error']}"
  else
    response
  end
end

.find(id) ⇒ Object



11
12
13
# File 'app/models/closeio/rails/custom_field.rb', line 11

def self.find(id)
  self.new(Closeio::Rails.configuration.client.find_custom_field(id))
end

Instance Method Details

#add_choice(choice) ⇒ Object



26
27
28
29
# File 'app/models/closeio/rails/custom_field.rb', line 26

def add_choice(choice)
  new_choices = choices.push(choice)
  Closeio::Rails.configuration.client.update_custom_field(id,choices: new_choices)
end

#remove_choice(choice) ⇒ Object



31
32
33
34
# File 'app/models/closeio/rails/custom_field.rb', line 31

def remove_choice(choice)
  new_choices = choices.reject {|c| c == choice}
  Closeio::Rails.configuration.client.update_custom_field(id,choices: new_choices)
end

#set_all_choices(choices) ⇒ Object



36
37
38
# File 'app/models/closeio/rails/custom_field.rb', line 36

def set_all_choices(choices)
  Closeio::Rails.configuration.client.update_custom_field(id,choices: choices)
end