Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .document

This file was deleted.

18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
name: CI
on: [push]
on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: ['3.2', '3.3', '3.4', '4.0']
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle install
- run: bundle exec rspec
- run: bundle exec rake
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--color
--require spec_helper
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins:
- rubocop-rspec

AllCops:
TargetRubyVersion: 3.2
NewCops: enable
SuggestExtensions: false

Layout/LineLength:
Max: 120

Style/Documentation:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/ExampleLength:
Max: 15

Metrics/ParameterLists:
CountKeywordArgs: false
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

## 1.0.0

Breaking:

- Requires Ruby 3.2 or later.
- Built on Faraday 2 instead of oauth2. The client authenticates with an access token only:
`NationBuilder.new(hostname:, token:)`. `client_id`, `client_secret`, `username` and `password` are gone.
- Errors are `NationBuilder::Error` and its subclasses `NotFoundError`, `ValidationError` and `RateLimitedError`,
instead of `OAuth2::Error`. `NationBuilder::Exceptions::ValidationError` is now `NationBuilder::ValidationError`.
- No longer depends on activesupport or pins json.
- `People#create_or_update` and `People#match_or_add` are removed; compose `match` with `add`/`update` instead.
- `People#delete_tagging` returns nil and raises on failure.
- `Tags#people` now calls `tags/:tag/people`, and tag names are escaped as path segments (`%20`, not `+`).
- Instrumentation also replaces trailing numeric IDs, e.g. `people/123` becomes `people/_`.

Other:

- Request timeouts default to 10s open / 30s read.
- Replaced juwelier with a plain gemspec and Bundler's gem tasks; CI runs RuboCop and RSpec on Ruby 3.2–4.0.
21 changes: 9 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
source 'http://rubygems.org'
# frozen_string_literal: true

# NationBuilder puts error messages in a different location.
gem 'oauth2', git: 'https://github.com/controlshift/oauth2.git'
gem 'json', '~> 2.1'
gem 'activesupport', '>3.0.0'
source 'https://rubygems.org'

group :development do
gem 'webmock', '~> 3.0', '>= 3.0.1'
gem 'byebug', '~> 9.0', '>= 9.0.6'
gem 'rspec', '~> 3.6'
gem 'bundler', '>= 0'
gem 'juwelier', '~> 2.4', '>= 2.4.7'
end
gemspec

gem 'rake'
gem 'rspec', '~> 3.13'
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'webmock', '~> 3.23'
48 changes: 30 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
# nation_builder

