action_network_rest 0.6.0 → 0.8.2
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/.gitignore +4 -14
- data/.rubocop.yml +16 -25
- data/.ruby-version +1 -1
- data/Gemfile +4 -2
- data/README.md +9 -1
- data/Rakefile +5 -3
- data/action_network_rest.gemspec +21 -17
- data/bin/console +4 -3
- data/bin/rake +8 -8
- data/bin/rspec +8 -8
- data/example.rb +3 -1
- data/lib/action_network_rest/api.rb +20 -0
- data/lib/action_network_rest/attendances.rb +31 -0
- data/lib/action_network_rest/base.rb +3 -1
- data/lib/action_network_rest/client.rb +27 -5
- data/lib/action_network_rest/entry_point.rb +2 -0
- data/lib/action_network_rest/event_campaigns.rb +40 -0
- data/lib/action_network_rest/events.rb +55 -0
- data/lib/action_network_rest/people.rb +6 -8
- data/lib/action_network_rest/petitions.rb +4 -2
- data/lib/action_network_rest/response/raise_error.rb +34 -0
- data/lib/action_network_rest/signatures.rb +5 -5
- data/lib/action_network_rest/taggings.rb +3 -1
- data/lib/action_network_rest/tags.rb +5 -3
- data/lib/action_network_rest/version.rb +3 -1
- data/lib/action_network_rest.rb +9 -2
- metadata +34 -15
- 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: 805ab89baf0bfa4fe4635e963cd112a0ffeef25764d200d1d62b759f258db9ec
|
4
|
+
data.tar.gz: 48bcee71e1c6f0bda6e19a7d2dfa3efdc46040f60c6647a1ec030210a456536e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01df31dc26e22c1b9aaad6399ed5a8fbffdf37f17876640aca512840d1e3e73f6da51b0455b830b2c07c6d3b31bf62572ddd19c57753a26aa3fb7de818d0096d
|
7
|
+
data.tar.gz: 85ac9b3aaf713840db2314813ca71ee479e0c0fd8643ca61d96b587a6a1523937d81d0da31d34dcb2cf93b6c655ba5a1c999a13b154500e2f764d2a831f098a1
|
@@ -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/.gitignore
CHANGED
@@ -16,20 +16,7 @@
|
|
16
16
|
# Ignore Byebug command history file.
|
17
17
|
.byebug_history
|
18
18
|
|
19
|
-
|
20
|
-
.dat*
|
21
|
-
.repl_history
|
22
|
-
build/
|
23
|
-
*.bridgesupport
|
24
|
-
build-iPhoneOS/
|
25
|
-
build-iPhoneSimulator/
|
26
|
-
|
27
|
-
## Specific to RubyMotion (use of CocoaPods):
|
28
|
-
#
|
29
|
-
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
-
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
-
#
|
19
|
+
|
33
20
|
# vendor/Pods/
|
34
21
|
|
35
22
|
## Documentation cache and generated files:
|
@@ -56,3 +43,6 @@ Gemfile.lock
|
|
56
43
|
# .rubocop-https?--*
|
57
44
|
|
58
45
|
.rspec_status
|
46
|
+
.DS_store
|
47
|
+
.idea/
|
48
|
+
.rakeTasks
|
data/.rubocop.yml
CHANGED
@@ -1,27 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
1
4
|
AllCops:
|
2
|
-
DisabledByDefault: true
|
3
5
|
NewCops: enable
|
4
|
-
|
5
|
-
|
6
|
-
Enabled:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Enabled: true
|
18
|
-
Lint/RaiseException:
|
19
|
-
Enabled: true
|
20
|
-
Naming/AsciiIdentifiers:
|
21
|
-
Enabled: true
|
22
|
-
Naming/ClassAndModuleCamelCase:
|
23
|
-
Enabled: true
|
24
|
-
Naming/ConstantName:
|
25
|
-
Enabled: true
|
26
|
-
Naming/FileName:
|
27
|
-
Enabled: true
|
6
|
+
TargetRubyVersion: 2.6
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Enabled: false
|
13
|
+
Naming/AccessorMethodName:
|
14
|
+
Enabled: false
|
15
|
+
Naming/MemoizedInstanceVariableName:
|
16
|
+
Enabled: false
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.4
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in action_network_rest.gemspec
|
6
8
|
gemspec
|
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
|
|
@@ -106,6 +106,14 @@ tagging = client.tags(tag_id).taggings.get(tagging_id)
|
|
106
106
|
|
107
107
|
# Delete a Tagging
|
108
108
|
client.tags(tag_id).taggings.delete(tagging_id)
|
109
|
+
|
110
|
+
# List Events in an Event Campaign
|
111
|
+
event_campaign_id = '123e4567-e89b-12d3-a456-426614174000'
|
112
|
+
client.event_campaigns(event_campaign_id).events.list
|
113
|
+
|
114
|
+
# Add an Attendance
|
115
|
+
event_id = '123e4567-e89b-12d3-a456-426655440000'
|
116
|
+
client.events(event_id).attendances.create({ person: {email_addresses: [{address: 'alice@example.com'}]}})
|
109
117
|
```
|
110
118
|
|
111
119
|
## Development
|
data/Rakefile
CHANGED
data/action_network_rest.gemspec
CHANGED
@@ -1,32 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require 'action_network_rest/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'action_network_rest'
|
8
9
|
spec.version = ActionNetworkRest::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Grey Moore']
|
11
|
+
spec.email = ['grey@controlshiftlabs.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.summary = 'Ruby client for interacting with the ActionNetwork REST API'
|
14
|
+
spec.homepage = 'https://github.com/controlshift/action-network-rest'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
# Specify which files should be added to the gem when it is released.
|
17
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir.chdir(File.expand_path(
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
21
|
end
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
22
23
|
|
23
|
-
spec.
|
24
|
+
spec.required_ruby_version = '>= 2.6'
|
24
25
|
|
25
|
-
spec.
|
26
|
-
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_runtime_dependency 'vertebrae', '~> 0.6.0'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
29
|
+
spec.add_development_dependency 'byebug', '~> 11.1'
|
30
|
+
spec.add_development_dependency 'dotenv', '~> 2.7'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
33
|
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'rubocop-performance'
|
35
|
+
spec.add_development_dependency 'webmock', '~> 3.8.3'
|
32
36
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'action_network_rest'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "action_network_rest"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/bin/rake
CHANGED
@@ -8,14 +8,14 @@
|
|
8
8
|
# this file is here to facilitate running it.
|
9
9
|
#
|
10
10
|
|
11
|
-
require
|
12
|
-
ENV[
|
13
|
-
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
14
|
|
15
|
-
bundle_binstub = File.expand_path(
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
16
|
|
17
17
|
if File.file?(bundle_binstub)
|
18
|
-
if
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
19
|
load(bundle_binstub)
|
20
20
|
else
|
21
21
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
require
|
27
|
-
require
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
28
|
|
29
|
-
load Gem.bin_path(
|
29
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/rspec
CHANGED
@@ -8,14 +8,14 @@
|
|
8
8
|
# this file is here to facilitate running it.
|
9
9
|
#
|
10
10
|
|
11
|
-
require
|
12
|
-
ENV[
|
13
|
-
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
14
|
|
15
|
-
bundle_binstub = File.expand_path(
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
16
|
|
17
17
|
if File.file?(bundle_binstub)
|
18
|
-
if
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
19
|
load(bundle_binstub)
|
20
20
|
else
|
21
21
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
require
|
27
|
-
require
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
28
|
|
29
|
-
load Gem.bin_path(
|
29
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/example.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/action_network_rest'
|
2
4
|
require 'dotenv'
|
3
5
|
require 'byebug'
|
@@ -10,4 +12,4 @@ client = ActionNetworkRest.new(api_key: ENV['API_KEY']) # rubocop:disable Lint/U
|
|
10
12
|
puts "Ready to call Action Network API using 'client' object"
|
11
13
|
byebug # rubocop:disable Lint/Debugger
|
12
14
|
|
13
|
-
puts
|
15
|
+
puts 'Bye!'
|
@@ -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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionNetworkRest
|
4
|
+
class Attendances < Base
|
5
|
+
attr_accessor :event_campaign_id, :event_id
|
6
|
+
|
7
|
+
def base_path
|
8
|
+
if event_campaign_id.present?
|
9
|
+
"event_campaigns/#{url_escape(event_campaign_id)}/events/#{url_escape(event_id)}/attendances/"
|
10
|
+
else
|
11
|
+
"events/#{url_escape(event_id)}/attendances/"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(attendance_data)
|
16
|
+
response = client.post_request base_path, attendance_data
|
17
|
+
object_from_response(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(id, attendance_data)
|
21
|
+
response = client.put_request "#{base_path}#{url_escape(id)}", attendance_data
|
22
|
+
object_from_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def osdi_key
|
28
|
+
'osdi:attendance'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class Base < Vertebrae::Model
|
3
5
|
def get(id)
|
@@ -6,7 +8,7 @@ module ActionNetworkRest
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def list(page: 1)
|
9
|
-
response = client.get_request "#{base_path}?page=#{page}"
|
11
|
+
response = client.get_request "#{base_path}?page=#{url_escape(page)}"
|
10
12
|
objects = response.body.dig('_embedded', osdi_key)
|
11
13
|
return [] if objects.nil?
|
12
14
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
|
-
class Client <
|
4
|
+
class Client < API
|
3
5
|
attr_accessor :api_key
|
4
6
|
|
5
|
-
def initialize(options={}, &block)
|
7
|
+
def initialize(options = {}, &block)
|
6
8
|
self.api_key = options[:api_key]
|
7
9
|
super(options, &block)
|
8
10
|
end
|
@@ -12,7 +14,7 @@ module ActionNetworkRest
|
|
12
14
|
host: 'actionnetwork.org',
|
13
15
|
prefix: '/api/v2',
|
14
16
|
content_type: 'application/json',
|
15
|
-
additional_headers: {'OSDI-API-Token' => api_key},
|
17
|
+
additional_headers: { 'OSDI-API-Token' => api_key },
|
16
18
|
user_agent: 'ruby: ActionNetworkRest'
|
17
19
|
}
|
18
20
|
end
|
@@ -23,6 +25,26 @@ module ActionNetworkRest
|
|
23
25
|
|
24
26
|
## Helpers to let users do things like `an_client.people.create(params)`
|
25
27
|
|
28
|
+
def events(event_id = nil)
|
29
|
+
if @_events&.send(:[], event_id).nil?
|
30
|
+
@_events = {} if @_events.nil?
|
31
|
+
|
32
|
+
@_events[event_id] = ActionNetworkRest::Events.new(event_id: event_id, client: self)
|
33
|
+
end
|
34
|
+
|
35
|
+
@_events[event_id]
|
36
|
+
end
|
37
|
+
|
38
|
+
def event_campaigns(event_campaign_id = nil)
|
39
|
+
if @_event_campaigns&.send(:[], event_campaign_id).nil?
|
40
|
+
@_event_campaigns = {} if @_event_campaigns.nil?
|
41
|
+
|
42
|
+
@_event_campaigns[event_campaign_id] = ActionNetworkRest::EventCampaigns.new(event_campaign_id, client: self)
|
43
|
+
end
|
44
|
+
|
45
|
+
@_event_campaigns[event_campaign_id]
|
46
|
+
end
|
47
|
+
|
26
48
|
def entry_point
|
27
49
|
@_entry_point ||= ActionNetworkRest::EntryPoint.new(client: self)
|
28
50
|
end
|
@@ -31,7 +53,7 @@ module ActionNetworkRest
|
|
31
53
|
@_people ||= ActionNetworkRest::People.new(client: self)
|
32
54
|
end
|
33
55
|
|
34
|
-
def petitions(petition_id=nil)
|
56
|
+
def petitions(petition_id = nil)
|
35
57
|
if @_petitions&.send(:[], petition_id).nil?
|
36
58
|
@_petitions = {} if @_petitions.nil?
|
37
59
|
|
@@ -41,7 +63,7 @@ module ActionNetworkRest
|
|
41
63
|
@_petitions[petition_id]
|
42
64
|
end
|
43
65
|
|
44
|
-
def tags(tag_id=nil)
|
66
|
+
def tags(tag_id = nil)
|
45
67
|
if @_tags&.send(:[], tag_id).nil?
|
46
68
|
@_tags = {} if @_tags.nil?
|
47
69
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionNetworkRest
|
4
|
+
class EventCampaigns < Base
|
5
|
+
attr_accessor :event_campaign_id
|
6
|
+
|
7
|
+
# Without a event_campaign_id, this class is used for EventCampaign creation/update endpoints.
|
8
|
+
# With a event_campaign_id, this class is used to initialise the Events class,
|
9
|
+
# like client.event_campaigns(123).events
|
10
|
+
def initialize(event_campaign_id = nil, client:)
|
11
|
+
super(client: client, event_campaign_id: event_campaign_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_path
|
15
|
+
'event_campaigns/'
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(event_campaign_data)
|
19
|
+
response = client.post_request(base_path, event_campaign_data)
|
20
|
+
object_from_response(response)
|
21
|
+
end
|
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
|
+
|
29
|
+
def events(event_id = nil)
|
30
|
+
@_events ||= ActionNetworkRest::Events.new(event_campaign_id: event_campaign_id, event_id: event_id,
|
31
|
+
client: client)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def osdi_key
|
37
|
+
'action_network:event_campaigns'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionNetworkRest
|
4
|
+
class Events < Base
|
5
|
+
attr_accessor :event_campaign_id, :event_id
|
6
|
+
|
7
|
+
def initialize(client:, event_campaign_id: nil, event_id: nil)
|
8
|
+
super(client: client, event_id: event_id, event_campaign_id: event_campaign_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_path
|
12
|
+
if event_campaign_id.present?
|
13
|
+
"event_campaigns/#{url_escape(event_campaign_id)}/events/"
|
14
|
+
else
|
15
|
+
'events/'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(event_data, creator_person_id: nil, organizer_person_id: nil)
|
20
|
+
post_body = event_data
|
21
|
+
|
22
|
+
if creator_person_id.present?
|
23
|
+
creator_person_url = action_network_url("/people/#{url_escape(creator_person_id)}")
|
24
|
+
post_body['_links'] ||= {}
|
25
|
+
post_body['_links']['osdi:creator'] = { href: creator_person_url }
|
26
|
+
end
|
27
|
+
|
28
|
+
if organizer_person_id.present?
|
29
|
+
organizer_person_url = action_network_url("/people/#{url_escape(organizer_person_id)}")
|
30
|
+
post_body['_links'] ||= {}
|
31
|
+
post_body['_links']['osdi:organizer'] = { href: organizer_person_url }
|
32
|
+
end
|
33
|
+
|
34
|
+
response = client.post_request(base_path, post_body)
|
35
|
+
object_from_response(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def attendances
|
39
|
+
@_attendances ||= ActionNetworkRest::Attendances.new(client: client, event_id: event_id,
|
40
|
+
event_campaign_id: event_campaign_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def update(id, event_data)
|
44
|
+
event_path = "#{base_path}#{url_escape(id)}"
|
45
|
+
response = client.put_request event_path, event_data
|
46
|
+
object_from_response(response)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def osdi_key
|
52
|
+
'osdi:events'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class People < Base
|
3
5
|
def base_path
|
@@ -5,17 +7,15 @@ module ActionNetworkRest
|
|
5
7
|
end
|
6
8
|
|
7
9
|
def create(person_data, tags: [])
|
8
|
-
post_body = {'person' => person_data}
|
9
|
-
if tags.any?
|
10
|
-
post_body['add_tags'] = tags
|
11
|
-
end
|
10
|
+
post_body = { 'person' => person_data }
|
11
|
+
post_body['add_tags'] = tags if tags.any?
|
12
12
|
|
13
13
|
response = client.post_request base_path, post_body
|
14
14
|
object_from_response(response)
|
15
15
|
end
|
16
16
|
|
17
17
|
def unsubscribe(id)
|
18
|
-
request_body = {email_addresses: [{status: 'unsubscribed'}]}
|
18
|
+
request_body = { email_addresses: [{ status: 'unsubscribed' }] }
|
19
19
|
response = client.put_request "#{base_path}#{url_escape(id)}", request_body
|
20
20
|
object_from_response(response)
|
21
21
|
end
|
@@ -36,9 +36,7 @@ module ActionNetworkRest
|
|
36
36
|
url_encoded_filter_string = url_escape("email_address eq '#{email}'")
|
37
37
|
response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
|
38
38
|
person_object = response.body[:_embedded][osdi_key].first
|
39
|
-
if person_object.present?
|
40
|
-
set_action_network_id_on_object(person_object)
|
41
|
-
end
|
39
|
+
set_action_network_id_on_object(person_object) if person_object.present?
|
42
40
|
end
|
43
41
|
|
44
42
|
def update(id, person_data)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class Petitions < Base
|
3
5
|
attr_accessor :petition_id
|
@@ -5,7 +7,7 @@ module ActionNetworkRest
|
|
5
7
|
# Without a petition_id, this class is used for Petition creation/update endpoints.
|
6
8
|
# With a petition_id, this class is used to initialise the Signatures class,
|
7
9
|
# like client.petitions(123).signatures
|
8
|
-
def initialize(petition_id=nil, client:)
|
10
|
+
def initialize(petition_id = nil, client:)
|
9
11
|
super(client: client, petition_id: petition_id)
|
10
12
|
end
|
11
13
|
|
@@ -21,7 +23,7 @@ module ActionNetworkRest
|
|
21
23
|
post_body = petition_data
|
22
24
|
if creator_person_id.present?
|
23
25
|
creator_person_url = action_network_url("/people/#{url_escape(creator_person_id)}")
|
24
|
-
post_body['_links'] = {'osdi:creator' => {href: creator_person_url}}
|
26
|
+
post_body['_links'] = { 'osdi:creator' => { href: creator_person_url } }
|
25
27
|
end
|
26
28
|
|
27
29
|
response = client.post_request base_path, post_body
|
@@ -0,0 +1,34 @@
|
|
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
|
+
else
|
19
|
+
raise ResponseError, error_message(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# rubocop:enable Style/GuardClause
|
24
|
+
|
25
|
+
def error_message(response)
|
26
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MustSpecifyValidPersonId < StandardError; end
|
31
|
+
|
32
|
+
class ResponseError < StandardError; end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class Signatures < Base
|
3
5
|
attr_accessor :petition_id
|
@@ -8,16 +10,14 @@ module ActionNetworkRest
|
|
8
10
|
|
9
11
|
def create(signature_data, tags: [])
|
10
12
|
post_body = signature_data
|
11
|
-
if tags.any?
|
12
|
-
post_body['add_tags'] = tags
|
13
|
-
end
|
13
|
+
post_body['add_tags'] = tags if tags.any?
|
14
14
|
|
15
|
-
response = client.post_request
|
15
|
+
response = client.post_request(base_path, post_body)
|
16
16
|
object_from_response(response)
|
17
17
|
end
|
18
18
|
|
19
19
|
def update(id, signature_data)
|
20
|
-
response = client.put_request
|
20
|
+
response = client.put_request("#{base_path}#{url_escape(id)}", signature_data)
|
21
21
|
object_from_response(response)
|
22
22
|
end
|
23
23
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class Taggings < Base
|
3
5
|
attr_accessor :tag_id
|
@@ -9,7 +11,7 @@ module ActionNetworkRest
|
|
9
11
|
def create(tagging_data, person_id:)
|
10
12
|
post_body = tagging_data
|
11
13
|
person_url = action_network_url("/people/#{url_escape(person_id)}")
|
12
|
-
post_body['_links'] = {'osdi:person' => {href: person_url}}
|
14
|
+
post_body['_links'] = { 'osdi:person' => { href: person_url } }
|
13
15
|
|
14
16
|
response = client.post_request base_path, post_body
|
15
17
|
object_from_response(response)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionNetworkRest
|
2
4
|
class Tags < Base
|
3
5
|
attr_accessor :tag_id
|
@@ -5,7 +7,7 @@ module ActionNetworkRest
|
|
5
7
|
# Without a tag_id, this class is used for the Tag creation endpoint.
|
6
8
|
# With a tag_id, this class is used to initialise the Taggings class,
|
7
9
|
# like client.tags(123).taggings
|
8
|
-
def initialize(tag_id=nil, client:)
|
10
|
+
def initialize(tag_id = nil, client:)
|
9
11
|
super(client: client, tag_id: tag_id)
|
10
12
|
end
|
11
13
|
|
@@ -18,7 +20,7 @@ module ActionNetworkRest
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def create(name)
|
21
|
-
post_body = {name: name}
|
23
|
+
post_body = { name: name }
|
22
24
|
response = client.post_request base_path, post_body
|
23
25
|
object_from_response(response)
|
24
26
|
end
|
@@ -29,7 +31,7 @@ module ActionNetworkRest
|
|
29
31
|
# all tags and iterate to find the one we're looking for.
|
30
32
|
page = 1
|
31
33
|
loop do
|
32
|
-
tags =
|
34
|
+
tags = list(page: page)
|
33
35
|
return nil if tags.empty?
|
34
36
|
|
35
37
|
found_tag = tags.find { |t| t.name == name }
|
data/lib/action_network_rest.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'vertebrae'
|
2
4
|
|
3
5
|
module ActionNetworkRest
|
@@ -10,11 +12,16 @@ module ActionNetworkRest
|
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
require
|
14
|
-
require
|
15
|
+
require 'action_network_rest/version'
|
16
|
+
require 'action_network_rest/api'
|
17
|
+
require 'action_network_rest/response/raise_error'
|
18
|
+
require 'action_network_rest/client'
|
15
19
|
require 'action_network_rest/base'
|
16
20
|
|
21
|
+
require 'action_network_rest/attendances'
|
17
22
|
require 'action_network_rest/entry_point'
|
23
|
+
require 'action_network_rest/events'
|
24
|
+
require 'action_network_rest/event_campaigns'
|
18
25
|
require 'action_network_rest/people'
|
19
26
|
require 'action_network_rest/petitions'
|
20
27
|
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.8.2
|
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:
|
11
|
+
date: 2021-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vertebrae
|
@@ -95,21 +95,21 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
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
|
-
version:
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: rubocop
|
112
|
+
name: rubocop-performance
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -122,7 +122,21 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.8.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.8.3
|
139
|
+
description:
|
126
140
|
email:
|
127
141
|
- grey@controlshiftlabs.com
|
128
142
|
executables: []
|
@@ -130,11 +144,11 @@ extensions: []
|
|
130
144
|
extra_rdoc_files: []
|
131
145
|
files:
|
132
146
|
- ".env.sample"
|
147
|
+
- ".github/workflows/ci.yml"
|
133
148
|
- ".gitignore"
|
134
149
|
- ".rubocop.yml"
|
135
150
|
- ".ruby-gemset"
|
136
151
|
- ".ruby-version"
|
137
|
-
- ".travis.yml"
|
138
152
|
- CODE_OF_CONDUCT.md
|
139
153
|
- Gemfile
|
140
154
|
- LICENSE
|
@@ -146,11 +160,16 @@ files:
|
|
146
160
|
- bin/rspec
|
147
161
|
- example.rb
|
148
162
|
- lib/action_network_rest.rb
|
163
|
+
- lib/action_network_rest/api.rb
|
164
|
+
- lib/action_network_rest/attendances.rb
|
149
165
|
- lib/action_network_rest/base.rb
|
150
166
|
- lib/action_network_rest/client.rb
|
151
167
|
- lib/action_network_rest/entry_point.rb
|
168
|
+
- lib/action_network_rest/event_campaigns.rb
|
169
|
+
- lib/action_network_rest/events.rb
|
152
170
|
- lib/action_network_rest/people.rb
|
153
171
|
- lib/action_network_rest/petitions.rb
|
172
|
+
- lib/action_network_rest/response/raise_error.rb
|
154
173
|
- lib/action_network_rest/signatures.rb
|
155
174
|
- lib/action_network_rest/taggings.rb
|
156
175
|
- lib/action_network_rest/tags.rb
|
@@ -159,7 +178,7 @@ homepage: https://github.com/controlshift/action-network-rest
|
|
159
178
|
licenses:
|
160
179
|
- MIT
|
161
180
|
metadata: {}
|
162
|
-
post_install_message:
|
181
|
+
post_install_message:
|
163
182
|
rdoc_options: []
|
164
183
|
require_paths:
|
165
184
|
- lib
|
@@ -167,15 +186,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
186
|
requirements:
|
168
187
|
- - ">="
|
169
188
|
- !ruby/object:Gem::Version
|
170
|
-
version: '
|
189
|
+
version: '2.6'
|
171
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
191
|
requirements:
|
173
192
|
- - ">="
|
174
193
|
- !ruby/object:Gem::Version
|
175
194
|
version: '0'
|
176
195
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
178
|
-
signing_key:
|
196
|
+
rubygems_version: 3.1.6
|
197
|
+
signing_key:
|
179
198
|
specification_version: 4
|
180
199
|
summary: Ruby client for interacting with the ActionNetwork REST API
|
181
200
|
test_files: []
|