action_network_rest 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ac436fdf54dc3a69ce38d4a38cb2f3b40db35083d20a5817db63e4546da610
4
- data.tar.gz: a61e130172cf21c309000c632b6b57230c5d88fb18213c0c3c5961cc697e74de
3
+ metadata.gz: abb5c663b923a0f30bfcaf0b70fd43de40baf9f59752154eaead286acf7259a7
4
+ data.tar.gz: dbd808c9166b1047c70d87df247a5d624851f1e69a4271da6edb70ca578a9161
5
5
  SHA512:
6
- metadata.gz: 3a5bd5ea4d0f915429a85f7c01380642c0a390bf2d011cfa507b01f094572deab777184b2d11e58ba7cc118253cd9e042e0c005936e9255cfb7fade3bbe6019b
7
- data.tar.gz: 1f73b9a22ca1cc3328331435cdcdcc25dfffe8d1dc85e053dd0a79df14f36343374dfc4daeac812c3949bb6c2f10998487ada99df81d16e349fb39cb2f6a6c98
6
+ metadata.gz: 71b0865b95a6d0ac618f6d9a35379b9998391c05dee7714c5b12dc0c8215e2ade7163cd8d2e81b3bd1a5d4743d6599207c22d48b22a7a5f9e724ccbc99ebe907
7
+ data.tar.gz: afac667e373e1ce51641edd1cde82d4269220ef95b847cc589fd9ffa079419e559f42c677210a87a91888e978a40ac07c5199179e684923f2feebc8c032849a8
data/README.md CHANGED
@@ -35,6 +35,17 @@ client.entry_point.get
35
35
  person = client.people.create(email_addresses: [{address: 'foo@example.com'}])
36
36
  person_id = person.action_network_id
37
37
 
38
+ # List people
39
+ people = client.people.list
40
+
41
+ # Iterate over a list of people
42
+ page_number = 1
43
+ loop do
44
+ people = client.people.list(page: page_number)
45
+ break if people.empty?
46
+ page_number += 1
47
+ end
48
+
38
49
  # Retrieve a Person's data
39
50
  person = client.people.get(person_id)
40
51
  puts person.email_addresses
@@ -78,6 +89,9 @@ tag_id = tag.action_network_id
78
89
  # Retrieve a Tag
79
90
  tag = client.tags.get(tag_id)
80
91
 
92
+ # Retrieve a Tag by name
93
+ tag = client.tags.find_by_name('Volunteers')
94
+
81
95
  # Apply a Tag to a Person
82
96
  tagging = client.tags(tag_id).create({identifiers: ['external:123']}, person_id: person_id)
83
97
  tagging_id = tagging.action_network_id
@@ -5,13 +5,23 @@ module ActionNetworkRest
5
5
  object_from_response(response)
6
6
  end
7
7
 
8
+ def list(page: 1)
9
+ response = client.get_request "#{base_path}?page=#{page}"
10
+ objects = response.body.dig('_embedded', osdi_key)
11
+ return [] if objects.nil?
12
+
13
+ objects.each { |obj| set_action_network_id_on_object(obj) }
14
+
15
+ objects
16
+ end
17
+
8
18
  private
9
19
 
10
20
  def url_escape(string)
11
21
  CGI.escape(string.to_s)
12
22
  end
13
23
 
14
- def object_with_action_network_id(obj)
24
+ def set_action_network_id_on_object(obj)
15
25
  # Takes an object which may contain an `identifiers` key, which may contain an action_network identifier
16
26
  # If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
17
27
  # for the convenience of callers using the returned object.
@@ -33,7 +43,7 @@ module ActionNetworkRest
33
43
 
34
44
  def object_from_response(response)
35
45
  obj = response.body
36
- object_with_action_network_id(obj)
46
+ set_action_network_id_on_object(obj)
37
47
  end
38
48
 
39
49
  def action_network_url(path)
@@ -35,10 +35,16 @@ module ActionNetworkRest
35
35
  #
36
36
  url_encoded_filter_string = url_escape("email_address eq '#{email}'")
37
37
  response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
38
- person_object = response.body[:_embedded]['osdi:people'].first
38
+ person_object = response.body[:_embedded][osdi_key].first
39
39
  if person_object.present?
40
- object_with_action_network_id(person_object)
40
+ set_action_network_id_on_object(person_object)
41
41
  end
42
42
  end
43
+
44
+ private
45
+
46
+ def osdi_key
47
+ 'osdi:people'
48
+ end
43
49
  end
44
50
  end
@@ -33,5 +33,11 @@ module ActionNetworkRest
33
33
  response = client.put_request petition_path, petition_data
34
34
  object_from_response(response)
35
35
  end
36
+
37
+ private
38
+
39
+ def osdi_key
40
+ 'osdi:petitions'
41
+ end
36
42
  end
37
43
  end
@@ -20,5 +20,11 @@ module ActionNetworkRest
20
20
  response = client.put_request "#{base_path}#{url_escape(id)}", signature_data
21
21
  object_from_response(response)
22
22
  end
23
+
24
+ private
25
+
26
+ def osdi_key
27
+ 'osdi:signatures'
28
+ end
23
29
  end
24
30
  end
@@ -19,5 +19,11 @@ module ActionNetworkRest
19
19
  response = client.delete_request "#{base_path}#{url_escape(id)}"
20
20
  object_from_response(response)
21
21
  end
22
+
23
+ private
24
+
25
+ def osdi_key
26
+ 'osdi:taggings'
27
+ end
22
28
  end
23
29
  end
@@ -22,5 +22,27 @@ module ActionNetworkRest
22
22
  response = client.post_request base_path, post_body
23
23
  object_from_response(response)
24
24
  end
25
+
26
+ def find_by_name(name)
27
+ # Action Network API doesn't support currently OData querying for tags
28
+ # (https://actionnetwork.org/docs/v2#odata) so we need to retrieve a list of
29
+ # all tags and iterate to find the one we're looking for.
30
+ page = 1
31
+ loop do
32
+ tags = self.list(page: page)
33
+ return nil if tags.empty?
34
+
35
+ found_tag = tags.find { |t| t.name == name }
36
+ return found_tag unless found_tag.nil?
37
+
38
+ page += 1
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def osdi_key
45
+ 'osdi:tags'
46
+ end
25
47
  end
26
48
  end
@@ -1,3 +1,3 @@
1
1
  module ActionNetworkRest
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_network_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []
177
- rubygems_version: 3.0.3
177
+ rubygems_version: 3.0.8
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Ruby client for interacting with the ActionNetwork REST API