mobilize-america-client 0.3.6 → 0.5.0

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: 9a8aa2a6520cae7a352ffabce99976284b1348b63f16cdc29d9933fb7b5b0881
4
- data.tar.gz: d5a2a05390fc6f003042d345a16a2bf903cce4e130347207581f2b7ae5178863
3
+ metadata.gz: e61d4dfecfc193f37dd96467f4732e354b294743c4a6f7e5abe4fccbcfcdb2b4
4
+ data.tar.gz: 821a77b1fdacfef7e386c0c35c70b4e493d5249301c397d76eef9866d3c1624b
5
5
  SHA512:
6
- metadata.gz: a58a2cbc1e069b67a845e16db9a8e4954b63b9fb2f0842cf9fc4913974ca9589e16c6fc7d13e767e1b8837cf9711f85e7358e917ad555c53e17d8fd321142ff9
7
- data.tar.gz: c0995119c306cb4e1e96478401a3b91630a52c88990b72c1fe13ce137bd85c5cfe97c8aefbc991c6f601212b420f2d8554a1adfc02a66a3eafebc305fcb3c52d
6
+ metadata.gz: ba9c9de519868fc5f8f318f9b7d7ba01ab9050673f86847eb71f620e1cf013e5ef21ba10ba7d6b88292c9fd4642b79ff7d93078bcb8be238f5489d218615c22d
7
+ data.tar.gz: 52d4e7ec4b1f4d6e2380de88c20cd002126634e25339b5eb35433924d551222ac9fbf942a94ae81ffd7cd440b7119b6c71bc02fdb8341614fed76fcf94c120b8
@@ -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/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.4
1
+ 3.2.0
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.3.6
1
+ 0.5.0
@@ -0,0 +1,15 @@
1
+ module MobilizeAmericaClient
2
+ class Client
3
+ module Attendances
4
+ def organization_attendances(organization_id:, updated_since: nil)
5
+ params = {}
6
+
7
+ unless updated_since.nil?
8
+ params[:updated_since] = updated_since.to_i
9
+ end
10
+
11
+ get(path: "/organizations/#{esc(organization_id)}/attendances", params: params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module MobilizeAmericaClient
2
+ class Client
3
+ module Enums
4
+ def enums
5
+ get(path: '/enums')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,7 +2,8 @@ module MobilizeAmericaClient
2
2
  class Client
3
3
  module Events
4
4
  def organization_events(organization_id:, timeslot_start: nil, timeslot_end: nil, updated_since: nil,
5
- max_distance_miles: nil, page: nil, per_page: nil, zipcode: nil)
5
+ max_distance_miles: nil, page: nil, per_page: nil, zipcode: nil, event_campaign_id: nil,
6
+ tag_ids: nil, event_types: nil, is_virtual: nil, exclude_full: nil)
6
7
  params = {}
7
8
 
8
9
  unless page.nil?
@@ -33,6 +34,26 @@ module MobilizeAmericaClient
33
34
  end
34
35
  end
35
36
 
37
+ unless event_campaign_id.nil?
38
+ params[:event_campaign_id] = event_campaign_id.to_i
39
+ end
40
+
41
+ unless tag_ids.nil? || tag_ids.empty?
42
+ params[:tag_id] = tag_ids.join(',')
43
+ end
44
+
45
+ unless event_types.nil? || event_types.empty?
46
+ params[:event_types] = event_types.join(',')
47
+ end
48
+
49
+ unless is_virtual.nil?
50
+ params[:is_virtual] = is_virtual ? 'true' : 'false'
51
+ end
52
+
53
+ unless exclude_full.nil?
54
+ params[:exclude_full] = exclude_full ? 'true' : 'false'
55
+ end
56
+
36
57
  get(path: "/organizations/#{esc(organization_id)}/events", params: params)
37
58
  end
38
59
  end
@@ -40,5 +61,13 @@ module MobilizeAmericaClient
40
61
  def organization_event(organization_id:, event_id:)
41
62
  get(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}")
42
63
  end
64
+
65
+ def organization_event_attendances(organization_id:, event_id:)
66
+ get(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}/attendances")
67
+ end
68
+
69
+ def create_organization_event_attendance(organization_id:, event_id:, attendance_data:)
70
+ post(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}/attendances", body: attendance_data)
71
+ end
43
72
  end
44
73
  end
@@ -1,4 +1,6 @@
1
1
  require 'faraday'
2
+ require 'mobilize_america_client/client/attendances'
3
+ require 'mobilize_america_client/client/enums'
2
4
  require 'mobilize_america_client/client/events'
