action_network_rest 0.10.0 → 0.12.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: 37c51a40b6924bf886e768ec83816bbe33d0a9cbd006c995631d5ddf1248b677
4
- data.tar.gz: 0a4506ccdd24760312a0149f4d5e363d99c4a27d21a6b11537ce059f3c637830
3
+ metadata.gz: 4dd1262504cea7929b18b241d18a1559bae11daa1f48cbc3d460726e5e71d091
4
+ data.tar.gz: 413a0c44954cb1e8163a880196f3ef9e05d42fad5d9ddcb3685b55ef6c35426c
5
5
  SHA512:
6
- metadata.gz: e52d89573de10a3963b5f14da3269beb6568a3090bf975c419c6f641a62f090277ec3fcc4d9c22be13f3160ab4d2be7f256b106379339ce8e16f4c8c06b109b4
7
- data.tar.gz: 366ab08d1f91e871414a6b721ca846ab17ecaf87e2ed6c344d144bd8e9004cc6574af5dcdfc95b217aec7a0d17cb02cc50f4d01cc3b86d76e3bd09dc1c2e16cb
6
+ metadata.gz: 34765ac6ce7ace26653131e30d6ddb89cafd8f0757206fb224f82d408e87ba2f960c81a0e90fabc0aaea1fa7d5035a253f83e8587e83b3884a8de8ccd4bededc
7
+ data.tar.gz: 0d229ac881b630f9caa45b2219ff4dc3bb5248f3d57a3b3ae6e975a8758c29be8fec293ee2e6e3e4f93ec7d0717765744a22fe0f51593659e41588b27a333b77
@@ -6,9 +6,9 @@ jobs:
6
6
  runs-on: ubuntu-latest
7
7
  steps:
8
8
  - uses: actions/checkout@v2
9
- - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
9
+ - uses: ruby/setup-ruby@v1
10
10
  with:
11
- ruby-version: 2.7
11
+ ruby-version: 3.1
12
12
  bundler-cache: true
13
13
  - run: bundle install
14
14
  - run: bundle exec rspec
@@ -16,9 +16,9 @@ jobs:
16
16
  runs-on: ubuntu-latest
17
17
  steps:
18
18
  - uses: actions/checkout@v2
19
- - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
19
+ - uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 2.7
21
+ ruby-version: 3.1
22
22
  bundler-cache: true
23
23
  - run: bundle install
24
24
  - run: bundle exec rubocop
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.4
1
+ 3.2.2
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- ```
25
+ ```ruby
26
26
  require 'action_network_rest'
27
27
 
28
28
  client = ActionNetworkRest.new(api_key: YOUR_API_KEY)
@@ -40,6 +40,9 @@ person_id = person.action_network_id
40
40
  # List people
41
41
  people = client.people.list
42
42
 
43
+ # List all people
44
+ people = client.people.all
45
+
43
46
  # Iterate over a list of people
44
47
  page_number = 1
45
48
  loop do
@@ -57,6 +60,11 @@ person = client.people.find_by_email(person_email)
57
60
  person_id = person.action_network_id
58
61
  puts person.email_addresses
59
62
 
63
+ # Retrieve a Person's data by their phone_number
64
+ person = client.people.find_by_phone_number('+12223334444')
65
+ person_id = person.action_network_id
66
+ puts person.phone_numbers
67
+
60
68
  # Update a Person
61
69
  client.people.update(person_id, {custom_fields: {custom_id: "12345"}})
62
70
 
@@ -114,6 +122,38 @@ client.event_campaigns(event_campaign_id).events.list
114
122
  # Add an Attendance
115
123
  event_id = '123e4567-e89b-12d3-a456-426655440000'
116
124
  client.events(event_id).attendances.create({ person: {email_addresses: [{address: 'alice@example.com'}]}})
