diff --git a/.ruby-version b/.ruby-version index a4dd9db..944880f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.4 +3.2.0 diff --git a/lib/mobilize_america_client/client.rb b/lib/mobilize_america_client/client.rb index e1af6e2..a992cfd 100644 --- a/lib/mobilize_america_client/client.rb +++ b/lib/mobilize_america_client/client.rb @@ -1,4 +1,5 @@ require 'faraday' +require 'mobilize_america_client/client/enums' require 'mobilize_america_client/client/events' require 'mobilize_america_client/client/organizations' require 'mobilize_america_client/request' @@ -14,10 +15,11 @@ def initialize(options = {}) api_domain = options[:api_domain] || API_DOMAIN - @connection = Faraday.new(url: "https://#{api_domain}") + @connection = Faraday.new(url: "https://#{api_domain}", request: { params_encoder: Faraday::FlatParamsEncoder }) end include MobilizeAmericaClient::Request + include MobilizeAmericaClient::Client::Enums include MobilizeAmericaClient::Client::Events include MobilizeAmericaClient::Client::Organizations end diff --git a/lib/mobilize_america_client/client/enums.rb b/lib/mobilize_america_client/client/enums.rb new file mode 100644 index 0000000..9c7195b --- /dev/null +++ b/lib/mobilize_america_client/client/enums.rb @@ -0,0 +1,9 @@ +module MobilizeAmericaClient + class Client + module Enums + def enums + get(path: '/enums') + end + end + end +end diff --git a/lib/mobilize_america_client/client/events.rb b/lib/mobilize_america_client/client/events.rb index 5f12ab6..93d6500 100644 --- a/lib/mobilize_america_client/client/events.rb +++ b/lib/mobilize_america_client/client/events.rb @@ -2,7 +2,8 @@ module MobilizeAmericaClient class Client module Events def organization_events(organization_id:, timeslot_start: nil, timeslot_end: nil, updated_since: nil, - max_distance_miles: nil, page: nil, per_page: nil, zipcode: nil) + max_distance_miles: nil, page: nil, per_page: nil, zipcode: nil, event_campaign_id: nil, + tag_ids: nil, event_types: nil, is_virtual: nil, exclude_full: nil) params = {} unless page.nil? @@ -33,6 +34,26 @@ def organization_events(organization_id:, timeslot_start: nil, timeslot_end: nil end end + unless event_campaign_id.nil? + params[:event_campaign_id] = event_campaign_id.to_i + end + + unless tag_ids.nil? || tag_ids.empty? + params[:tag_id] = tag_ids.join(',') + end + + unless event_types.nil? || event_types.empty? + params[:event_types] = event_types.join(',') + end + + unless is_virtual.nil? + params[:is_virtual] = is_virtual ? 'true' : 'false' + end + + unless exclude_full.nil? + params[:exclude_full] = exclude_full ? 'true' : 'false' + end + get(path: "/organizations/#{esc(organization_id)}/events", params: params) end end @@ -40,5 +61,13 @@ def organization_events(organization_id:, timeslot_start: nil, timeslot_end: nil def organization_event(organization_id:, event_id:) get(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}") end + + def organization_event_attendances(organization_id:, event_id:) + get(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}/attendances") + end + + def create_organization_event_attendance(organization_id:, event_id:, attendance_data:) + post(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}/attendances", body: attendance_data) + end end end diff --git a/lib/mobilize_america_client/request.rb b/lib/mobilize_america_client/request.rb index e053f64..08cd6a6 100644 --- a/lib/mobilize_america_client/request.rb +++ b/lib/mobilize_america_client/request.rb @@ -6,7 +6,11 @@ module Request API_BASE_PATH = '/v1'.freeze def get(path:, params: {}) - request(method: :get, path: path, params: params) + request(method: :get, path:, params:) + end + + def post(path:, body:) + request(method: :post, path:, body:) end private diff --git a/spec/client/enums_spec.rb b/spec/client/enums_spec.rb new file mode 100644 index 0000000..56df1e5 --- /dev/null +++ b/spec/client/enums_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +RSpec.describe MobilizeAmericaClient::Client::Enums do + let(:standard_headers) { {'Content-Type' => 'application/json'} } + + subject { MobilizeAmericaClient::Client.new } + + let(:base_url) { "https://#{MobilizeAmericaClient::Client::API_DOMAIN}#{MobilizeAmericaClient::Client::API_BASE_PATH}" } + + describe '#enums' do + let(:enums_url) { "#{base_url}/enums" } + let(:response) { {'hello' => 'world'} } + + it 'should call the endpoint and return JSON' do + stub_request(:get, enums_url).with(headers: standard_headers).to_return(body: response.to_json) + expect(subject.enums).to eq response + end + end +end diff --git a/spec/client/events_spec.rb b/spec/client/events_spec.rb index 3609ce3..9cbe544 100644 --- a/spec/client/events_spec.rb +++ b/spec/client/events_spec.rb @@ -75,6 +75,41 @@ .to_return(body: response.to_json) expect(subject.organization_events(organization_id: org_id, page: 2, per_page: 100)).to eq(response) end + + it 'should support an event campaign id parameter' do + stub_request(:get, events_url) + .with(headers: standard_headers, query: {event_campaign_id: 1}) + .to_return(body: response.to_json) + expect(subject.organization_events(organization_id: org_id, event_campaign_id: 1)).to eq(response) + end + + it 'should support a tag ids parameter' do + stub_request(:get, events_url) + .with(headers: standard_headers, query: {tag_id: 'foo,bar'}) + .to_return(body: response.to_json) + expect(subject.organization_events(organization_id: org_id, tag_ids: ['foo', 'bar'])).to eq(response) + end + + it 'should support an event types parameter' do + stub_request(:get, events_url) + .with(headers: standard_headers, query: {event_types: 'foo,bar'}) + .to_return(body: response.to_json) + expect(subject.organization_events(organization_id: org_id, event_types: ['foo', 'bar'])).to eq(response) + end + + it 'should support a virtual parameter' do + stub_request(:get, events_url) + .with(headers: standard_headers, query: {is_virtual: true}) + .to_return(body: response.to_json) + expect(subject.organization_events(organization_id: org_id, is_virtual: true)).to eq(response) + end + + it 'should support an exclude full parameter' do + stub_request(:get, events_url) + .with(headers: standard_headers, query: {exclude_full: true}) + .to_return(body: response.to_json) + expect(subject.organization_events(organization_id: org_id, exclude_full: true)).to eq(response) + end end describe '#organization_event' do