3
5
  require 'mobilize_america_client/client/organizations'
4
6
  require 'mobilize_america_client/request'
@@ -14,10 +16,12 @@ module MobilizeAmericaClient
14
16
 
15
17
  api_domain = options[:api_domain] || API_DOMAIN
16
18
 
17
- @connection = Faraday.new(url: "https://#{api_domain}")
19
+ @connection = Faraday.new(url: "https://#{api_domain}", request: { params_encoder: Faraday::FlatParamsEncoder })
18
20
  end
19
21
 
20
22
  include MobilizeAmericaClient::Request
23
+ include MobilizeAmericaClient::Client::Attendances
24
+ include MobilizeAmericaClient::Client::Enums
21
25
  include MobilizeAmericaClient::Client::Events
22
26
  include MobilizeAmericaClient::Client::Organizations
23
27
  end
@@ -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
@@ -6,7 +6,11 @@ module MobilizeAmericaClient
6
6
  API_BASE_PATH = '/v1'.freeze
7
7
 
8
8
  def get(path:, params: {})
9
- request(method: :get, path: path, params: params)
9
+ request(method: :get, path:, params:)
10
+ end
11
+
12
+ def post(path:, body:)
13
+ request(method: :post, path:, body:)
10
14
  end
11
15
 
12
16
  private
@@ -28,6 +32,10 @@ module MobilizeAmericaClient
28
32
  req.body = ::JSON.generate(body) unless body.empty?
29
33
  end
30
34
 
35
+ if response.status == 401
36
+ raise MobilizeAmericaClient::UnauthorizedError
37
+ end
38
+
31
39
  if response.status == 404
32
40
  raise MobilizeAmericaClient::NotFoundError
33
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.3.6 ruby lib
5
+ # stub: mobilize-america-client 0.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mobilize-america-client".freeze
9
- s.version = "0.3.6"
9
+ s.version = "0.5.0"
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 = "2021-09-14"
14
+ s.date = "2023-02-23"
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,16 @@ 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",
41
+ "lib/mobilize_america_client/client/enums.rb",
40
42
  "lib/mobilize_america_client/client/events.rb",
41
43
  "lib/mobilize_america_client/client/organizations.rb",
42
44
  "lib/mobilize_america_client/errors.rb",
43
45
  "lib/mobilize_america_client/request.rb",
44
46
  "mobilize-america-client.gemspec",
47
+ "spec/client/attendances_spec.rb",
45
48
  "spec/client/client_spec.rb",
49
+ "spec/client/enums_spec.rb",
46
50
  "spec/client/events_spec.rb",
47
51
  "spec/client/organizations_spec.rb",
48
52
  "spec/fixtures/organizations.json",
@@ -50,40 +54,18 @@ Gem::Specification.new do |s|
50
54
  ]
51
55
  s.homepage = "http://github.com/controlshift/mobilize_america_client".freeze
52
56
  s.licenses = ["MIT".freeze]
53
- s.rubygems_version = "3.0.9".freeze
57
+ s.rubygems_version = "3.4.3".freeze
54
58
  s.summary = "Client gem for the MobilizeAmerica API".freeze
55
59
 
56
- if s.respond_to? :specification_version then
57
- s.specification_version = 4
60
+ s.specification_version = 4
58
61
 
59
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
- s.add_runtime_dependency(%q<faraday>.freeze, ["> 0.15"])
61
- s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
62
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
63
- s.add_development_dependency(%q<rake>.freeze, [">= 0"])
64
- s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
65
- s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
66
- s.add_development_dependency(%q<dotenv>.freeze, [">= 0"])
67
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
68
- else
69
- s.add_dependency(%q<faraday>.freeze, ["> 0.15"])
70
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
71
- s.add_dependency(%q<juwelier>.freeze, [">= 0"])
72
- s.add_dependency(%q<rake>.freeze, [">= 0"])
73
- s.add_dependency(%q<webmock>.freeze, [">= 0"])
74
- s.add_dependency(%q<rubocop>.freeze, [">= 0"])
75
- s.add_dependency(%q<dotenv>.freeze, [">= 0"])
76
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
77
- end
78
- else
79
- s.add_dependency(%q<faraday>.freeze, ["> 0.15"])
80
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
81
- s.add_dependency(%q<juwelier>.freeze, [">= 0"])
82
- s.add_dependency(%q<rake>.freeze, [">= 0"])
83
- s.add_dependency(%q<webmock>.freeze, [">= 0"])
84
- s.add_dependency(%q<rubocop>.freeze, [">= 0"])
85
- s.add_dependency(%q<dotenv>.freeze, [">= 0"])
86
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
87
- end
62
+ s.add_runtime_dependency(%q<faraday>.freeze, ["> 0.15"])
63
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
64
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
65
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
66
+ s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
67
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
68
+ s.add_development_dependency(%q<dotenv>.freeze, [">= 0"])
69
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
88
70
  end
