action_network_rest 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +24 -0
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/README.md +1 -1
- data/lib/action_network_rest/api.rb +20 -0
- data/lib/action_network_rest/attendances.rb +11 -1
- data/lib/action_network_rest/base.rb +5 -3
- data/lib/action_network_rest/client.rb +1 -1
- data/lib/action_network_rest/event_campaigns.rb +6 -0
- data/lib/action_network_rest/events.rb +1 -1
- data/lib/action_network_rest/response/raise_error.rb +40 -0
- data/lib/action_network_rest/signatures.rb +11 -1
- data/lib/action_network_rest/version.rb +1 -1
- data/lib/action_network_rest.rb +2 -0
- metadata +9 -7
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37c51a40b6924bf886e768ec83816bbe33d0a9cbd006c995631d5ddf1248b677
|
4
|
+
data.tar.gz: 0a4506ccdd24760312a0149f4d5e363d99c4a27d21a6b11537ce059f3c637830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52d89573de10a3963b5f14da3269beb6568a3090bf975c419c6f641a62f090277ec3fcc4d9c22be13f3160ab4d2be7f256b106379339ce8e16f4c8c06b109b4
|
7
|
+
data.tar.gz: 366ab08d1f91e871414a6b721ca846ab17ecaf87e2ed6c344d144bd8e9004cc6574af5dcdfc95b217aec7a0d17cb02cc50f4d01cc3b86d76e3bd09dc1c2e16cb
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@v2
|
9
|
+
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
|
10
|
+
with:
|
11
|
+
ruby-version: 2.7
|
12
|
+
bundler-cache: true
|
13
|
+
- run: bundle install
|
14
|
+
- run: bundle exec rspec
|
15
|
+
rubocop:
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
|
20
|
+
with:
|
21
|
+
ruby-version: 2.7
|
22
|
+
bundler-cache: true
|
23
|
+
- run: bundle install
|
24
|
+
- run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -4,8 +4,12 @@ require:
|
|
4
4
|
AllCops:
|
5
5
|
NewCops: enable
|
6
6
|
TargetRubyVersion: 2.6
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
7
9
|
Metrics/BlockLength:
|
8
10
|
Enabled: false
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Enabled: false
|
9
13
|
Naming/AccessorMethodName:
|
10
14
|
Enabled: false
|
11
15
|
Naming/MemoizedInstanceVariableName:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.4
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Ruby client for interacting with the [ActionNetwork REST API](https://actionnetwork.org/docs/) from the engineering team at [ControlShift](https://www.controlshiftlabs.com/).
|
4
4
|
|
5
|
-
[](https://github.com/controlshift/action-network-rest/actions/workflows/ci.yml)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionNetworkRest
|
4
|
+
class API < Vertebrae::API
|
5
|
+
def setup
|
6
|
+
connection.stack do |builder|
|
7
|
+
builder.use Faraday::Request::Multipart
|
8
|
+
builder.use Faraday::Request::UrlEncoded
|
9
|
+
|
10
|
+
builder.use Faraday::Response::Logger if ENV['DEBUG']
|
11
|
+
|
12
|
+
builder.use FaradayMiddleware::Mashify
|
13
|
+
builder.use FaradayMiddleware::ParseJson
|
14
|
+
|
15
|
+
builder.use ActionNetworkRest::Response::RaiseError
|
16
|
+
builder.adapter connection.configuration.adapter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module ActionNetworkRest
|
4
4
|
class Attendances < Base
|
5
|
+
class CreateError < StandardError; end
|
6
|
+
|
5
7
|
attr_accessor :event_campaign_id, :event_id
|
6
8
|
|
7
9
|
def base_path
|
@@ -14,7 +16,15 @@ module ActionNetworkRest
|
|
14
16
|
|
15
17
|
def create(attendance_data)
|
16
18
|
response = client.post_request base_path, attendance_data
|
17
|
-
object_from_response(response)
|
19
|
+
new_attendance = object_from_response(response)
|
20
|
+
|
21
|
+
# Action Network treats the attendance create helper endpoint as an unauthenticated
|
22
|
+
# "blind" POST (see https://actionnetwork.org/docs/v2/unauthenticated-post/). For this
|
23
|
+
# reason they don't return a status code with error to avoid leaking private data. Instead
|
24
|
+
# they return 200 OK with an empty body (vs. the newly created attendance's data for successful calls)
|
25
|
+
raise CreateError if new_attendance.empty?
|
26
|
+
|
27
|
+
new_attendance
|
18
28
|
end
|
19
29
|
|
20
30
|
def update(id, attendance_data)
|
@@ -23,7 +23,7 @@ module ActionNetworkRest
|
|
23
23
|
CGI.escape(string.to_s)
|
24
24
|
end
|
25
25
|
|
26
|
-
def set_action_network_id_on_object(obj)
|
26
|
+
def set_action_network_id_on_object(obj, action_network_id_required: false)
|
27
27
|
# Takes an object which may contain an `identifiers` key, which may contain an action_network identifier
|
28
28
|
# If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
|
29
29
|
# for the convenience of callers using the returned object.
|
@@ -38,14 +38,16 @@ module ActionNetworkRest
|
|
38
38
|
end
|
39
39
|
if qualified_actionnetwork_id.present?
|
40
40
|
obj.action_network_id = qualified_actionnetwork_id.sub(/^action_network:/, '')
|
41
|
+
elsif action_network_id_required
|
42
|
+
raise ActionNetworkRest::Response::MissingActionNetworkId, obj.inspect
|
41
43
|
end
|
42
44
|
|
43
45
|
obj
|
44
46
|
end
|
45
47
|
|
46
|
-
def object_from_response(response)
|
48
|
+
def object_from_response(response, action_network_id_required: false)
|
47
49
|
obj = response.body
|
48
|
-
set_action_network_id_on_object(obj)
|
50
|
+
set_action_network_id_on_object(obj, action_network_id_required: action_network_id_required)
|
49
51
|
end
|
50
52
|
|
51
53
|
def action_network_url(path)
|
@@ -20,6 +20,12 @@ module ActionNetworkRest
|
|
20
20
|
object_from_response(response)
|
21
21
|
end
|
22
22
|
|
23
|
+
def update(id, event_campaign_data)
|
24
|
+
event_campaign_path = "#{base_path}#{url_escape(id)}"
|
25
|
+
response = client.put_request event_campaign_path, event_campaign_data
|
26
|
+
object_from_response(response)
|
27
|
+
end
|
28
|
+
|
23
29
|
def events(event_id = nil)
|
24
30
|
@_events ||= ActionNetworkRest::Events.new(event_campaign_id: event_campaign_id, event_id: event_id,
|
25
31
|
client: client)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionNetworkRest
|
4
|
+
module Response
|
5
|
+
class RaiseError < Faraday::Response::Middleware
|
6
|
+
# rubocop:disable Style/GuardClause
|
7
|
+
def on_complete(response)
|
8
|
+
status_code = response[:status].to_i
|
9
|
+
|
10
|
+
if (400...600).cover? status_code
|
11
|
+
if status_code == 400 && response[:body].include?('error')
|
12
|
+
error_hsh = JSON.parse(response[:body])
|
13
|
+
error_message = error_hsh['error']
|
14
|
+
|
15
|
+
if error_message == 'You must specify a valid person id'
|
16
|
+
raise MustSpecifyValidPersonId, error_message(response)
|
17
|
+
end
|
18
|
+
elsif status_code == 404
|
19
|
+
raise NotFoundError, error_message(response)
|
20
|
+
else
|
21
|
+
raise ResponseError, error_message(response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# rubocop:enable Style/GuardClause
|
26
|
+
|
27
|
+
def error_message(response)
|
28
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class MissingActionNetworkId < StandardError; end
|
33
|
+
|
34
|
+
class MustSpecifyValidPersonId < StandardError; end
|
35
|
+
|
36
|
+
class NotFoundError < StandardError; end
|
37
|
+
|
38
|
+
class ResponseError < StandardError; end
|
39
|
+
end
|
40
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module ActionNetworkRest
|
4
4
|
class Signatures < Base
|
5
|
+
class CreateError < StandardError; end
|
6
|
+
|
5
7
|
attr_accessor :petition_id
|
6
8
|
|
7
9
|
def base_path
|
@@ -13,7 +15,15 @@ module ActionNetworkRest
|
|
13
15
|
post_body['add_tags'] = tags if tags.any?
|
14
16
|
|
15
17
|
response = client.post_request(base_path, post_body)
|
16
|
-
object_from_response(response)
|
18
|
+
new_signature = object_from_response(response)
|
19
|
+
|
20
|
+
# Action Network treats the signature create helper endpoint as an unauthenticated
|
21
|
+
# "blind" POST (see https://actionnetwork.org/docs/v2/unauthenticated-post/). For this
|
22
|
+
# reason they don't return a status code with error to avoid leaking private data. Instead
|
23
|
+
# they return 200 OK with an empty body (vs. the newly created signature's data for successful calls)
|
24
|
+
raise CreateError if new_signature.empty?
|
25
|
+
|
26
|
+
new_signature
|
17
27
|
end
|
18
28
|
|
19
29
|
def update(id, signature_data)
|
data/lib/action_network_rest.rb
CHANGED
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.10.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-
|
11
|
+
date: 2021-10-04 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: []
|
@@ -144,11 +144,11 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".env.sample"
|
147
|
+
- ".github/workflows/ci.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rubocop.yml"
|
149
150
|
- ".ruby-gemset"
|
150
151
|
- ".ruby-version"
|
151
|
-
- ".travis.yml"
|
152
152
|
- CODE_OF_CONDUCT.md
|
153
153
|
- Gemfile
|
154
154
|
- LICENSE
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- bin/rspec
|
161
161
|
- example.rb
|
162
162
|
- lib/action_network_rest.rb
|
163
|
+
- lib/action_network_rest/api.rb
|
163
164
|
- lib/action_network_rest/attendances.rb
|
164
165
|
- lib/action_network_rest/base.rb
|
165
166
|
- lib/action_network_rest/client.rb
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- lib/action_network_rest/events.rb
|
169
170
|
- lib/action_network_rest/people.rb
|
170
171
|
- lib/action_network_rest/petitions.rb
|
172
|
+
- lib/action_network_rest/response/raise_error.rb
|
171
173
|
- lib/action_network_rest/signatures.rb
|
172
174
|
- lib/action_network_rest/taggings.rb
|
173
175
|
- lib/action_network_rest/tags.rb
|
@@ -176,7 +178,7 @@ homepage: https://github.com/controlshift/action-network-rest
|
|
176
178
|
licenses:
|
177
179
|
- MIT
|
178
180
|
metadata: {}
|
179
|
-
post_install_message:
|
181
|
+
post_install_message:
|
180
182
|
rdoc_options: []
|
181
183
|
require_paths:
|
182
184
|
- lib
|
@@ -192,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
194
|
version: '0'
|
193
195
|
requirements: []
|
194
196
|
rubygems_version: 3.1.6
|
195
|
-
signing_key:
|
197
|
+
signing_key:
|
196
198
|
specification_version: 4
|
197
199
|
summary: Ruby client for interacting with the ActionNetwork REST API
|
198
200
|
test_files: []
|