Module: Constituents
- Included in:
- TessituraRest
- Defined in:
- lib/tessitura_rest/crm/constituents.rb
Instance Method Summary collapse
- #create_constituent_by_snapshot(first_name, last_name, email, phone, constituent_type, source, street1, street2, city, state, zip, country, options = {}) ⇒ Object
- #get_constituent_snapshot(id, options = {}) ⇒ Object
- #is_household?(snapshot) ⇒ Boolean
- #update_constituent(constituent_id, params, options = {}) ⇒ Object
- #update_household(params, current, options = {}) ⇒ Object
Instance Method Details
#create_constituent_by_snapshot(first_name, last_name, email, phone, constituent_type, source, street1, street2, city, state, zip, country, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/tessitura_rest/crm/constituents.rb', line 8 def create_constituent_by_snapshot(first_name, last_name, email, phone, constituent_type, source, street1, street2, city, state, zip, country, = {}) parameters = { 'ConstituentType': { 'Id': constituent_type, 'Inactive': false, }, 'FirstName': first_name, 'LastName': last_name, 'ElectronicAddress': { 'Address': email, 'ElectronicAddressType': { 'Id': 1, }, 'AllowHtmlFormat': true, 'Inactive': false, 'AllowMarketing': false, 'Months': 'YYYYYYYYYYYY', 'PrimaryIndicator': true, }, 'PrimaryPhoneNumbers': [ { 'PhoneNumber': phone, 'PhoneType': { 'Id': 5, }, }, ], 'OriginalSource': { 'Id': source, }, 'Address': { 'AddressType': { 'Id': 3, }, 'City': city, 'PostalCode': zip, 'State': { 'Id': state, }, 'Street1': street1, 'Street2': street2, 'Country': { 'Id': country, }, }, } parameters.delete(:PrimaryPhoneNumbers) unless phone.present? .merge!(basic_auth: @auth, headers: @headers) .merge!(:body => parameters.to_json, :headers => { 'Content-Type' => 'application/json' }) self.class.post(base_api_endpoint('CRM/Constituents/Snapshot'), ) end |
#get_constituent_snapshot(id, options = {}) ⇒ Object
2 3 4 5 6 |
# File 'lib/tessitura_rest/crm/constituents.rb', line 2 def get_constituent_snapshot(id, = {}) .merge!(basic_auth: @auth, headers: @headers) response = self.class.get(base_api_endpoint("CRM/Constituents/#{id}/Snapshot"), ) JSON.parse(response.body) end |
#is_household?(snapshot) ⇒ Boolean
101 102 103 |
# File 'lib/tessitura_rest/crm/constituents.rb', line 101 def is_household?(snapshot) snapshot['ConstituentType']['Id'] == 9 end |
#update_constituent(constituent_id, params, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/tessitura_rest/crm/constituents.rb', line 63 def update_constituent(constituent_id, params, = {}) current = get_constituent_snapshot(constituent_id) if is_household?(current) update_household(params, current) else parameters = { 'ConstituentType': { 'Id': current['ConstituentType']['Id'], 'Inactive': false, }, 'Id': constituent_id, 'UpdatedDateTime': current['UpdatedDateTime'], 'FirstName': params[:first_name], 'LastName': params[:last_name], 'MiddleName': params[:middle_name], 'SortName': current['SortName'], 'Prefix': { 'Id': params[:prefix], 'Inactive': false, }, 'Suffix': { 'Id': params[:suffix], 'Inactive': false, }, 'OriginalSource': { 'Id': current['OriginalSource']['Id'], 'Inactive': false, }, } parameters.delete(:Prefix) unless params[:prefix].present? parameters.delete(:Suffix) unless params[:suffix].present? .merge!(basic_auth: @auth, headers: @headers) .merge!(:body => parameters.to_json, :headers => { 'Content-Type' => 'application/json' }) self.class.put(base_api_endpoint("CRM/Constituents/#{constituent_id}"), ) end end |
#update_household(params, current, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tessitura_rest/crm/constituents.rb', line 105 def update_household(params, current, = {}) constituents = current['Affiliates'].map { |c| c['RelatedConstituentId'] } update = [] constituents.each_with_index do |constituent, i| snapshot = get_constituent_snapshot(constituent) parameters = { 'ConstituentType': { 'Id': snapshot['ConstituentType']['Id'], 'Inactive': false, }, 'Id': constituent, 'FirstName': i == 0 ? params[:first_name] : params[:first_name_2], 'UpdatedDateTime': snapshot['UpdatedDateTime'], 'LastName': i == 0 ? params[:last_name] : params[:last_name_2], 'MiddleName': i == 0 ? params[:middle_name] : params[:middle_name_2], 'Prefix': { 'Id': i == 0 ? params[:prefix] : params[:prefix_2], 'Inactive': false, }, 'Suffix': { 'Id': i == 0 ? params[:suffix] : params[:suffix_2], 'Inactive': false, }, 'OriginalSource': { 'Id': snapshot['OriginalSource']['Id'], 'Inactive': false, }, } .merge!(basic_auth: @auth, headers: @headers) .merge!(:body => parameters) update << self.class.put(base_api_endpoint("CRM/Constituents/#{constituent}"), ) end update.last if update.present? end |