Skip to content

Repository files navigation

ActionNetworkRest

Ruby client for interacting with the ActionNetwork REST API from the engineering team at ControlShift.

CI Status

Requirements

  • Ruby 3.3, 3.4, or 4.0
  • Faraday ~> 2.0

Installation

Add this line to your application's Gemfile:

gem'action_network_rest'

And then execute:

$ bundle

Or install it yourself as:

$ gem install action_network_rest

Usage

require'action_network_rest'client=ActionNetworkRest.new(api_key: YOUR_API_KEY)# Check that our API key is working. Returns true or false.client.entry_point.authenticated_successfully?# See information about Action Network API endpointsclient.entry_point.get# Create a new Personperson=client.people.create(email_addresses: [{address: 'foo@example.com'}])person_id=person.action_network_id# List peoplepeople=client.people.list# List all peoplepeople=client.people.all# Iterate over a list of peoplepage_number=1loopdopeople=client.people.list(page: page_number)breakifpeople.empty?page_number += 1end# Retrieve a Person's dataperson=client.people.get(person_id)putsperson.email_addresses# Retrieve a Person's data by their email addressperson=client.people.find_by_email(person_email)person_id=person.action_network_idputsperson.email_addresses# Retrieve a Person's data by their phone_numberperson=client.people.find_by_phone_number('+12223334444')person_id=person.action_network_idputsperson.phone_numbers# Update a Personclient.people.update(person_id,{custom_fields: {custom_id: "12345"}})# Unsubscribe a Personclient.people.unsubscribe(person_id)# Create a new Petitionpetition=client.petitions.create({title: 'Do the Thing!'},creator_person_id: person_id)petition_id=petition.action_network_id# Retrieve a Petitionpetition=client.petitions.get(petition_id)putspetition.title# Update a Petitionclient.petitions.update(petition_id,{description: 'An updated description'})# Create a Signature on a Petitionsignature=client.petitions(petition_id).signatures.create({comments: 'This is so important',person: {email_addresses: [{address: 'alice@example.com'}]}},tags: ['volunteer'])signature_id=signature.action_network_id# Retrieve a Signaturesignature=client.petitions(petition_id).signatures.get(signature_id)putssignature.created_date# Update a Signatureclient.petitions(petition_id).signatures.update(signature_id,{comments: 'new comments'})# Create a Tagtag=client.tags.create('Volunteers')tag_id=tag.action_network_id# Retrieve a Tagtag=client.tags.get(tag_id)# Retrieve a Tag by nametag=client.tags.find_by_name('Volunteers')# Apply a Tag to a Persontagging=client.tags(tag_id).create({identifiers: ['external:123']},person_id: person_id)tagging_id=tagging.action_network_id# Retrieve a Taggingtagging=client.tags(tag_id).taggings.get(tagging_id)# Delete a Taggingclient.tags(tag_id).taggings.delete(tagging_id)# List Events in an Event Campaignevent_campaign_id='123e4567-e89b-12d3-a456-426614174000'client.event_campaigns(event_campaign_id).events.list# Add an Attendanceevent_id='123e4567-e89b-12d3-a456-426655440000'client.events(event_id).attendances.create({person: {email_addresses: [{address: 'alice@example.com'}]}})# Get, list, or list all campaignsclient.campaigns.get('123e4567-e89b-12d3-a456-426614174000')client.campaigns.listclient.campaigns.all# Get, list, list all, create or update Advocacy Campaignsclient.advocacy_campaigns.listclient.advocacy_campaigns.allclient.advocacy_campaigns.create({title: "My Free Advocacy Campaign",origin_system: "FreeAdvocacy.com",type: "email"})client.advocacy_campaigns.get('123e4567-e89b-12d3-a456-426614174000')client.advocacy_campaigns.update('123e4567-e89b-12d3-a456-426614174000',{title: "My Free Advocacy Campaign With A New Name",description: "This is my free advocacy campaign description"})# Get, list, list all, create or update formssclient.form.listclient.form.allclient.form.create({title: "My Free Form",origin_system: "FreeForm.com"})client.form.get('123e4567-e89b-12d3-a456-426614174000')client.form.update('123e4567-e89b-12d3-a456-426614174000',{title: "My Free Form With A New Name",description: "This is my free form description"})

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.

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.

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.

Contributing

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 code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ActionNetworkRest project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Ruby client for interacting with the ActionNetwork REST API

Resources

Code of conduct

Stars

10 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages