action_network_rest 0.7.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6ad7612c6bccf090f5e717750753d3f47314b53b0a36d0b59907102f1dcd1eb
4
- data.tar.gz: adddc2d4bb8bab60b0db1ebb4312651793e757f193f177c68562c2b96d57cdd2
3
+ metadata.gz: f9016ae9e2c22b78c042639d589683ff591c4098712cad0861dc8faab843c82a
4
+ data.tar.gz: 114f680aead1e7b3500c26fb61175784046bf68db57ac62137df455f98f1789e
5
5
  SHA512:
6
- metadata.gz: f9e77003bda8400d416e299575383eb36c4d9aa43e8451abb29877e7fd329d5fad8dd58655137218525d351ae49e6b274e75f80e75db90a94161f4ac9eeb9f43
7
- data.tar.gz: 171aa0166b8a8667f9ee1540ca5bdf3182401a9a7c91badd0bb701815d17e4f0ae22435da8e9202d636a25d7f9a3dd607272f13519238d0110cc4944e0f66021
6
+ metadata.gz: 7f811528d9ffe857652121e3c3bf42b517b9991a5335dd52fd99c02d36b3a75688bbc403c16aca0cdd619a4efc96fc3d5f50cb7d4fcddc2b01731c068c85e03b
7
+ data.tar.gz: b4db252bd30f7aeee2f3d402f287104212e51a7cf2e745773767d63f577a9d1c9131b4162b671b0568108b1b7d6e7e23434ed5d1016c949eb5e613238722c5fb
@@ -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.3
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
- [![Build Status](https://travis-ci.org/controlshift/action-network-rest.svg?branch=master)](https://travis-ci.org/controlshift/action-network-rest)
5
+ [![CI Status](https://github.com/controlshift/action-network-rest/actions/workflows/ci.yml/badge.svg)](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)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionNetworkRest
4
- class Client < Vertebrae::API
4
+ class Client < API
5
5
  attr_accessor :api_key
6
6
 
7
7
  def initialize(options = {}, &block)
@@ -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)
@@ -16,8 +16,22 @@ module ActionNetworkRest
16
16
  end
17
17
  end
18
18
 
19
- def create(event_data)
20
- response = client.post_request(base_path, event_data)
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)
21
35
  object_from_response(response)
22
36
  end
23
37
 
@@ -26,6 +40,12 @@ module ActionNetworkRest
26
40
  event_campaign_id: event_campaign_id)
27
41
  end
28
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
+
29
49
  private
30
50
 
31
51
  def osdi_key
@@ -0,0 +1,38 @@
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 MustSpecifyValidPersonId < StandardError; end
33
+
34
+ class NotFoundError < StandardError; end
35
+
36
+ class ResponseError < StandardError; end
37
+ end
38
+ 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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionNetworkRest
4
- VERSION = '0.7.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -13,6 +13,8 @@ module ActionNetworkRest
13
13
  end
14
14
 
15
15
  require 'action_network_rest/version'
16
+ require 'action_network_rest/api'
17
+ require 'action_network_rest/response/raise_error'
16
18
  require 'action_network_rest/client'
17
19
  require 'action_network_rest/base'
18
20
 
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.7.0
4
+ version: 0.9.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: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -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
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.7
4
- cache: bundler
5
- before_install:
6
- - gem install bundler
7
- script:
8
- - bundle exec rspec
9
- - bundle exec rubocop