From bd05a43c17a49f6f901f76c42a68b90a16a72de5 Mon Sep 17 00:00:00 2001 From: Christopher Styles Date: Mon, 14 Mar 2016 13:08:00 -0700 Subject: [PATCH] Set up and configure ngp_van This update adds the `ngp_van` gem, and configures the app using an initializer. Sample environment configuration has been provided in the `.env.sample`. The `ngp_van` gem is currently private until the general election, and in order to install it you will need to authenticate Bundler to GitHub using an oauth access token. Please contact a team member in Slack for the correct token to use. Once you have the token, you can use [`bundler-config`](http://bundler.io/v1.11/man/bundle-config.1.html) to configure the project locally: bundle config --local GITHUB_OAUTH_TOKEN :x-oauth-basic Then `bundle install`. Configure the following environment variables in `.env` [[docs](http://developers.everyaction.com/van-api#van-authentication)]: ``` NGP_VAN_APPLICATION_NAME="YourApplicationName" NGP_VAN_API_KEY="ApiKey|Mode" ``` An `NgpVan` object will be available to interact with via the console: ```ruby % rails c [1] pry(main)> NgpVan.district_fields ``` API Methods can be called as module methods or as instance methods on the client. ```ruby [2] pry(main)> NgpVan.district_fields ``` or ```ruby [3] pry(main)> client = NpgVan.client [4] pry(main)> client.district_fields ``` Resolves #126 --- .env.sample | 2 ++ Gemfile | 2 ++ Gemfile.lock | 11 ++++++++++- README.md | 12 +++++++----- config/initializers/ngp_van.rb | 13 +++++++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 config/initializers/ngp_van.rb diff --git a/.env.sample b/.env.sample index 52515fa..592d90b 100644 --- a/.env.sample +++ b/.env.sample @@ -12,3 +12,5 @@ SENTRY_DSN= CORS_ORIGINS= MIN_COMPATIBLE_APP_VERSION= FORCE_SSL= +NGP_VAN_APPLICATION_NAME= +NGP_VAN_API_KEY= diff --git a/Gemfile b/Gemfile index 50899e7..cf51fc8 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,8 @@ gem 'newrelic_rpm' gem 'rack-cors', require: 'rack/cors' +gem 'ngp_van', git: 'https://github.com/christopherstyles/ngp_van.git' + group :development, :production do gem 'rails_12factor' end diff --git a/Gemfile.lock b/Gemfile.lock index 737c2c0..cf654ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,14 @@ GIT activemodel (>= 4.0) railties (>= 4.0) +GIT + remote: https://github.com/christopherstyles/ngp_van.git + revision: c5b32106c1727cca35ebbf8807acd140d049ccb5 + specs: + ngp_van (0.1.0) + faraday (~> 0.9.2) + faraday_middleware (~> 0.10.0) + GIT remote: https://github.com/thoughtbot/paperclip revision: 523bd46c768226893f23889079a7aa9c73b57d68 @@ -317,6 +325,7 @@ DEPENDENCIES koala leaderboard newrelic_rpm + ngp_van! oauth2 paperclip! parse-ruby-client @@ -340,4 +349,4 @@ DEPENDENCIES webmock BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/README.md b/README.md index 94bfe91..7582870 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,13 @@ Rails API for crowdsourced voter canvassing. ### Setup 1. Clone the repository (`git clone git@github.com:Bernie-2016/fieldthebern-api.git`) -2. Install gem dependencies: `bundle install` -3. Create and migrate the database: `rake db:setup` -4. Copy `.env.sample` to `.env`. Create test apps with the relevant services to get credentials. -5. Run `gem install foreman` to install the foreman gem, used for running Procfile-based apps. -6. Run `foreman start` to start the server. +2. Obtain an oauth access token for `ngp_van` from a team member in Slack. +3. Configure the project locally: `bundle config --local GITHUB_OAUTH_TOKEN :x-oauth-basic` +4. Install gem dependencies: `bundle install` +5. Create and migrate the database: `rake db:setup` +6. Copy `.env.sample` to `.env`. Create test apps with the relevant services to get credentials. +7. Run `gem install foreman` to install the foreman gem, used for running Procfile-based apps. +8. Run `foreman start` to start the server. ### Testing `http://api.lvh.me:5000/ping` diff --git a/config/initializers/ngp_van.rb b/config/initializers/ngp_van.rb new file mode 100644 index 0000000..7e3daac --- /dev/null +++ b/config/initializers/ngp_van.rb @@ -0,0 +1,13 @@ +ngp_van_enabled = %w( + NGP_VAN_APPLICATION_NAME + NGP_VAN_API_KEY +).all? { |key| ENV.key? key } + +if ngp_van_enabled + require 'ngp_van' + + NgpVan.configure do |config| + config.application_name = ENV['NGP_VAN_APPLICATION_NAME'] + config.api_key = ENV['NGP_VAN_API_KEY'] + end +end