action_network_rest 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -4
- data/lib/action_network_rest.rb +4 -0
- data/lib/action_network_rest/base.rb +42 -0
- data/lib/action_network_rest/client.rb +8 -0
- data/lib/action_network_rest/entry_point.rb +21 -0
- data/lib/action_network_rest/people.rb +6 -11
- data/lib/action_network_rest/petitions.rb +37 -0
- data/lib/action_network_rest/signatures.rb +29 -0
- data/lib/action_network_rest/version.rb +1 -1
- metadata +6 -3
- 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: cc85d83854d521199b82e855ee4369c66c076a8487753756cc454010a0a22907
|
4
|
+
data.tar.gz: 684db90a396a39ebbdc54ffec3fcdba678a2338fbc334052786f7422d4990eb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5f2ece5e76ef8bfbffd96349eb0c545c423da441a318fab71458d86f7ebfd483a4bc7f512f25df73ad9a5f1acfc32a1f60e1acb69770f5b0c75b8b695420ec
|
7
|
+
data.tar.gz: '0897288683f87fc8a9a273d360bf01bbbcf0da24bf7d90ffbb1176299a79f376a01d55e57af7a7680a771c8787579f78353eb5d32a08b0691d131b76f4431b45'
|
data/README.md
CHANGED
@@ -23,13 +23,46 @@ Or install it yourself as:
|
|
23
23
|
```
|
24
24
|
client = ActionNetworkRest.new(api_key: YOUR_API_KEY)
|
25
25
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
26
|
+
# Check that our API key is working. Returns true or false.
|
27
|
+
client.entry_point.authenticated_successfully?
|
28
|
+
|
29
|
+
# See information about Action Network API endpoints
|
30
|
+
client.entry_point.get
|
29
31
|
|
30
32
|
# Create a new Person
|
31
33
|
person = client.people.create(email_addresses: [{address: 'foo@example.com'}])
|
32
|
-
|
34
|
+
person_id = person.action_network_id
|
35
|
+
|
36
|
+
# Retrieve a Person's data
|
37
|
+
person = client.people.get(person_id)
|
38
|
+
puts person.email_addresses
|
39
|
+
|
40
|
+
# Unsubscribe a Person
|
41
|
+
client.people.unsubscribe(person_id)
|
42
|
+
|
43
|
+
# Create a new Petition
|
44
|
+
petition = client.petitions.create({title: 'Do the Thing!'}, creator_person_id: person_id)
|
45
|
+
petition_id = petition.action_network_id
|
46
|
+
|
47
|
+
# Retrieve a Petition
|
48
|
+
petition = client.petitions.get(petition_id)
|
49
|
+
puts petition.title
|
50
|
+
|
51
|
+
# Update a Petition
|
52
|
+
client.petitions.update(petition_id, {description: 'An updated description'})
|
53
|
+
|
54
|
+
# Create a Signature on a Petition
|
55
|
+
signature = client.petitions(petition_id).signatures.create({comments: 'This is so important',
|
56
|
+
person: {email_addresses: [{address: 'alice@example.com'}]}},
|
57
|
+
tags: ['volunteer'])
|
58
|
+
signature_id = signature.action_network_id
|
59
|
+
|
60
|
+
# Retrieve a Signature
|
61
|
+
signature = client.petitions(petition_id).signatures.get(signature_id)
|
62
|
+
puts signature.created_date
|
63
|
+
|
64
|
+
# Update a Signature
|
65
|
+
client.petitions(petition_id).signatures.update(signature_id, {comments: 'new comments'})
|
33
66
|
```
|
34
67
|
|
35
68
|
## Development
|
data/lib/action_network_rest.rb
CHANGED
@@ -12,5 +12,9 @@ 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'
|
@@ -0,0 +1,42 @@
|
|
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
|
+
private
|
9
|
+
|
10
|
+
def url_escape(string)
|
11
|
+
CGI.escape(string.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def object_from_response(response)
|
15
|
+
obj = response.body
|
16
|
+
|
17
|
+
# The response we get from Action Network may contain an "identifiers" block that looks something like:
|
18
|
+
#
|
19
|
+
# "identifiers": [
|
20
|
+
# "action_network:d6bdf50e-c3a4-4981-a948-3d8c086066d7",
|
21
|
+
# "some_external_system:1",
|
22
|
+
# "another_external_system:57"
|
23
|
+
# ]
|
24
|
+
#
|
25
|
+
# If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
|
26
|
+
# for the convenience of callers using the returned object.
|
27
|
+
identifiers = obj[:identifiers] || []
|
28
|
+
qualified_actionnetwork_id = identifiers.find do |id|
|
29
|
+
id.split(':').first == 'action_network'
|
30
|
+
end
|
31
|
+
if qualified_actionnetwork_id.present?
|
32
|
+
obj.action_network_id = qualified_actionnetwork_id.sub(/^action_network:/, '')
|
33
|
+
end
|
34
|
+
|
35
|
+
obj
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_network_url(path)
|
39
|
+
client.connection.configuration.endpoint + path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -23,8 +23,16 @@ 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
|
+
@_petitions ||= ActionNetworkRest::Petitions.new(petition_id, client: self)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
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,13 @@ module ActionNetworkRest
|
|
16
11
|
end
|
17
12
|
|
18
13
|
response = client.post_request base_path, post_body
|
19
|
-
response
|
14
|
+
object_from_response(response)
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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 get(id)
|
10
|
+
response = client.get_request "#{base_path}#{url_escape(id)}"
|
11
|
+
object_from_response(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(signature_data, tags: [])
|
15
|
+
post_body = signature_data
|
16
|
+
if tags.any?
|
17
|
+
post_body['add_tags'] = tags
|
18
|
+
end
|
19
|
+
|
20
|
+
response = client.post_request base_path, post_body
|
21
|
+
object_from_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(id, signature_data)
|
25
|
+
response = client.put_request "#{base_path}#{url_escape(id)}", signature_data
|
26
|
+
object_from_response(response)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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.2.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-04-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vertebrae
|
@@ -93,13 +93,16 @@ files:
|
|
93
93
|
- CODE_OF_CONDUCT.md
|
94
94
|
- Gemfile
|
95
95
|
- LICENSE
|
96
|
-
- LICENSE.txt
|
97
96
|
- README.md
|
98
97
|
- Rakefile
|
99
98
|
- action_network_rest.gemspec
|
100
99
|
- lib/action_network_rest.rb
|
100
|
+
- lib/action_network_rest/base.rb
|
101
101
|
- lib/action_network_rest/client.rb
|
102
|
+
- lib/action_network_rest/entry_point.rb
|
102
103
|
- lib/action_network_rest/people.rb
|
104
|
+
- lib/action_network_rest/petitions.rb
|
105
|
+
- lib/action_network_rest/signatures.rb
|
103
106
|
- lib/action_network_rest/version.rb
|
104
107
|
homepage: https://github.com/controlshift/action-network-rest
|
105
108
|
licenses:
|
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.
|