Skip to content

Commit

Permalink
Merge pull request #8 from daisychainapp/main
Browse files Browse the repository at this point in the history
Add some more endpoints to gem
  • Loading branch information
anero authored Feb 20, 2023
2 parents c37db4d + b885fc2 commit a064531
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.2.0
4 changes: 3 additions & 1 deletion lib/mobilize_america_client/client.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/mobilize_america_client/client/enums.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module MobilizeAmericaClient
class Client
module Enums
def enums
get(path: '/enums')
end
end
end
end
31 changes: 30 additions & 1 deletion lib/mobilize_america_client/client/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -33,12 +34,40 @@ 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

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
6 changes: 5 additions & 1 deletion lib/mobilize_america_client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/client/enums_spec.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions spec/client/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a064531

Please sign in to comment.