Module: TheCity
- Defined in:
- lib/the_city_admin.rb,
lib/common.rb,
lib/api/tag.rb,
lib/api/fund.rb,
lib/api/role.rb,
lib/api/user.rb,
lib/api/group.rb,
lib/api/skill.rb,
lib/auto_load.rb,
lib/api/campus.rb,
lib/api/church.rb,
lib/api/family.rb,
lib/api/metric.rb,
lib/api/pledge.rb,
lib/api/address.rb,
lib/api/barcode.rb,
lib/api/checkin.rb,
lib/api/api_list.rb,
lib/api/donation.rb,
lib/api/tag_list.rb,
lib/api/web_hook.rb,
lib/api/fund_list.rb,
lib/api/group_tag.rb,
lib/api/role_list.rb,
lib/api/user_list.rb,
lib/api/user_note.rb,
lib/api/user_role.rb,
lib/api/api_object.rb,
lib/api/group_list.rb,
lib/api/group_role.rb,
lib/api/invitation.rb,
lib/api/skill_list.rb,
lib/api/user_count.rb,
lib/api/user_skill.rb,
lib/api/campus_list.rb,
lib/api/metric_list.rb,
lib/api/pledge_list.rb,
lib/api/terminology.rb,
lib/api/address_list.rb,
lib/api/checkin_list.rb,
lib/api/group_export.rb,
lib/api/user_address.rb,
lib/api/user_barcode.rb,
lib/api/user_process.rb,
lib/api/donation_list.rb,
lib/api/family_member.rb,
lib/api/group_address.rb,
lib/api/group_checkin.rb,
lib/api/web_hook_list.rb,
lib/api/group_tag_list.rb,
lib/api/tag_group_list.rb,
lib/api/user_note_list.rb,
lib/api/user_role_list.rb,
lib/readers/api_reader.rb,
lib/readers/tag_reader.rb,
lib/writers/api_writer.rb,
lib/writers/tag_writer.rb,
lib/api/donation_export.rb,
lib/api/group_role_list.rb,
lib/api/invitation_list.rb,
lib/api/user_invitation.rb,
lib/api/user_skill_list.rb,
lib/readers/fund_reader.rb,
lib/readers/user_reader.rb,
lib/writers/fund_writer.rb,
lib/writers/user_writer.rb,
lib/api/group_invitation.rb,
lib/api/terminology_list.rb,
lib/api/user_family_list.rb,
lib/readers/group_reader.rb,
lib/readers/skill_reader.rb,
lib/writers/group_writer.rb,
lib/writers/skill_writer.rb,
lib/api/group_export_list.rb,
lib/api/skilled_user_list.rb,
lib/api/user_address_list.rb,
lib/api/user_process_list.rb,
lib/cachers/cache_adapter.rb,
lib/readers/church_reader.rb,
lib/readers/family_reader.rb,
lib/readers/metric_reader.rb,
lib/readers/pledge_reader.rb,
lib/writers/family_writer.rb,
lib/writers/metric_writer.rb,
lib/api/group_address_list.rb,
lib/api/group_checkin_list.rb,
lib/api/metric_measurement.rb,
lib/api/user_family_member.rb,
lib/readers/address_reader.rb,
lib/readers/checkin_reader.rb,
lib/api/group_checkin_event.rb,
lib/api/user_process_answer.rb,
lib/cachers/file/json_cache.rb,
lib/readers/donation_reader.rb,
lib/readers/tag_list_reader.rb,
lib/writers/web_hook_writer.rb,
lib/api/donation_export_list.rb,
lib/api/skilled_user_id_list.rb,
lib/api/user_admin_privilege.rb,
lib/api/user_invitation_list.rb,
lib/readers/fund_list_reader.rb,
lib/readers/role_list_reader.rb,
lib/readers/user_list_reader.rb,
lib/writers/user_note_writer.rb,
lib/writers/user_role_writer.rb,
lib/api/group_invitation_list.rb,
lib/readers/group_list_reader.rb,
lib/readers/skill_list_reader.rb,
lib/readers/user_count_reader.rb,
lib/writers/user_skill_writer.rb,
lib/api/group_event_attendance.rb,
lib/readers/campus_list_reader.rb,
lib/readers/metric_list_reader.rb,
lib/readers/pledge_list_reader.rb,
lib/readers/terminology_reader.rb,
lib/writers/terminology_writer.rb,
lib/api/metric_measurement_list.rb,
lib/readers/address_list_reader.rb,
lib/readers/checkin_list_reader.rb,
lib/readers/group_export_reader.rb,
lib/writers/group_export_writer.rb,
lib/writers/user_address_writer.rb,
lib/api/user_process_answer_list.rb,
lib/readers/donation_list_reader.rb,
lib/readers/group_checkin_reader.rb,
lib/readers/web_hook_list_reader.rb,
lib/writers/group_address_writer.rb,
lib/api/group_checkin_events_list.rb,
lib/api/metric_measurement_values.rb,
lib/api/user_admin_privilege_list.rb,
lib/readers/group_tag_list_reader.rb,
lib/readers/tag_group_list_reader.rb,
lib/readers/user_note_list_reader.rb,
lib/readers/user_role_list_reader.rb,
lib/readers/donation_export_reader.rb,
lib/readers/group_role_list_reader.rb,
lib/readers/invitation_list_reader.rb,
lib/readers/user_skill_list_reader.rb,
lib/writers/donation_export_writer.rb,
lib/writers/user_invitation_writer.rb,
lib/api/group_event_attendance_list.rb,
lib/readers/terminology_list_reader.rb,
lib/readers/user_family_list_reader.rb,
lib/api/checkin_list_by_pager_number.rb,
lib/readers/group_export_list_reader.rb,
lib/readers/skilled_user_list_reader.rb,
lib/readers/user_address_list_reader.rb,
lib/readers/user_process_list_reader.rb,
lib/readers/group_address_list_reader.rb,
lib/readers/group_checkin_list_reader.rb,
lib/readers/metric_measurement_reader.rb,
lib/writers/metric_measurement_writer.rb,
lib/readers/donation_export_list_reader.rb,
lib/readers/skilled_user_id_list_reader.rb,
lib/readers/user_invitation_list_reader.rb,
lib/writers/user_admin_privilege_writer.rb,
lib/api/checkin_list_by_callboard_number.rb,
lib/readers/group_invitation_list_reader.rb,
lib/readers/metric_measurement_list_reader.rb,
lib/readers/user_process_answer_list_reader.rb,
lib/readers/group_checkin_events_list_reader.rb,
lib/readers/metric_measurement_values_reader.rb,
lib/readers/user_admin_privilege_list_reader.rb,
lib/readers/group_event_attendance_list_reader.rb,
lib/readers/checkin_list_by_pager_number_reader.rb,
lib/readers/checkin_list_by_callboard_number_reader.rb
Overview
This class is meant to be a wrapper TheCity Admin API (OnTheCity.org).
Defined Under Namespace
Classes: Address, AddressList, AddressListReader, AddressReader, AdminApi, ApiList, ApiObject, ApiReader, ApiWriter, Barcode, CacheAdapter, Campus, CampusList, CampusListReader, Checkin, CheckinList, CheckinListByCallboardNumber, CheckinListByCallboardNumberReader, CheckinListByPagerNumber, CheckinListByPagerNumberReader, CheckinListReader, CheckinReader, Church, ChurchReader, Donation, DonationExport, DonationExportList, DonationExportListReader, DonationExportReader, DonationExportWriter, DonationList, DonationListReader, DonationReader, Family, FamilyMember, FamilyReader, FamilyWriter, Fund, FundList, FundListReader, FundReader, FundWriter, Group, GroupAddress, GroupAddressList, GroupAddressListReader, GroupAddressWriter, GroupCheckin, GroupCheckinEvent, GroupCheckinEventsList, GroupCheckinEventsListReader, GroupCheckinList, GroupCheckinListReader, GroupCheckinReader, GroupEventAttendance, GroupEventAttendanceList, GroupEventAttendanceListReader, GroupExport, GroupExportList, GroupExportListReader, GroupExportReader, GroupExportWriter, GroupInvitation, GroupInvitationList, GroupInvitationListReader, GroupList, GroupListReader, GroupReader, GroupRole, GroupRoleList, GroupRoleListReader, GroupTag, GroupTagList, GroupTagListReader, GroupWriter, Invitation, InvitationList, InvitationListReader, JsonCache, Metric, MetricList, MetricListReader, MetricMeasurement, MetricMeasurementList, MetricMeasurementListReader, MetricMeasurementReader, MetricMeasurementValues, MetricMeasurementValuesReader, MetricMeasurementWriter, MetricReader, MetricWriter, Pledge, PledgeList, PledgeListReader, PledgeReader, Role, RoleList, RoleListReader, Skill, SkillList, SkillListReader, SkillReader, SkillWriter, SkilledUserIdList, SkilledUserIdListReader, SkilledUserList, SkilledUserListReader, Tag, TagGroupList, TagGroupListReader, TagList, TagListReader, TagReader, TagWriter, Terminology, TerminologyList, TerminologyListReader, TerminologyReader, TerminologyWriter, User, UserAddress, UserAddressList, UserAddressListReader, UserAddressWriter, UserAdminPrivilege, UserAdminPrivilegeList, UserAdminPrivilegeListReader, UserAdminPrivilegeWriter, UserBarcode, UserCount, UserCountReader, UserFamilyList, UserFamilyListReader, UserFamilyMember, UserInvitation, UserInvitationList, UserInvitationListReader, UserInvitationWriter, UserList, UserListReader, UserNote, UserNoteList, UserNoteListReader, UserNoteWriter, UserProcess, UserProcessAnswer, UserProcessAnswerList, UserProcessAnswerListReader, UserProcessList, UserProcessListReader, UserReader, UserRole, UserRoleList, UserRoleListReader, UserRoleWriter, UserSkill, UserSkillList, UserSkillListReader, UserSkillWriter, UserWriter, WebHook, WebHookList, WebHookListReader, WebHookWriter
Class Method Summary collapse
- ._build_admin_headers(method, path, params, body) ⇒ Object
- .admin_request(method, path, params = {}, body = '') ⇒ Object
Class Method Details
._build_admin_headers(method, path, params, body) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/common.rb', line 42 def self._build_admin_headers(method, path, params, body) get_vars = method == :post ? '' : '?' if params get_vars += params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1].to_s}" }.join('&') end get_vars = '' if get_vars == '?' method_request = method.to_s.upcase url = THE_CITY_ADMIN_PATH + path + get_vars + body current_time = Time.now.to_i.to_s string_to_sign = current_time.to_s + method_request + url unencoded_hmac = OpenSSL::HMAC.digest('sha256', TheCity::AdminApi.api_key, string_to_sign) unescaped_hmac = Base64.encode64(unencoded_hmac).chomp hmac_signature = CGI.escape(unescaped_hmac) {'X-City-Sig' => hmac_signature, 'X-City-User-Token' => TheCity::AdminApi.api_token, 'X-City-Time' => current_time, 'Accept' => 'application/vnd.thecity.admin.v1+json', 'Content-Type' => 'application/json', 'Content-Length' => body.length} end |
.admin_request(method, path, params = {}, body = '') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/common.rb', line 6 def self.admin_request(method, path, params = {}, body = '') headers = self._build_admin_headers(method, path, params, body) url = THE_CITY_ADMIN_PATH+path response = case method when :post Typhoeus::Request.post(url, {:headers => headers, :body => body}) when :get Typhoeus::Request.get(url, {:headers => headers, :params => params}) when :put Typhoeus::Request.put(url, {:headers => headers, :body => body}) when :delete Typhoeus::Request.delete(url, {:headers => headers, :params => params}) end unless response.success? if response.code > 0 raise TheCityExceptions::UnableToConnectToTheCity.new(response.body) else begin = JSON.parse(response.body)['error_message'] rescue response_code_desc = response.headers.partition("\r\n")[0].sub(/^\S+/, '') rescue nil raise TheCityExceptions::UnknownErrorConnectingToTheCity.new("Unknown error when connecting to The City.#{response_code_desc}") else raise TheCityExceptions::TheCityResponseError.new() end end end response end |