Module: Addresses

Included in:
TessituraRest
Defined in:
lib/tessitura_rest/crm/addresses.rb

Instance Method Summary collapse

Instance Method Details

#create_address(constituent, address_type, city, postal_code, state, country, street1, street2, primary, options = {}) ⇒ Object



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
# File 'lib/tessitura_rest/crm/addresses.rb', line 14

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,
      '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.to_json)
  response = self.class.post(base_api_endpoint('CRM/Addresses'), options)
  JSON.parse(response.body)
end

#deactivate_address(id, options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tessitura_rest/crm/addresses.rb', line 81

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,
      '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.to_json)
  self.class.put(base_api_endpoint("CRM/Addresses/#{id}"), options)
end

#delete_address(address_id, options = {}) ⇒ Object



114
115
116
117
# File 'lib/tessitura_rest/crm/addresses.rb', line 114

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

#get_address(address_id, options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/tessitura_rest/crm/addresses.rb', line 2

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

#get_all_addresses(constituent_id, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/tessitura_rest/crm/addresses.rb', line 8

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

#update_address(id, address_type, city, postal_code, state, country, street1, street2, primary, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tessitura_rest/crm/addresses.rb', line 46

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,
      '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.to_json)
  response = self.class.put(base_api_endpoint("CRM/Addresses/#{id}"), options)
  JSON.parse(response.body)
end