action_network_rest 0.9.0 → 0.11.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 +1 -0
- data/example.rb +1 -1
- data/lib/action_network_rest/advocacy_campaigns.rb +33 -0
- data/lib/action_network_rest/base.rb +48 -3
- data/lib/action_network_rest/campaigns.rb +21 -0
- data/lib/action_network_rest/client.rb +12 -0
- data/lib/action_network_rest/events.rb +1 -1
- data/lib/action_network_rest/forms.rb +33 -0
- data/lib/action_network_rest/response/raise_error.rb +8 -0
- data/lib/action_network_rest/version.rb +1 -1
- data/lib/action_network_rest.rb +3 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ec6a3895471c7d3a0f2a45076fc79e085a215ab5615be1db0f665ad6503106
|
4
|
+
data.tar.gz: 940276b2e72e63794de66a46d06c549126a446de28f79dc8a8ba5440fd7d4657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a5c4e166e1d6a83c637a7ff70ef0bec3e105d647bf484fd35bd296b11787812fcf6cb7a2d73ad55a60aea7adba1ebb3083170208db3c8132aa94890982f5ba
|
7
|
+
data.tar.gz: 6436d185b7311fd1dae2c9663f178886a0d1cc9ab5a5fcf956ff001acc1154e5e8ecc0cf978dc441470effc00ce4c01bb919185929036a7dcf7fc93aba041fce
|
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
|
-
|
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
|
data/action_network_rest.gemspec
CHANGED
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
|
@@ -17,13 +17,56 @@ 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)
|
23
66
|
CGI.escape(string.to_s)
|
24
67
|
end
|
25
68
|
|
26
|
-
def set_action_network_id_on_object(obj)
|
69
|
+
def set_action_network_id_on_object(obj, action_network_id_required: false)
|
27
70
|
# Takes an object which may contain an `identifiers` key, which may contain an action_network identifier
|
28
71
|
# If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
|
29
72
|
# for the convenience of callers using the returned object.
|
@@ -38,14 +81,16 @@ module ActionNetworkRest
|
|
38
81
|
end
|
39
82
|
if qualified_actionnetwork_id.present?
|
40
83
|
obj.action_network_id = qualified_actionnetwork_id.sub(/^action_network:/, '')
|
84
|
+
elsif action_network_id_required
|
85
|
+
raise ActionNetworkRest::Response::MissingActionNetworkId, obj.inspect
|
41
86
|
end
|
42
87
|
|
43
88
|
obj
|
44
89
|
end
|
45
90
|
|
46
|
-
def object_from_response(response)
|
91
|
+
def object_from_response(response, action_network_id_required: false)
|
47
92
|
obj = response.body
|
48
|
-
set_action_network_id_on_object(obj)
|
93
|
+
set_action_network_id_on_object(obj, action_network_id_required: action_network_id_required)
|
49
94
|
end
|
50
95
|
|
51
96
|
def action_network_url(path)
|
@@ -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
|
@@ -29,10 +31,16 @@ module ActionNetworkRest
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
class MissingActionNetworkId < StandardError; end
|
35
|
+
|
32
36
|
class MustSpecifyValidPersonId < StandardError; end
|
33
37
|
|
34
38
|
class NotFoundError < StandardError; end
|
35
39
|
|
36
40
|
class ResponseError < StandardError; end
|
41
|
+
|
42
|
+
class TooManyRequests < StandardError; end
|
43
|
+
|
44
|
+
class UsedAllRequestTries < StandardError; end
|
37
45
|
end
|
38
46
|
end
|
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,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.
|
4
|
+
version: 0.11.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: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vertebrae
|
@@ -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.3.19
|
197
201
|
signing_key:
|
198
202
|
specification_version: 4
|
199
203
|
summary: Ruby client for interacting with the ActionNetwork REST API
|