action_network_rest 0.10.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -4
- data/.ruby-version +1 -1
- data/README.md +36 -1
- data/action_network_rest.gemspec +3 -2
- data/example.rb +1 -1
- data/lib/action_network_rest/advocacy_campaigns.rb +33 -0
- data/lib/action_network_rest/api.rb +7 -9
- data/lib/action_network_rest/base.rb +43 -0
- data/lib/action_network_rest/campaigns.rb +21 -0
- data/lib/action_network_rest/client.rb +12 -0
- data/lib/action_network_rest/forms.rb +33 -0
- data/lib/action_network_rest/response/raise_error.rb +9 -1
- data/lib/action_network_rest/version.rb +1 -1
- data/lib/action_network_rest.rb +3 -0
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e65f3bb81f2d96f6387f07f7eb28ac79cc851c5552ef2f8c8925bec3ae44c192
|
4
|
+
data.tar.gz: a49f69fe3f7c43e5f7eb5102529943a4dca20c1a69b22baa8c916829a4b85c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2562c647add336113f29e9ab423484c46db0a4e678d7b665d7b556229aa206af28cb652eedde6278b3f4b6cebd908fe17b3af3c41673cba8c3c3cfd6d120980b
|
7
|
+
data.tar.gz: f1c8324c8cbe351074c43c7c8ea0de6e30de049c73abe3afbecd9b77b8b2865b684a11d7232e0a8f9f10c8df4d2cc6cbcd2712b8a2a8ad2061a9340d5aeb76e7
|
data/.github/workflows/ci.yml
CHANGED
@@ -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@
|
9
|
+
- uses: ruby/setup-ruby@v1
|
10
10
|
with:
|
11
|
-
ruby-version:
|
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@
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version:
|
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.
|
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
|
@@ -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
|
data/action_network_rest.gemspec
CHANGED
@@ -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', '
|
26
|
+
spec.add_runtime_dependency 'vertebrae', '>= 1.0.0'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
29
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'debug'
|
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
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
|
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
|
@@ -3,17 +3,15 @@
|
|
3
3
|
module ActionNetworkRest
|
4
4
|
class API < Vertebrae::API
|
5
5
|
def setup
|
6
|
-
connection.
|
7
|
-
|
8
|
-
|
6
|
+
connection.faraday_connection = Faraday.new(connection.configuration.faraday_options) do |f|
|
7
|
+
f.request :multipart
|
8
|
+
f.request :url_encoded
|
9
9
|
|
10
|
-
|
10
|
+
f.response :mashify
|
11
|
+
f.response :json
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
builder.use ActionNetworkRest::Response::RaiseError
|
16
|
-
builder.adapter connection.configuration.adapter
|
13
|
+
f.response :actionnetwork_raise_error
|
14
|
+
f.adapter connection.configuration.adapter
|
17
15
|
end
|
18
16
|
end
|
19
17
|
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
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module ActionNetworkRest
|
4
4
|
module Response
|
5
|
-
class RaiseError < Faraday::
|
5
|
+
class RaiseError < Faraday::Middleware
|
6
6
|
# rubocop:disable Style/GuardClause
|
7
7
|
def on_complete(response)
|
8
8
|
status_code = response[:status].to_i
|
@@ -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,11 @@ 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
|
47
|
+
|
48
|
+
Faraday::Response.register_middleware actionnetwork_raise_error: -> { ActionNetworkRest::Response::RaiseError }
|
data/lib/action_network_rest.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.0.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:
|
11
|
+
date: 2023-05-10 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.
|
19
|
+
version: 1.0.0
|
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.
|
26
|
+
version: 1.0.0
|
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:
|
42
|
+
name: debug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dotenv
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
200
|
+
rubygems_version: 3.4.10
|
197
201
|
signing_key:
|
198
202
|
specification_version: 4
|
199
203
|
summary: Ruby client for interacting with the ActionNetwork REST API
|