Class: ActionNetworkRest::People
- Defined in:
- lib/action_network_rest/people.rb
Instance Method Summary collapse
- #base_path ⇒ Object
- #create(person_data, tags: []) ⇒ Object
- #find_by_email(email) ⇒ Object
- #find_by_phone_number(phone_number) ⇒ Object
- #unsubscribe(id) ⇒ Object
- #update(id, person_data) ⇒ Object
Methods inherited from Base
Instance Method Details
#base_path ⇒ Object
5 6 7 |
# File 'lib/action_network_rest/people.rb', line 5 def base_path 'people/' end |
#create(person_data, tags: []) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/action_network_rest/people.rb', line 9 def create(person_data, tags: []) post_body = { 'person' => person_data } post_body['add_tags'] = if .any? response = client.post_request base_path, post_body object_from_response(response) end |
#find_by_email(email) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/action_network_rest/people.rb', line 23 def find_by_email(email) # This works for parsing exactly 1 person's info out of the response. # The response we get from Action Network is expected to have # # "_embedded": { # "osdi:people": [{ # "identifiers": [ # "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29" # .... # ] # }] # } # url_encoded_filter_string = url_escape("email_address eq '#{email}'") response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}" person_object = response.body[:_embedded][osdi_key].first set_action_network_id_on_object(person_object) if person_object.present? end |
#find_by_phone_number(phone_number) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/action_network_rest/people.rb', line 42 def find_by_phone_number(phone_number) # This works for parsing exactly 1 person's info out of the response. # The response we get from Action Network is expected to have # # "_embedded": { # "osdi:people": [{ # "identifiers": [ # "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29" # .... # ] # }] # } # url_encoded_filter_string = url_escape("phone_number eq '#{phone_number}'") response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}" person_object = response.body[:_embedded][osdi_key].first set_action_network_id_on_object(person_object) if person_object.present? end |
#unsubscribe(id) ⇒ Object
17 18 19 20 21 |
# File 'lib/action_network_rest/people.rb', line 17 def unsubscribe(id) request_body = { email_addresses: [{ status: 'unsubscribed' }] } response = client.put_request "#{base_path}#{url_escape(id)}", request_body object_from_response(response) end |
#update(id, person_data) ⇒ Object
61 62 63 64 65 |
# File 'lib/action_network_rest/people.rb', line 61 def update(id, person_data) people_path = "#{base_path}#{url_escape(id)}" response = client.put_request people_path, person_data object_from_response(response) end |