mobilize-america-client 0.4.0 → 0.5.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: 12aa69da81126f0f2d45a23926cf1c72f0c50b6043b14be748a67683763a6ba7
4
- data.tar.gz: cab2e8b1f0b12122d3fbd6ef4752b1f14fe1eac360b58515654af74795a93e47
3
+ metadata.gz: 3be8d8de92d42072ed7e068bc049479f01132a72e957ca4646bf54247eeb17df
4
+ data.tar.gz: 4956ea1496d3da6895fd07a3ab051781b93f4e9606468989ce7cdad33816bfe2
5
5
  SHA512:
6
- metadata.gz: 42e2b43747a196c8a0cdf27dd787e8cc650fddbbf04a44fd0af3cfdc7a163d429aef5790221d590eac87d87e5c2eb7183749417738dddc04c8ad914ca905e1bd
7
- data.tar.gz: beb749323b9cc4f0e3e019ad7da3b7bef61afac440003f7537939e3f8f1672ff6f9da6bf6688b821217d71d020129e9f4764f5533c17fcf0d320f6ff57f9129f
6
+ metadata.gz: 710e02c68d9f508259129cbb5cf8b16de836c02d5d8c2a9943d1a60489c8c2775c82dff77afb8c0ed54e2b81e861c5be71feefd82e9e0f0c045b6094f76706d1
7
+ data.tar.gz: fe215dcaabe4358f455cfffbd900ab29ab203d11d25c8b8f9675100d65751c889f2a38fe6a71151fcd134b268940ad1118efc8d2d9780c57383c7e4e4d211c73
@@ -6,9 +6,9 @@ jobs:
6
6
  runs-on: ubuntu-latest
7
7
  steps:
8
8
  - uses: actions/checkout@v2
9
- - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
9
+ - uses: ruby/setup-ruby@v1
10
10
  with:
11
- ruby-version: 2.7
11
+ ruby-version: 3.2.1
12
12
  bundler-cache: true
13
13
  - run: bundle install
14
14
  - run: bundle exec rspec
@@ -16,9 +16,9 @@ jobs:
16
16
  runs-on: ubuntu-latest
17
17
  steps:
18
18
  - uses: actions/checkout@v2
19
- - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
19
+ - uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 2.7
21
+ ruby-version: 3.2.1
22
22
  bundler-cache: true
23
23
  - run: bundle install
24
24
  - run: bundle exec rubocop
data/README.md CHANGED
@@ -22,12 +22,12 @@ Or install it yourself as:
22
22
 
23
23
  ## Configuration
24
24
 
25
- By default, the client accesses the public production instance without authentication.
25
+ By default, the client accesses the public production instance without authentication.
26
26
 
27
27
  `client = MobilizeAmericaClient::Client.new`
28
28
 
29
29
  It is also possible to provide an API key to the client to make authenticated requests, or to specify
30
- other endpoints.
30
+ other endpoints.
31
31
 
32
32
  `client = MobilizeAmericaClient::Client.new(api_key: 'abc123', api_domain: 'staging-api.mobilize.us')`
33
33
 
@@ -37,13 +37,18 @@ other endpoints.
37
37
  Retrieve a list of organizations
38
38
  `client.organizations(page: 2, per_page: 50)`
39
39
 
40
-
41
40
  Retrieve a list of an organization's events
42
41
  `client.organization_events(organization_id: 123)`
43
42
 
44
43
  Retrieve a specific event
45
44
  `client.organization_event(organization_id: 123, event_id: 123)`
46
45
 
46
+ Retrieve a list of attendances for a specific event
47
+ `client.organization_event_attendances(organization_id: 123, event_id: 123)`
48
+
49
+ Retrieve a list of an organization's attendandes
50
+ `client.organization_attendances(organization_id: 123)`
51
+
47
52
 
48
53
  ## Development
49
54
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.1
@@ -0,0 +1,23 @@
1
+ module MobilizeAmericaClient
2
+ class Client
3
+ module Attendances
4
+ def organization_attendances(organization_id:, updated_since: nil, page: nil, per_page: nil)
5
+ params = {}
6
+
7
+ unless updated_since.nil?
8
+ params[:updated_since] = updated_since.to_i
9
+ end
10
+
11
+ unless page.nil?
12
+ params[:page] = page
13
+ end
14
+
15
+ unless per_page.nil?
16
+ params[:per_page] = per_page
17
+ end
18
+
19
+ get(path: "/organizations/#{esc(organization_id)}/attendances", params: params)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'mobilize_america_client/client/attendances'
2
3
  require 'mobilize_america_client/client/enums'
3
4
  require 'mobilize_america_client/client/events'
4
5
  require 'mobilize_america_client/client/organizations'
@@ -19,6 +20,7 @@ module MobilizeAmericaClient
19
20
  end
20
21
 
21
22
  include MobilizeAmericaClient::Request
23
+ include MobilizeAmericaClient::Client::Attendances
22
24
  include MobilizeAmericaClient::Client::Enums
23
25
  include MobilizeAmericaClient::Client::Events
24
26
  include MobilizeAmericaClient::Client::Organizations
@@ -1,4 +1,7 @@
1
1
  module MobilizeAmericaClient
2
2
  class NotFoundError < StandardError
3
3
  end
4
+
5
+ class UnauthorizedError < StandardError
6
+ end
4
7
  end
@@ -32,6 +32,10 @@ module MobilizeAmericaClient
32
32
  req.body = ::JSON.generate(body) unless body.empty?
33
33
  end
34
34
 
