module Addresses def get_address(address_id, options = {}) options.merge!(basic_auth: @auth, headers: @headers) response = self.class.get(base_api_endpoint("CRM/Addresses/#{address_id}"), options) JSON.parse(response.body) end def get_all_addresses(constituent_id, options = {}) options.merge!(basic_auth: @auth, headers: @headers) response = self.class.get(base_api_endpoint("CRM/Addresses?constituentId=#{constituent_id}"), options) JSON.parse(response.body) end def create_address(constituent, address_type, city, postal_code, state, country, street1, street2, primary, options = {}) parameters = { 'AddressType': { 'Id': address_type, }, 'City': city, 'Constituent': { 'Id': constituent, }, 'Inactive': false, 'Label': true, 'Months': 'YYYYYYYYYYYY', 'PostalCode': postal_code, 'PrimaryIndicator': primary, 'State': { 'Id': state, 'Country': { 'Id': country, }, }, 'Street1': street1, 'Street2': street2, 'Country': { 'Id': country, }, } options.merge!(basic_auth: @auth, headers: @headers) options.merge!(:body => parameters) response = self.class.post(base_api_endpoint('CRM/Addresses'), options) JSON.parse(response.body) end def update_address(id, address_type, city, postal_code, state, country, street1, street2, primary, options = {}) current = get_address(id) parameters = { 'Id': id, 'UpdatedDateTime': current['UpdatedDateTime'], 'AddressType': { 'Id': address_type, }, 'City': city, 'Constituent': { 'Id': current['Constituent']['Id'], }, 'Inactive': false, 'Label': true, 'Months': 'YYYYYYYYYYYY', 'PostalCode': postal_code, 'PrimaryIndicator': primary, 'State': { 'Id': state, 'Country': { 'Id': country, }, }, 'Street1': street1, 'Street2': street2, 'Country': { 'Id': country, }, } options.merge!(basic_auth: @auth, headers: @headers) options.merge!(:body => parameters) response = self.class.put(base_api_endpoint("CRM/Addresses/#{id}"), options) JSON.parse(response.body) end def deactivate_address(id, options = {}) current = get_address(id) parameters = { 'Id': id, 'UpdatedDateTime': current['UpdatedDateTime'], 'AddressType': { 'Id': current['AddressType']['Id'], }, 'City': current['City'], 'Constituent': { 'Id': current['Constituent']['Id'], }, 'Inactive': true, 'Label': true, 'Months': 'YYYYYYYYYYYY', 'PostalCode': current['PostalCode'], 'State': { 'Id': current['State']['Id'], 'Country': { 'Id': current['Country']['Id'], }, }, 'Street1': current['Street1'], 'Street2': current['Street2'], 'Country': { 'Id': current['Country']['Id'], }, } options.merge!(basic_auth: @auth, headers: @headers) options.merge!(:body => parameters) self.class.put(base_api_endpoint("CRM/Addresses/#{id}"), options) end def delete_address(address_id, options = {}) options.merge!(basic_auth: @auth, headers: @headers) self.class.delete(base_api_endpoint("CRM/Addresses/#{address_id}"), options) end end