Class: BlueStateDigital::Constituent
- Inherits:
-
ApiDataModel
- Object
- ApiDataModel
- BlueStateDigital::Constituent
- Defined in:
- lib/blue_state_digital/constituent.rb
Constant Summary collapse
- FIELDS =
[:id, :firstname, :lastname, :is_banned, :create_dt, :ext_id, :birth_dt, :gender, :emails, :addresses, :phones, :groups, :is_new]
Constants inherited from ApiDataModel
Instance Attribute Summary collapse
-
#group_ids ⇒ Object
Returns the value of attribute group_ids.
Attributes inherited from ApiDataModel
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Constituent
constructor
A new instance of Constituent.
- #is_new? ⇒ Boolean
- #save ⇒ Object
- #to_xml ⇒ Object
Methods inherited from ApiDataModel
Constructor Details
#initialize(attrs = {}) ⇒ Constituent
Returns a new instance of Constituent.
8 9 10 11 |
# File 'lib/blue_state_digital/constituent.rb', line 8 def initialize(attrs = {}) super(attrs) self.group_ids = [] end |
Instance Attribute Details
#group_ids ⇒ Object
Returns the value of attribute group_ids.
6 7 8 |
# File 'lib/blue_state_digital/constituent.rb', line 6 def group_ids @group_ids end |
Instance Method Details
#is_new? ⇒ Boolean
26 27 28 |
# File 'lib/blue_state_digital/constituent.rb', line 26 def is_new? is_new == "1" end |
#save ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/blue_state_digital/constituent.rb', line 13 def save xml = connection.wait_for_deferred_result( connection.perform_request '/cons/upsert_constituent_data', {}, "POST", self.to_xml ) doc = Nokogiri::XML(xml) record = doc.xpath('//cons').first if record self.id = record[:id] self.is_new = record[:is_new] else raise "upsert_constituent_data failed with message: #{xml}" end self end |
#to_xml ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/blue_state_digital/constituent.rb', line 30 def to_xml builder = Builder::XmlMarkup.new builder.instruct! :xml, version: '1.0', encoding: 'utf-8' builder.api do |api| cons_attrs = {} cons_attrs[:id] = self.id unless self.id.blank? unless self.ext_id.blank? cons_attrs[:ext_id] = self.ext_id.id unless self.ext_id.id.blank? cons_attrs[:ext_type] = self.ext_id.type unless self.ext_id.type.blank? end api.cons(cons_attrs) do |cons| cons.firstname(self.firstname) unless self.firstname.blank? cons.lastname(self.lastname) unless self.lastname.blank? cons.is_banned(self.is_banned) unless self.is_banned.blank? cons.create_dt(self.create_dt) unless self.create_dt.blank? cons.birth_dt(self.birth_dt) unless self.birth_dt.blank? cons.gender(self.gender) unless self.gender.blank? unless self.emails.blank? self.emails.each {|email| build_constituent_email(email, cons) } end unless self.addresses.blank? self.addresses.each {|address| build_constituent_address(address, cons) } end unless self.phones.blank? self.phones.each {|phone| build_constituent_phone(phone, cons) } end unless self.groups.blank? self.groups.each {|group| build_constituent_group(group, cons) } end end end end |