nationbuilder-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a79348cf6dff6bc6705e08d2144cf90c6afbe4ab10657e51ccb204cdc973dbb2
4
- data.tar.gz: 3f17828873cb5e2f6e68b7a5801084fbcea27974bfbf9dd42056db5d44a4c026
3
+ metadata.gz: 2d2f6784e1cc972b7e4768b529fe766325a180a2b88d62b6f96746f2d041d220
4
+ data.tar.gz: 5d4ef33738835838b845bce05728d879586f701f9b7127454d80230a98ecd776
5
5
  SHA512:
6
- metadata.gz: f1ffc914085d349b0fbe750218383cead745f9a8296aa77fe921a219bee74d9cda04ea7f1055afdcad886b655efa083d4e19521c62b49d55144940e35bbe0cd0
7
- data.tar.gz: 1daf6bea9055d07b87554630653fb5ba7f1518f7a13778cd6bda847e244f8fcc860347e0d0b0fc75acc346d69745162271c53d1e896bbaddd7216262eb43da72
6
+ metadata.gz: be5debdb622f30ae69d68c7beaf75fbc2e202964b06c4550dd2e3d471213b89c3eb5f68c0804cbc13e1a4d479d5af1b3d53b2039adde3931cd79d99f534ff0d6
7
+ data.tar.gz: 1b0541f110196d0457745236b069d9006d5fd622dc48926f3041d6da08bb7b297afff57c8b9db91c1b925cdec0be70e09e5741ef36ba8bc9450cedd332c427d4
data/README.md CHANGED
@@ -1,24 +1,32 @@
1
- # NationBuilder
1
+ # NationBuilder API Client
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nationbuilder/api`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A simple, flexible NationBuilder API client that is compatible with V1 and V2 APIs, using the OAuth2 authentication and refresh flows, and respects the "retry-after" rate limiting headers.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
8
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ $ bundle add nationbuilder-api
14
10
 
15
11
  If bundler is not being used to manage dependencies, install the gem by executing:
16
12
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install nationbuilder-api
18
14
 
19
15
  ## Usage
20
16
 
21
- TODO: Write usage instructions here
17
+ The gem expects that you have a "nation" object that has attributes for `slug`, `token`, `refresh_token`, `token_expires_at`. This could be an ActiveModel object, or a simple hash.
18
+
19
+ Create a client with `client = NationBuilder::Client.new(nation)`
20
+
21
+ Then make API calls with that client with `response = client.call(:get, "/api/v1/people")`
22
+
23
+ `response` will contain `{code: 200, status: :success, body: {...}}`
24
+
25
+ For `put` or `post` calls, include the body like so `response = client.call(:put, "/api/v1/people/2", {person: {first_name: "Alex"}})`
26
+
27
+ ## Todo
28
+
29
+ Still need to implement token refreshing.
22
30
 
23
31
  ## Development
24
32
 
@@ -28,7 +36,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
36
 
29
37
  ## Contributing
30
38
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nationbuilder-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/nationbuilder-api/blob/main/CODE_OF_CONDUCT.md).
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/acflint/nationbuilder-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/acflint/nationbuilder-api/blob/main/CODE_OF_CONDUCT.md).
32
40
 
33
41
  ## License
34
42
 
@@ -36,4 +44,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
36
44
 
37
45
  ## Code of Conduct
38
46
 
39
- Everyone interacting in the NationBuilder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nationbuilder-api/blob/main/CODE_OF_CONDUCT.md).
47
+ Everyone interacting in the NationBuilder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/acflint/nationbuilder-api/blob/main/CODE_OF_CONDUCT.md).
@@ -43,7 +43,7 @@ class NationBuilder::Client
43
43
  elsif response.code == 429 && response.headers["retry-after"]
44
44
  sleep(response.headers["retry-after"].to_i + 1)
45
45
  call(action, path, body)
46
- elsif expired_token_error?(response_body) && @nation.refresh_oauth_token
46
+ elsif expired_token_error?(response_body) && refresh_oauth_token
47
47
  call(action, path, body)
48
48
  else
49
49
  raise OAuth2::Error.new(response)
@@ -52,6 +52,11 @@ class NationBuilder::Client
52
52
 
53
53
  private
54
54
 
55
+ def refresh_oauth_token
56
+ # TODO: implement
57
+ raise OAuth2::Error.new("token expired")
58
+ end
59
+
55
60
  def response_status(code)
56
61
  case code
57
62
  when 200, 201, 202, 204
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NationBuilder
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -13,8 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
-
18
16
  spec.metadata["homepage_uri"] = spec.homepage
19
17
  spec.metadata["source_code_uri"] = spec.homepage
20
18
  spec.metadata["changelog_uri"] = spec.homepage
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nationbuilder-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Flint