action_network_rest 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +2 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +27 -0
- data/.travis.yml +9 -0
- data/README.md +83 -5
- data/action_network_rest.gemspec +3 -0
- data/bin/console +14 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/example.rb +13 -0
- data/lib/action_network_rest.rb +6 -0
- data/lib/action_network_rest/base.rb +53 -0
- data/lib/action_network_rest/client.rb +25 -1
- data/lib/action_network_rest/entry_point.rb +21 -0
- data/lib/action_network_rest/people.rb +37 -9
- data/lib/action_network_rest/petitions.rb +43 -0
- data/lib/action_network_rest/signatures.rb +30 -0
- data/lib/action_network_rest/taggings.rb +29 -0
- data/lib/action_network_rest/tags.rb +48 -0
- data/lib/action_network_rest/version.rb +1 -1
- metadata +58 -4
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d8ccace61c21488260b04d902f02bf58cea6c834f7d118efec1d4ab1118e25e
|
4
|
+
data.tar.gz: 13e514a3edb2121263a1cea07ecf67ae809609dbfd596f51d7297e559ef9f48b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48ea50aef6bdc81d44e79e396c7386ca87042af2991ab016205b56e3491868e95ed213f3ed744ddbef3ad5846a72bd2dbd0cd0f80d22195bcdb6b4ba2085300
|
7
|
+
data.tar.gz: c83e23dbbd65671efc3c9498a1f26406f66156b834f643ae801221b83eefb8220c9e4b0fc9d949db834f7ee8189f52896b736457096045dd20c4ac1a5c809cfc
|
data/.env.sample
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisabledByDefault: true
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Security:
|
6
|
+
Enabled: true
|
7
|
+
|
8
|
+
Bundler/DuplicatedGem:
|
9
|
+
Enabled: true
|
10
|
+
Bundler/InsecureProtocolSource:
|
11
|
+
Enabled: true
|
12
|
+
Layout/IndentationStyle:
|
13
|
+
Enabled: true
|
14
|
+
Layout/SpaceInsideRangeLiteral:
|
15
|
+
Enabled: true
|
16
|
+
Lint:
|
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
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActionNetworkRest
|
2
2
|
|
3
|
-
Ruby client for interacting with the [ActionNetwork REST API](https://actionnetwork.org/docs/)
|
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
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/controlshift/action-network-rest.svg?branch=master)](https://travis-ci.org/controlshift/action-network-rest)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -21,15 +23,89 @@ Or install it yourself as:
|
|
21
23
|
## Usage
|
22
24
|
|
23
25
|
```
|
26
|
+
require 'action_network_rest'
|
27
|
+
|
24
28
|
client = ActionNetworkRest.new(api_key: YOUR_API_KEY)
|
25
29
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
30
|
+
# Check that our API key is working. Returns true or false.
|
31
|
+
client.entry_point.authenticated_successfully?
|
32
|
+
|
33
|
+
# See information about Action Network API endpoints
|
34
|
+
client.entry_point.get
|
29
35
|
|
30
36
|
# Create a new Person
|
31
37
|
person = client.people.create(email_addresses: [{address: 'foo@example.com'}])
|
32
|
-
|
38
|
+
person_id = person.action_network_id
|
39
|
+
|
40
|
+
# List people
|
41
|
+
people = client.people.list
|
42
|
+
|
43
|
+
# Iterate over a list of people
|
44
|
+
page_number = 1
|
45
|
+
loop do
|
46
|
+
people = client.people.list(page: page_number)
|
47
|
+
break if people.empty?
|
48
|
+
page_number += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
# Retrieve a Person's data
|
52
|
+
person = client.people.get(person_id)
|
53
|
+
puts person.email_addresses
|
54
|
+
|
55
|
+
# Retrieve a Person's data by their email address
|
56
|
+
person = client.people.find_by_email(person_email)
|
57
|
+
person_id = person.action_network_id
|
58
|
+
puts person.email_addresses
|
59
|
+
|
60
|
+
# Update a Person
|
61
|
+
client.people.update(person_id, {custom_fields: {custom_id: "12345"}})
|
62
|
+
|
63
|
+
# Unsubscribe a Person
|
64
|
+
client.people.unsubscribe(person_id)
|
65
|
+
|
66
|
+
# Create a new Petition
|
67
|
+
petition = client.petitions.create({title: 'Do the Thing!'}, creator_person_id: person_id)
|
68
|
+
petition_id = petition.action_network_id
|
69
|
+
|
70
|
+
# Retrieve a Petition
|
71
|
+
petition = client.petitions.get(petition_id)
|
72
|
+
puts petition.title
|
73
|
+
|
74
|
+
# Update a Petition
|
75
|
+
client.petitions.update(petition_id, {description: 'An updated description'})
|
76
|
+
|
77
|
+
# Create a Signature on a Petition
|
78
|
+
signature = client.petitions(petition_id).signatures.create({comments: 'This is so important',
|
79
|
+
person: {email_addresses: [{address: 'alice@example.com'}]}},
|
80
|
+
tags: ['volunteer'])
|
81
|
+
signature_id = signature.action_network_id
|
82
|
+
|
83
|
+
# Retrieve a Signature
|
84
|
+
signature = client.petitions(petition_id).signatures.get(signature_id)
|
85
|
+
puts signature.created_date
|
86
|
+
|
87
|
+
# Update a Signature
|
88
|
+
client.petitions(petition_id).signatures.update(signature_id, {comments: 'new comments'})
|
89
|
+
|
90
|
+
# Create a Tag
|
91
|
+
tag = client.tags.create('Volunteers')
|
92
|
+
tag_id = tag.action_network_id
|
93
|
+
|
94
|
+
# Retrieve a Tag
|
95
|
+
tag = client.tags.get(tag_id)
|
96
|
+
|
97
|
+
# Retrieve a Tag by name
|
98
|
+
tag = client.tags.find_by_name('Volunteers')
|
99
|
+
|
100
|
+
# Apply a Tag to a Person
|
101
|
+
tagging = client.tags(tag_id).create({identifiers: ['external:123']}, person_id: person_id)
|
102
|
+
tagging_id = tagging.action_network_id
|
103
|
+
|
104
|
+
# Retrieve a Tagging
|
105
|
+
tagging = client.tags(tag_id).taggings.get(tagging_id)
|
106
|
+
|
107
|
+
# Delete a Tagging
|
108
|
+
client.tags(tag_id).taggings.delete(tagging_id)
|
33
109
|
```
|
34
110
|
|
35
111
|
## Development
|
@@ -38,6 +114,8 @@ After checking out the repo, run `bundle install` to install dependencies. Then,
|
|
38
114
|
|
39
115
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
116
|
|
117
|
+
To run a REPL with an initialized client object you'll need to create your own `.env` file based off `.env.sample` and then run `bundle exec ruby example.rb`.
|
118
|
+
|
41
119
|
## Contributing
|
42
120
|
|
43
121
|
Bug reports and pull requests are welcome on GitHub at https://github.com/controlshift/action-network-rest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/action_network_rest.gemspec
CHANGED
@@ -23,7 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "vertebrae", "~> 0.6.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 2.1"
|
26
|
+
spec.add_development_dependency "byebug", "~> 11.1"
|
27
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
26
28
|
spec.add_development_dependency "rake", "~> 13.0"
|
27
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
30
|
spec.add_development_dependency 'webmock', '~> 3.8.3'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
29
32
|
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "action_network_rest"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/example.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'lib/action_network_rest'
|
2
|
+
require 'dotenv'
|
3
|
+
require 'byebug'
|
4
|
+
|
5
|
+
Dotenv.load('.env')
|
6
|
+
raise 'Must set API_KEY environmental variable. See .env.sample for details' if ENV['API_KEY'].nil?
|
7
|
+
|
8
|
+
client = ActionNetworkRest.new(api_key: ENV['API_KEY']) # rubocop:disable Lint/UselessAssignment
|
9
|
+
|
10
|
+
puts "Ready to call Action Network API using 'client' object"
|
11
|
+
byebug # rubocop:disable Lint/Debugger
|
12
|
+
|
13
|
+
puts "Bye!"
|
data/lib/action_network_rest.rb
CHANGED
@@ -12,5 +12,11 @@ end
|
|
12
12
|
|
13
13
|
require "action_network_rest/version"
|
14
14
|
require "action_network_rest/client"
|
15
|
+
require 'action_network_rest/base'
|
15
16
|
|
17
|
+
require 'action_network_rest/entry_point'
|
16
18
|
require 'action_network_rest/people'
|
19
|
+
require 'action_network_rest/petitions'
|
20
|
+
require 'action_network_rest/signatures'
|
21
|
+
require 'action_network_rest/taggings'
|
22
|
+
require 'action_network_rest/tags'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class Base < Vertebrae::Model
|
3
|
+
def get(id)
|
4
|
+
response = client.get_request "#{base_path}#{url_escape(id)}"
|
5
|
+
object_from_response(response)
|
6
|
+
end
|
7
|
+
|
8
|
+
def list(page: 1)
|
9
|
+
response = client.get_request "#{base_path}?page=#{page}"
|
10
|
+
objects = response.body.dig('_embedded', osdi_key)
|
11
|
+
return [] if objects.nil?
|
12
|
+
|
13
|
+
objects.each { |obj| set_action_network_id_on_object(obj) }
|
14
|
+
|
15
|
+
objects
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def url_escape(string)
|
21
|
+
CGI.escape(string.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_action_network_id_on_object(obj)
|
25
|
+
# Takes an object which may contain an `identifiers` key, which may contain an action_network identifier
|
26
|
+
# If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
|
27
|
+
# for the convenience of callers using the returned object.
|
28
|
+
# "identifiers": [
|
29
|
+
# "action_network:d6bdf50e-c3a4-4981-a948-3d8c086066d7",
|
30
|
+
# "some_external_system:1",
|
31
|
+
# "another_external_system:57"
|
32
|
+
# ]
|
33
|
+
identifiers = obj[:identifiers] || []
|
34
|
+
qualified_actionnetwork_id = identifiers.find do |id|
|
35
|
+
id.split(':').first == 'action_network'
|
36
|
+
end
|
37
|
+
if qualified_actionnetwork_id.present?
|
38
|
+
obj.action_network_id = qualified_actionnetwork_id.sub(/^action_network:/, '')
|
39
|
+
end
|
40
|
+
|
41
|
+
obj
|
42
|
+
end
|
43
|
+
|
44
|
+
def object_from_response(response)
|
45
|
+
obj = response.body
|
46
|
+
set_action_network_id_on_object(obj)
|
47
|
+
end
|
48
|
+
|
49
|
+
def action_network_url(path)
|
50
|
+
client.connection.configuration.endpoint + path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -4,7 +4,7 @@ module ActionNetworkRest
|
|
4
4
|
|
5
5
|
def initialize(options={}, &block)
|
6
6
|
self.api_key = options[:api_key]
|
7
|
-
super(options
|
7
|
+
super(options, &block)
|
8
8
|
end
|
9
9
|
|
10
10
|
def default_options
|
@@ -23,8 +23,32 @@ module ActionNetworkRest
|
|
23
23
|
|
24
24
|
## Helpers to let users do things like `an_client.people.create(params)`
|
25
25
|
|
26
|
+
def entry_point
|
27
|
+
@_entry_point ||= ActionNetworkRest::EntryPoint.new(client: self)
|
28
|
+
end
|
29
|
+
|
26
30
|
def people
|
27
31
|
@_people ||= ActionNetworkRest::People.new(client: self)
|
28
32
|
end
|
33
|
+
|
34
|
+
def petitions(petition_id=nil)
|
35
|
+
if @_petitions&.send(:[], petition_id).nil?
|
36
|
+
@_petitions = {} if @_petitions.nil?
|
37
|
+
|
38
|
+
@_petitions[petition_id] = ActionNetworkRest::Petitions.new(petition_id, client: self)
|
39
|
+
end
|
40
|
+
|
41
|
+
@_petitions[petition_id]
|
42
|
+
end
|
43
|
+
|
44
|
+
def tags(tag_id=nil)
|
45
|
+
if @_tags&.send(:[], tag_id).nil?
|
46
|
+
@_tags = {} if @_tags.nil?
|
47
|
+
|
48
|
+
@_tags[tag_id] = ActionNetworkRest::Tags.new(tag_id, client: self)
|
49
|
+
end
|
50
|
+
|
51
|
+
@_tags[tag_id]
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class EntryPoint < Vertebrae::Model
|
3
|
+
def base_path
|
4
|
+
''
|
5
|
+
end
|
6
|
+
|
7
|
+
def get
|
8
|
+
response = client.get_request base_path
|
9
|
+
response.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticated_successfully?
|
13
|
+
response_body = get
|
14
|
+
|
15
|
+
# If we successfully authenticated, the entrypoint response will include a reference to tags.
|
16
|
+
# If not (API key missing or wrong), the response will not include anything about tags,
|
17
|
+
# but will otherwise be successful.
|
18
|
+
response_body.dig('_links', 'osdi:tags').present?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,14 +1,9 @@
|
|
1
1
|
module ActionNetworkRest
|
2
|
-
class People <
|
2
|
+
class People < Base
|
3
3
|
def base_path
|
4
4
|
'people/'
|
5
5
|
end
|
6
6
|
|
7
|
-
def get(id)
|
8
|
-
response = client.get_request "#{base_path}#{url_escape(id)}"
|
9
|
-
response.body
|
10
|
-
end
|
11
|
-
|
12
7
|
def create(person_data, tags: [])
|
13
8
|
post_body = {'person' => person_data}
|
14
9
|
if tags.any?
|
@@ -16,13 +11,46 @@ module ActionNetworkRest
|
|
16
11
|
end
|
17
12
|
|
18
13
|
response = client.post_request base_path, post_body
|
19
|
-
response
|
14
|
+
object_from_response(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def unsubscribe(id)
|
18
|
+
request_body = {email_addresses: [{status: 'unsubscribed'}]}
|
19
|
+
response = client.put_request "#{base_path}#{url_escape(id)}", request_body
|
20
|
+
object_from_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_by_email(email)
|
24
|
+
# This works for parsing exactly 1 person's info out of the response.
|
25
|
+
# The response we get from Action Network is expected to have
|
26
|
+
#
|
27
|
+
# "_embedded": {
|
28
|
+
# "osdi:people": [{
|
29
|
+
# "identifiers": [
|
30
|
+
# "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29"
|
31
|
+
# ....
|
32
|
+
# ]
|
33
|
+
# }]
|
34
|
+
# }
|
35
|
+
#
|
36
|
+
url_encoded_filter_string = url_escape("email_address eq '#{email}'")
|
37
|
+
response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
|
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
|
42
|
+
end
|
43
|
+
|
44
|
+
def update(id, person_data)
|
45
|
+
people_path = "#{base_path}#{url_escape(id)}"
|
46
|
+
response = client.put_request people_path, person_data
|
47
|
+
object_from_response(response)
|
20
48
|
end
|
21
49
|
|
22
50
|
private
|
23
51
|
|
24
|
-
def
|
25
|
-
|
52
|
+
def osdi_key
|
53
|
+
'osdi:people'
|
26
54
|
end
|
27
55
|
end
|
28
56
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class Petitions < Base
|
3
|
+
attr_accessor :petition_id
|
4
|
+
|
5
|
+
# Without a petition_id, this class is used for Petition creation/update endpoints.
|
6
|
+
# With a petition_id, this class is used to initialise the Signatures class,
|
7
|
+
# like client.petitions(123).signatures
|
8
|
+
def initialize(petition_id=nil, client:)
|
9
|
+
super(client: client, petition_id: petition_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def signatures
|
13
|
+
@_signatures ||= ActionNetworkRest::Signatures.new(client: client, petition_id: petition_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_path
|
17
|
+
'petitions/'
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(petition_data, creator_person_id: nil)
|
21
|
+
post_body = petition_data
|
22
|
+
if creator_person_id.present?
|
23
|
+
creator_person_url = action_network_url("/people/#{url_escape(creator_person_id)}")
|
24
|
+
post_body['_links'] = {'osdi:creator' => {href: creator_person_url}}
|
25
|
+
end
|
26
|
+
|
27
|
+
response = client.post_request base_path, post_body
|
28
|
+
object_from_response(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update(id, petition_data)
|
32
|
+
petition_path = "#{base_path}#{url_escape(id)}"
|
33
|
+
response = client.put_request petition_path, petition_data
|
34
|
+
object_from_response(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def osdi_key
|
40
|
+
'osdi:petitions'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class Signatures < Base
|
3
|
+
attr_accessor :petition_id
|
4
|
+
|
5
|
+
def base_path
|
6
|
+
"petitions/#{url_escape(petition_id)}/signatures/"
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(signature_data, tags: [])
|
10
|
+
post_body = signature_data
|
11
|
+
if tags.any?
|
12
|
+
post_body['add_tags'] = tags
|
13
|
+
end
|
14
|
+
|
15
|
+
response = client.post_request base_path, post_body
|
16
|
+
object_from_response(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(id, signature_data)
|
20
|
+
response = client.put_request "#{base_path}#{url_escape(id)}", signature_data
|
21
|
+
object_from_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def osdi_key
|
27
|
+
'osdi:signatures'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class Taggings < Base
|
3
|
+
attr_accessor :tag_id
|
4
|
+
|
5
|
+
def base_path
|
6
|
+
"tags/#{url_escape(tag_id)}/taggings/"
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(tagging_data, person_id:)
|
10
|
+
post_body = tagging_data
|
11
|
+
person_url = action_network_url("/people/#{url_escape(person_id)}")
|
12
|
+
post_body['_links'] = {'osdi:person' => {href: person_url}}
|
13
|
+
|
14
|
+
response = client.post_request base_path, post_body
|
15
|
+
object_from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(id)
|
19
|
+
response = client.delete_request "#{base_path}#{url_escape(id)}"
|
20
|
+
object_from_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def osdi_key
|
26
|
+
'osdi:taggings'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ActionNetworkRest
|
2
|
+
class Tags < Base
|
3
|
+
attr_accessor :tag_id
|
4
|
+
|
5
|
+
# Without a tag_id, this class is used for the Tag creation endpoint.
|
6
|
+
# With a tag_id, this class is used to initialise the Taggings class,
|
7
|
+
# like client.tags(123).taggings
|
8
|
+
def initialize(tag_id=nil, client:)
|
9
|
+
super(client: client, tag_id: tag_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def taggings
|
13
|
+
@_taggings ||= ActionNetworkRest::Taggings.new(client: client, tag_id: tag_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_path
|
17
|
+
'tags/'
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(name)
|
21
|
+
post_body = {name: name}
|
22
|
+
response = client.post_request base_path, post_body
|
23
|
+
object_from_response(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_by_name(name)
|
27
|
+
# Action Network API doesn't support currently OData querying for tags
|
28
|
+
# (https://actionnetwork.org/docs/v2#odata) so we need to retrieve a list of
|
29
|
+
# all tags and iterate to find the one we're looking for.
|
30
|
+
page = 1
|
31
|
+
loop do
|
32
|
+
tags = self.list(page: page)
|
33
|
+
return nil if tags.empty?
|
34
|
+
|
35
|
+
found_tag = tags.find { |t| t.name == name }
|
36
|
+
return found_tag unless found_tag.nil?
|
37
|
+
|
38
|
+
page += 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def osdi_key
|
45
|
+
'osdi:tags'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
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.6.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: 2020-
|
11
|
+
date: 2020-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vertebrae
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: 3.8.3
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
description:
|
84
126
|
email:
|
85
127
|
- grey@controlshiftlabs.com
|
@@ -87,19 +129,31 @@ executables: []
|
|
87
129
|
extensions: []
|
88
130
|
extra_rdoc_files: []
|
89
131
|
files:
|
132
|
+
- ".env.sample"
|
90
133
|
- ".gitignore"
|
134
|
+
- ".rubocop.yml"
|
91
135
|
- ".ruby-gemset"
|
92
136
|
- ".ruby-version"
|
137
|
+
- ".travis.yml"
|
93
138
|
- CODE_OF_CONDUCT.md
|
94
139
|
- Gemfile
|
95
140
|
- LICENSE
|
96
|
-
- LICENSE.txt
|
97
141
|
- README.md
|
98
142
|
- Rakefile
|
99
143
|
- action_network_rest.gemspec
|
144
|
+
- bin/console
|
145
|
+
- bin/rake
|
146
|
+
- bin/rspec
|
147
|
+
- example.rb
|
100
148
|
- lib/action_network_rest.rb
|
149
|
+
- lib/action_network_rest/base.rb
|
101
150
|
- lib/action_network_rest/client.rb
|
151
|
+
- lib/action_network_rest/entry_point.rb
|
102
152
|
- lib/action_network_rest/people.rb
|
153
|
+
- lib/action_network_rest/petitions.rb
|
154
|
+
- lib/action_network_rest/signatures.rb
|
155
|
+
- lib/action_network_rest/taggings.rb
|
156
|
+
- lib/action_network_rest/tags.rb
|
103
157
|
- lib/action_network_rest/version.rb
|
104
158
|
homepage: https://github.com/controlshift/action-network-rest
|
105
159
|
licenses:
|
@@ -120,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
174
|
- !ruby/object:Gem::Version
|
121
175
|
version: '0'
|
122
176
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
177
|
+
rubygems_version: 3.0.8
|
124
178
|
signing_key:
|
125
179
|
specification_version: 4
|
126
180
|
summary: Ruby client for interacting with the ActionNetwork REST API
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2020 Grey Moore
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|