action_network_rest 0.10.0 → 0.11.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: 60ec6a3895471c7d3a0f2a45076fc79e085a215ab5615be1db0f665ad6503106
4
+ data.tar.gz: 940276b2e72e63794de66a46d06c549126a446de28f79dc8a8ba5440fd7d4657
5
5
  SHA512:
6
- metadata.gz: e52d89573de10a3963b5f14da3269beb6568a3090bf975c419c6f641a62f090277ec3fcc4d9c22be13f3160ab4d2be7f256b106379339ce8e16f4c8c06b109b4
7
- data.tar.gz: 366ab08d1f91e871414a6b721ca846ab17ecaf87e2ed6c344d144bd8e9004cc6574af5dcdfc95b217aec7a0d17cb02cc50f4d01cc3b86d76e3bd09dc1c2e16cb
6
+ metadata.gz: 13a5c4e166e1d6a83c637a7ff70ef0bec3e105d647bf484fd35bd296b11787812fcf6cb7a2d73ad55a60aea7adba1ebb3083170208db3c8132aa94890982f5ba
7
+ data.tar.gz: 6436d185b7311fd1dae2c9663f178886a0d1cc9ab5a5fcf956ff001acc1154e5e8ecc0cf978dc441470effc00ce4c01bb919185929036a7dcf7fc93aba041fce
@@ -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.1.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
@@ -114,6 +117,38 @@ client.event_campaigns(event_campaign_id).events.list
114
117
  # Add an Attendance
115
118
  event_id = '123e4567-e89b-12d3-a456-426655440000'
116
119
  client.events(event_id).attendances.create({ person: {email_addresses: [{address: 'alice@example.com'}]}})
120
+
121
+ # Get, list, or list all campaigns
122
+ client.campaigns.get('123e4567-e89b-12d3-a456-426614174000')
123
+ client.campaigns.list
124
+ client.campaigns.all
125
+
126
+ # Get, list, list all, create or update Advocacy Campaigns
127
+ client.advocacy_campaigns.list
128
+ client.advocacy_campaigns.all
129
+ client.advocacy_campaigns.create({
130
+ title: "My Free Advocacy Campaign",
131
+ origin_system: "FreeAdvocacy.com",
132
+ type: "email"
133
+ })
134
+ client.advocacy_campaigns.get('123e4567-e89b-12d3-a456-426614174000')
135
+ client.advocacy_campaigns.update('123e4567-e89b-12d3-a456-426614174000', {
136
+ title: "My Free Advocacy Campaign With A New Name",
137
+ description: "This is my free advocacy campaign description"
138
+ })
139
+
140
+ # Get, list, list all, create or update formss
141
+ client.form.list
142
+ client.form.all
143
+ client.form.create({
144
+ title: "My Free Form",
145
+ origin_system: "FreeForm.com"
146
+ })
147
+ client.form.get('123e4567-e89b-12d3-a456-426614174000')
148
+ client.form.update('123e4567-e89b-12d3-a456-426614174000', {
149
+ title: "My Free Form With A New Name",
150
+ description: "This is my free form description"
151
+ })
117
152
  ```
118
153
 
119
154
  ## Development
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rubocop'
34
34
  spec.add_development_dependency 'rubocop-performance'
35
35
  spec.add_development_dependency 'webmock', '~> 3.8.3'
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
36
37
  end
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 excede 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 reponse
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
@@ -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.11.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,14 +1,14 @@
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.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-04 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 3.8.3
139
- description:
139
+ description:
140
140
  email:
141
141
  - grey@controlshiftlabs.com
142
142
  executables: []
@@ -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,8 +180,9 @@ files:
177
180
  homepage: https://github.com/controlshift/action-network-rest
178
181
  licenses:
179
182
  - MIT
180
- metadata: {}
181
- post_install_message:
183
+ metadata:
184
+ rubygems_mfa_required: 'true'
185
+ post_install_message:
182
186
  rdoc_options: []
183
187
  require_paths:
184
188
  - lib
@@ -193,8 +197,8 @@ 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
197
- signing_key:
200
+ rubygems_version: 3.3.19
201
+ signing_key:
198
202
  specification_version: 4
199
203
  summary: Ruby client for interacting with the ActionNetwork REST API
200
204
  test_files: []