89
71
 
@@ -0,0 +1,50 @@
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
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe MobilizeAmericaClient::Client::Enums do
4
+ let(:standard_headers) { {'Content-Type' => 'application/json'} }
5
+
6
+ subject { MobilizeAmericaClient::Client.new }
7
+
8
+ let(:base_url) { "https://#{MobilizeAmericaClient::Client::API_DOMAIN}#{MobilizeAmericaClient::Client::API_BASE_PATH}" }
9
+
10
+ describe '#enums' do
11
+ let(:enums_url) { "#{base_url}/enums" }
12
+ let(:response) { {'hello' => 'world'} }
13
+
14
+ it 'should call the endpoint and return JSON' do
15
+ stub_request(:get, enums_url).with(headers: standard_headers).to_return(body: response.to_json)
16
+ expect(subject.enums).to eq response
17
+ end
18
+ end
19
+ end
@@ -75,6 +75,41 @@ RSpec.describe MobilizeAmericaClient::Client::Events do
75
75
  .to_return(body: response.to_json)
76
76
  expect(subject.organization_events(organization_id: org_id, page: 2, per_page: 100)).to eq(response)
77
77
  end
78
+
79
+ it 'should support an event campaign id parameter' do
80
+ stub_request(:get, events_url)
81
+ .with(headers: standard_headers, query: {event_campaign_id: 1})
82
+ .to_return(body: response.to_json)
83
+ expect(subject.organization_events(organization_id: org_id, event_campaign_id: 1)).to eq(response)
84
+ end
85
+
86
+ it 'should support a tag ids parameter' do
87
+ stub_request(:get, events_url)
88
+ .with(headers: standard_headers, query: {tag_id: 'foo,bar'})
89
+ .to_return(body: response.to_json)
90
+ expect(subject.organization_events(organization_id: org_id, tag_ids: ['foo', 'bar'])).to eq(response)
91
+ end
92
+
93
+ it 'should support an event types parameter' do
94
+ stub_request(:get, events_url)
95
+ .with(headers: standard_headers, query: {event_types: 'foo,bar'})
96
+ .to_return(body: response.to_json)
97
+ expect(subject.organization_events(organization_id: org_id, event_types: ['foo', 'bar'])).to eq(response)
98
+ end
99
+
100
+ it 'should support a virtual parameter' do
101
+ stub_request(:get, events_url)
102
+ .with(headers: standard_headers, query: {is_virtual: true})
103
+ .to_return(body: response.to_json)
104
+ expect(subject.organization_events(organization_id: org_id, is_virtual: true)).to eq(response)
105
+ end
106
+
107
+ it 'should support an exclude full parameter' do
108
+ stub_request(:get, events_url)
109
+ .with(headers: standard_headers, query: {exclude_full: true})
110
+ .to_return(body: response.to_json)
111
+ expect(subject.organization_events(organization_id: org_id, exclude_full: true)).to eq(response)
112
+ end
78
113
  end
79
114
 
80
115
  describe '#organization_event' do
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.3.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -150,12 +150,16 @@ 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
154
+ - lib/mobilize_america_client/client/enums.rb
153
155
  - lib/mobilize_america_client/client/events.rb
154
156
  - lib/mobilize_america_client/client/organizations.rb
155
157
  - lib/mobilize_america_client/errors.rb
156
158
  - lib/mobilize_america_client/request.rb
157
159
  - mobilize-america-client.gemspec
160
+ - spec/client/attendances_spec.rb
158
161
  - spec/client/client_spec.rb
162
+ - spec/client/enums_spec.rb
159
163
  - spec/client/events_spec.rb
160
164
  - spec/client/organizations_spec.rb
161
165
  - spec/fixtures/organizations.json
@@ -179,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
183
  - !ruby/object:Gem::Version
180
184
  version: '0'
181
185
  requirements: []
182
- rubygems_version: 3.1.6
186
+ rubygems_version: 3.4.3
183
187
  signing_key:
184
188
  specification_version: 4
185
189
  summary: Client gem for the MobilizeAmerica API