125
+
126
+ # Get, list, or list all campaigns
127
+ client.campaigns.get('123e4567-e89b-12d3-a456-426614174000')
128
+ client.campaigns.list
129
+ client.campaigns.all
130
+
131
+ # Get, list, list all, create or update Advocacy Campaigns
132
+ client.advocacy_campaigns.list
133
+ client.advocacy_campaigns.all
134
+ client.advocacy_campaigns.create({
135
+ title: "My Free Advocacy Campaign",
136
+ origin_system: "FreeAdvocacy.com",
137
+ type: "email"
138
+ })
139
+ client.advocacy_campaigns.get('123e4567-e89b-12d3-a456-426614174000')
140
+ client.advocacy_campaigns.update('123e4567-e89b-12d3-a456-426614174000', {
141
+ title: "My Free Advocacy Campaign With A New Name",
142
+ description: "This is my free advocacy campaign description"
143
+ })
144
+
145
+ # Get, list, list all, create or update formss
146
+ client.form.list
147
+ client.form.all
148
+ client.form.create({
149
+ title: "My Free Form",
150
+ origin_system: "FreeForm.com"
151
+ })
152
+ client.form.get('123e4567-e89b-12d3-a456-426614174000')
153
+ client.form.update('123e4567-e89b-12d3-a456-426614174000', {
154
+ title: "My Free Form With A New Name",
155
+ description: "This is my free form description"
156
+ })
117
157
  ```
118
158
 
119
159
  ## Development
@@ -23,14 +23,15 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.required_ruby_version = '>= 2.6'
25
25
 
26
- spec.add_runtime_dependency 'vertebrae', '~> 0.6.0'
26
+ spec.add_runtime_dependency 'vertebrae', '< 1'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 2.1'
29
- spec.add_development_dependency 'byebug', '~> 11.1'
29
+ spec.add_development_dependency 'debug', '> 0'
30
30
  spec.add_development_dependency 'dotenv', '~> 2.7'
31
31
  spec.add_development_dependency 'rake', '~> 13.0'
32
32
  spec.add_development_dependency 'rspec', '~> 3.0'
33
- spec.add_development_dependency 'rubocop'
34
- spec.add_development_dependency 'rubocop-performance'
33
+ spec.add_development_dependency 'rubocop', '> 0'
34
+ spec.add_development_dependency 'rubocop-performance', '> 0'
35
35
  spec.add_development_dependency 'webmock', '~> 3.8.3'
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
36
37
  end
data/bin/rake CHANGED
@@ -15,7 +15,7 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
15
15
  bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
18
+ if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
19
19
  load(bundle_binstub)
20
20
  else
21
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
data/bin/rspec CHANGED
@@ -15,7 +15,7 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
15
15
  bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
18
+ if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
19
19
  load(bundle_binstub)
20
20
  else
21
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
data/example.rb CHANGED
@@ -7,7 +7,7 @@ require 'byebug'
7
7
  Dotenv.load('.env')
8
8
  raise 'Must set API_KEY environmental variable. See .env.sample for details' if ENV['API_KEY'].nil?
9
9
 
10
- client = ActionNetworkRest.new(api_key: ENV['API_KEY']) # rubocop:disable Lint/UselessAssignment
10
+ client = ActionNetworkRest.new(api_key: ENV.fetch('API_KEY')) # rubocop:disable Lint/UselessAssignment
11
11
 
12
12
  puts "Ready to call Action Network API using 'client' object"
13
13
  byebug # rubocop:disable Lint/Debugger
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionNetworkRest
4
+ class AdvocacyCampaigns < Base
5
+ def initialize(client:)
6
+ super(client: client)
7
+ end
8
+
9
+ def base_path
10
+ 'advocacy_campaigns/'
11
+ end
12
+
13
+ def create(advocacy_campaign_data)
14
+ post_body = advocacy_campaign_data
15
+ puts base_path
16
+ response = client.post_request(base_path, post_body)
17
+ object_from_response(response, action_network_id_required: true)
18
+ end
19
+
20
+ def update(advocacy_campaign_id, advocacy_campaign_data)
21
+ put_body = advocacy_campaign_data
22
+
23
+ response = client.put_request("#{base_path}#{advocacy_campaign_id}", put_body)
24
+ object_from_response(response, action_network_id_required: true)
25
+ end
26
+
27
+ private
28
+
29
+ def osdi_key
30
+ 'osdi:advocacy_campaigns'
31
+ end
32
+ end
33
+ end
@@ -17,6 +17,49 @@ module ActionNetworkRest
17
17
  objects
18
18
  end
19
19
 
20
+ def all
21
+ min_wait = 0.25 # sec to wait between calls
22
+ timestamp = Time.now.to_r # secs since Unix Epoch
23
+ page_number = 1
24
+ tries = 0
25
+ all = []
26
+ loop do
27
+ # Limit rate before request to avoid error
28
+ wait = min_wait * (1.5**tries)
29
+ new_time = Time.now.to_r
30
+ if (timestamp + min_wait - new_time).positive?
31
+ sleep(wait) # Wait if calling again could exceed the rate limit
32
+ tries += 1
33
+ next # check again
34
+ end
35
+
36
+ begin
37
+ page = list(page: page_number)
38
+ rescue ActionNetworkRest::Response::TooManyRequests
39
+ if tries >= 10
40
+ raise ActionNetworkRest::Response::UsedAllRequestTries,
41
+ {
42
+ tries: tries,
43
+ last_wait_length: wait,
44
+ resource: base_path
45
+ }.to_json
46
+ end
47
+
48
+ sleep(wait)
49
+ tries += 1 # Exponential back off if got Too Many Requests error response
50
+ next
51
+ end
52
+ timestamp = Time.now.to_r
53
+
54
+ break if page.empty?
55
+
56
+ all.concat(page)
57
+ page_number += 1
58
+ tries = 0
59
+ end
60
+ all
61
+ end
62
+
20
63
  private
21
64
 
22
65
  def url_escape(string)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionNetworkRest
4
+ class Campaigns < Base
5
+ attr_accessor :campaign_id
6
+
7
+ def initialize(client:)
8
+ super(client: client)
9
+ end
10
+
11
+ def base_path
12
+ 'campaigns/'
13
+ end
14
+
15
+ private
16
+
17
+ def osdi_key
18
+ 'action_network:campaigns'
19
+ end
20
+ end
21
+ end
@@ -25,6 +25,14 @@ module ActionNetworkRest
25
25
 
26
26
  ## Helpers to let users do things like `an_client.people.create(params)`
27
27
 
28
+ def advocacy_campaigns
29
+ @_advocacy_campaigns ||= ActionNetworkRest::AdvocacyCampaigns.new(client: self)
30
+ end
31
+
32
+ def campaigns
33
+ @_campaigns ||= ActionNetworkRest::Campaigns.new(client: self)
34
+ end
35
+
28
36
  def events(event_id = nil)
29
37
  if @_events&.send(:[], event_id).nil?
30
38
  @_events = {} if @_events.nil?
@@ -49,6 +57,10 @@ module ActionNetworkRest
49
57
  @_entry_point ||= ActionNetworkRest::EntryPoint.new(client: self)
50
58
  end
51
59
 
60
+ def forms
61
+ @_forms ||= ActionNetworkRest::Forms.new(client: self)
62
+ end
63
+
52
64
  def people
53
65
  @_people ||= ActionNetworkRest::People.new(client: self)
54
66
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionNetworkRest
4
+ class Forms < Base
5
+ def initialize(client:)
6
+ super(client: client)
7
+ end
8
+
9
+ def base_path
10
+ 'forms/'
11
+ end
12
+
13
+ def create(form_data)
14
+ post_data = form_data
15
+
16
+ response = client.post_request(base_path, post_data)
17
+ object_from_response(response, action_network_id_required: true)
18
+ end
19
+
20
+ def update(form_id, form_data)
21
+ put_data = form_data
22
+
23
+ response = client.put_request("#{base_path}#{form_id}", put_data)
24
+ object_from_response(response, action_network_id_required: true)
25
+ end
26
+
27
+ private
28
+
29
+ def osdi_key
30
+ 'osdi:forms'
31
+ end
32
+ end
33
+ end
@@ -39,6 +39,25 @@ module ActionNetworkRest
39
39
  set_action_network_id_on_object(person_object) if person_object.present?
40
40
  end
41
41
 
42
+ def find_by_phone_number(phone_number)
43
+ # This works for parsing exactly 1 person's info out of the response.
44
+ # The response we get from Action Network is expected to have
45
+ #
46
+ # "_embedded": {
47
+ # "osdi:people": [{
48
+ # "identifiers": [
49
+ # "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29"
50
+ # ....
51
+ # ]
52
+ # }]
53
+ # }
54
+ #
55
+ url_encoded_filter_string = url_escape("phone_number eq '#{phone_number}'")
56
+ response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
57
+ person_object = response.body[:_embedded][osdi_key].first
58
+ set_action_network_id_on_object(person_object) if person_object.present?
59
+ end
60
+
42
61
  def update(id, person_data)
43
62
  people_path = "#{base_path}#{url_escape(id)}"
44
63
  response = client.put_request people_path, person_data
@@ -17,6 +17,8 @@ module ActionNetworkRest
17
17
  end
18
18
  elsif status_code == 404
19
19
  raise NotFoundError, error_message(response)
20
+ elsif status_code == 429
21
+ raise TooManyRequests, error_message(response)
20
22
  else
21
23
  raise ResponseError, error_message(response)
22
24
  end
@@ -36,5 +38,9 @@ module ActionNetworkRest
36
38
  class NotFoundError < StandardError; end
37
39
 
38
40
  class ResponseError < StandardError; end
41
+
42
+ class TooManyRequests < StandardError; end
43
+
44
+ class UsedAllRequestTries < StandardError; end
39
45
  end
40
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionNetworkRest
4
- VERSION = '0.10.0'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -18,10 +18,13 @@ require 'action_network_rest/response/raise_error'
18
18
  require 'action_network_rest/client'
19
19
  require 'action_network_rest/base'
20
20
 
21
+ require 'action_network_rest/advocacy_campaigns'
21
22
  require 'action_network_rest/attendances'
23
+ require 'action_network_rest/campaigns'
22
24
  require 'action_network_rest/entry_point'
23
25
  require 'action_network_rest/events'
24
26
  require 'action_network_rest/event_campaigns'
27
+ require 'action_network_rest/forms'
25
28
  require 'action_network_rest/people'
26
29
  require 'action_network_rest/petitions'
27
30
  require 'action_network_rest/signatures'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_network_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-04 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: byebug
42
+ name: debug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
- version: '11.1'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
- version: '11.1'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dotenv
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,28 +98,28 @@ dependencies:
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - ">"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - ">"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-performance
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - ">"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - ">"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
@@ -160,13 +160,16 @@ files:
160
160
  - bin/rspec
161
161
  - example.rb
162
162
  - lib/action_network_rest.rb
163
+ - lib/action_network_rest/advocacy_campaigns.rb
163
164
  - lib/action_network_rest/api.rb
164
165
  - lib/action_network_rest/attendances.rb
165
166
  - lib/action_network_rest/base.rb
167
+ - lib/action_network_rest/campaigns.rb
166
168
  - lib/action_network_rest/client.rb
167
169
  - lib/action_network_rest/entry_point.rb
168
170
  - lib/action_network_rest/event_campaigns.rb
169
171
  - lib/action_network_rest/events.rb
172
+ - lib/action_network_rest/forms.rb
170
173
  - lib/action_network_rest/people.rb
171
174
  - lib/action_network_rest/petitions.rb
172
175
  - lib/action_network_rest/response/raise_error.rb
@@ -177,7 +180,8 @@ files:
177
180
  homepage: https://github.com/controlshift/action-network-rest
178
181
  licenses:
179
182
  - MIT
180
- metadata: {}
183
+ metadata:
184
+ rubygems_mfa_required: 'true'
181
185
  post_install_message:
182
186
  rdoc_options: []
183
187
  require_paths:
@@ -193,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
197
  - !ruby/object:Gem::Version
194
198
  version: '0'
195
199
  requirements: []
196
- rubygems_version: 3.1.6
200
+ rubygems_version: 3.3.19
197
201
  signing_key:
198
202
  specification_version: 4
199
203
  summary: Ruby client for interacting with the ActionNetwork REST API