A very simple ruby gem for interacting with NB people API.
[![CI](https://github.com/controlshift/nation_builder/actions/workflows/ci.yml/badge.svg)](https://github.com/controlshift/nation_builder/actions/workflows/ci.yml)

http://nationbuilder.com/api_documentation
A small Ruby client for the [NationBuilder v1 API](https://nationbuilder.com/api_documentation) people and tags
endpoints, built on Faraday.

### Usage
## Usage

```
The client takes an OAuth 2.0 access token. Obtaining one (the authorisation code flow) is left to your application.

```ruby
require 'nation_builder'
client = NationBuilder.new(hostname: 'whatever.nationbuilder.com', client_id: 'id', client_secret: 'secret', username: 'you@nation.com', password: 'pass')
client.people.create('person' => {'first_name' => 'George', 'last_name' => 'Washington', 'email' => 'george@washington.com'})
client.people.match('email' => 'george@washington.com) # either a person hash or nil.
client.people.list # returns people in nation
client.tags.list # all tags.

client = NationBuilder.new(hostname: 'mynation.nationbuilder.com', token: access_token)

client.people.match('email' => 'george@example.com') # person hash, or nil when there is no match
client.people.add('person' => { 'email' => 'george@example.com', 'first_name' => 'George' })
client.people.update(17, 'person' => { 'email_opt_in' => false })
client.people.add_tagging(17, 'volunteer')
client.tags.list
```

### Contributing
Optional keyword arguments: `logger:` (logs rate limit headers), `instrumentation:` (a callable invoked before each
request with `{ path:, request_type: }`), `adapter:`, `open_timeout:` and `timeout:`.

The current gem is minimalist -- but we'd welcome pull requests with additional functionality!
### Errors

[![CI Status](https://github.com/controlshift/nation_builder/actions/workflows/ci.yml/badge.svg)](https://github.com/controlshift/nation_builder/actions/workflows/ci.yml)
Non-2xx responses raise `NationBuilder::Error`, which exposes `status`, `code` (NationBuilder's error code) and
`body`. Subclasses: `NotFoundError`, `ValidationError` (`#errors`) and `RateLimitedError` (`#limit`, `#remaining`,
`#reset_at`).

### Release
## Development

```
rake version:bump:minor
BRANCH=main rake release
bundle install
bundle exec rake # rubocop + rspec
```

### Copyright
## Release

Bump `NationBuilder::VERSION` in `lib/nation_builder/version.rb`, update `CHANGELOG.md`, merge, then
`bundle exec rake release`.

Copyright (c) 2013 ControlShift Ltd. See LICENSE.txt for
further details.
## Copyright

Copyright (c) 2013 ControlShift Ltd. See LICENSE.txt for further details.
51 changes: 6 additions & 45 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'

require 'juwelier'
Juwelier::Tasks.new do |gem|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
gem.name = "nation_builder"
gem.homepage = "http://github.com/controlshift/nation_builder"
gem.license = "MIT"
gem.summary = "NationBuilder API wrapper"
gem.description = %Q{Ruby wrapper for NationBuilder API}
gem.email = "nathan@controlshiftlabs.com"
gem.authors = ["Nathan Woodhull", "Dan Schneiderman"]
# dependencies defined in Gemfile
end
Juwelier::RubygemsDotOrgTasks.new

require 'rspec/core'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

task :default => :spec
require 'rubocop/rake_task'

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "nation_builder #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
task default: %i[rubocop spec]
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

46 changes: 10 additions & 36 deletions lib/nation_builder.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
require 'oauth2'
require 'active_support/all'
require 'nation_builder/exceptions/validation_error'
require 'nation_builder/actions/show'
require 'nation_builder/actions/list'
require 'nation_builder/actions/update'
require 'nation_builder/actions/create'
# frozen_string_literal: true

require 'faraday'
require 'nation_builder/version'
require 'nation_builder/errors'
require 'nation_builder/client'
require 'nation_builder/remote_controller'
require 'nation_builder/tags'
require 'nation_builder/resource'
require 'nation_builder/people'

require 'nation_builder/tags'

module NationBuilder

class << self
# Initializes a new NationBuilder client
#
# @param [Hash] options the options to make the request with
# @option options [String] :client_id client ID used for OAuth 2.0 authenticated requests
# @option options [String] :client_secret secret used for OAuth 2.0 authenticated requests
# @option options [String] :hostname NationBuilder site hostname, must not include protocol (i.e.: 'http://')
# @option options [String] :token OAuth2 access token used for perform authenticated calls. Not required if performing authenticated calls with :username and :password
# @option options [String] :username username used for getting a OAuth 2.0 access token. Not required if performing authenticated calls with :token
# @option options [String] :password password used for getting a OAuth 2.0 access token. Not required if performing authenticated calls with :token
# @option options [Proc] :instrumentation block of code to be invoked on every request to NationBuilder. Should receive a single Hash argument that includes :path and :request_type.
# :path argument is normalized, replacing IDs with '_'
# @option options [Logger] :logger optional. If provided, rate limit related headers from successful responses will be logged.
def new(options = {})
NationBuilder::Client.new(options)
end

def method_missing(method, *args)
return super unless new.respond_to?(method)
new.send(method, *args)
end

def respond_to?(method, include_private = false)
new.respond_to?(method, include_private) || super(method, include_private)
end
# Shorthand for NationBuilder::Client.new
def self.new(...)
Client.new(...)
end
end
10 changes: 0 additions & 10 deletions lib/nation_builder/actions/create.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/nation_builder/actions/list.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/nation_builder/actions/show.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/nation_builder/actions/update.rb

This file was deleted.

Loading
Loading