35
+ if response.status == 401
36
+ raise MobilizeAmericaClient::UnauthorizedError
37
+ end
38
+
35
39
  if response.status == 404
36
40
  raise MobilizeAmericaClient::NotFoundError
37
41
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mobilize-america-client 0.4.0 ruby lib
5
+ # stub: mobilize-america-client 0.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mobilize-america-client".freeze
9
- s.version = "0.4.0"
9
+ s.version = "0.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Grey Moore".freeze]
14
- s.date = "2023-02-20"
14
+ s.date = "2023-03-02"
15
15
  s.email = "grey@controlshiftlabs.com".freeze
16
16
  s.executables = ["console".freeze, "setup".freeze]
17
17
  s.extra_rdoc_files = [
@@ -37,12 +37,14 @@ Gem::Specification.new do |s|
37
37
  "example.rb",
38
38
  "lib/mobilize_america_client.rb",
39
39
  "lib/mobilize_america_client/client.rb",
40
+ "lib/mobilize_america_client/client/attendances.rb",
40
41
  "lib/mobilize_america_client/client/enums.rb",
41
42
  "lib/mobilize_america_client/client/events.rb",
42
43
  "lib/mobilize_america_client/client/organizations.rb",
43
44
  "lib/mobilize_america_client/errors.rb",
44
45
  "lib/mobilize_america_client/request.rb",
45
46
  "mobilize-america-client.gemspec",
47
+ "spec/client/attendances_spec.rb",
46
48
  "spec/client/client_spec.rb",
47
49
  "spec/client/enums_spec.rb",
48
50
  "spec/client/events_spec.rb",
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe MobilizeAmericaClient::Client::Attendances do
4
+ let(:api_key) { 'abcde-123456' }
5
+ let(:expected_headers) { {'Content-Type' => 'application/json', 'Authorization' => "Bearer #{api_key}"} }
6
+ let(:base_url) { "https://#{MobilizeAmericaClient::Client::API_DOMAIN}#{MobilizeAmericaClient::Client::API_BASE_PATH}" }
7
+
8
+ subject { MobilizeAmericaClient::Client.new(api_key: api_key) }
9
+
10
+ describe '#organization_attendances' do
11
+ let(:org_id) { 123 }
12
+ let(:attendances_url) { "#{base_url}/organizations/#{org_id}/attendances" }
13
+ let(:response) { {'data' => [{'id' => 1, 'event' => {'id' => 1111}}, {'id' => 2, 'event' => {'id' => 2222}}]} }
14
+
15
+ context 'unauthenticated request' do
16
+ let(:api_key) { nil }
17
+
18
+ it 'should raise if response status is 401' do
19
+ stub_request(:get, attendances_url).with(headers: {'Content-Type' => 'application/json'}).to_return(status: 401, body: {error: 'unauthorized'}.to_json)
20
+
21
+ expect { subject.organization_attendances(organization_id: org_id) }.to raise_error MobilizeAmericaClient::UnauthorizedError
22
+ end
23
+ end
24
+
25
+ it 'should raise if response status is 404' do
26
+ stub_request(:get, attendances_url).with(headers: expected_headers).to_return(status: 404, body: {error: 'not found'}.to_json)
27
+
28
+ expect { subject.organization_attendances(organization_id: org_id) }.to raise_error MobilizeAmericaClient::NotFoundError
29
+ end
30
+
31
+ it 'should call the endpoint and return JSON' do
32
+ stub_request(:get, attendances_url).with(headers: expected_headers).to_return(body: response.to_json)
33
+ expect(subject.organization_attendances(organization_id: org_id)).to eq(response)
34
+ end
35
+
36
+ it 'should escape the organization ID' do
37
+ expected_url = "#{base_url}/organizations/foo%2Fbar/attendances"
38
+ stub_request(:get, expected_url).with(headers: expected_headers).to_return(body: response.to_json)
39
+ expect(subject.organization_attendances(organization_id: 'foo/bar')).to eq(response)
40
+ end
41
+
42
+ it 'should support an updated_since parameter' do
43
+ updated_since = Time.new
44
+ stub_request(:get, attendances_url)
45
+ .with(headers: expected_headers, query: {updated_since: updated_since.to_i})
46
+ .to_return(body: response.to_json)
47
+ expect(subject.organization_attendances(organization_id: org_id, updated_since: updated_since)).to eq(response)
48
+ end
49
+
50
+ it 'should support pagination parameters' do
51
+ stub_request(:get, attendances_url)
52
+ .with(headers: expected_headers, query: {page: 2, per_page: 100})
53
+ .to_return(body: response.to_json)
54
+ expect(subject.organization_attendances(organization_id: org_id, page: 2, per_page: 100)).to eq(response)
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilize-america-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -150,12 +150,14 @@ files:
150
150
  - example.rb
151
151
  - lib/mobilize_america_client.rb
152
152
  - lib/mobilize_america_client/client.rb
153
+ - lib/mobilize_america_client/client/attendances.rb
153
154
  - lib/mobilize_america_client/client/enums.rb
154
155
  - lib/mobilize_america_client/client/events.rb
155
156
  - lib/mobilize_america_client/client/organizations.rb
156
157
  - lib/mobilize_america_client/errors.rb
157
158
  - lib/mobilize_america_client/request.rb
158
159
  - mobilize-america-client.gemspec
160
+ - spec/client/attendances_spec.rb
159
161
  - spec/client/client_spec.rb
160
162
  - spec/client/enums_spec.rb
161
163
  - spec/client/events_spec.rb