Class: PlanningcenterOrbit::Planningcenter
- Inherits:
-
Object
- Object
- PlanningcenterOrbit::Planningcenter
- Defined in:
- lib/planningcenter_orbit/planningcenter.rb
Instance Method Summary collapse
- #get_event_checkins(link:) ⇒ Object
- #get_events ⇒ Object
-
#initialize(params = {}) ⇒ Planningcenter
constructor
A new instance of Planningcenter.
- #process_checkins ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Planningcenter
Returns a new instance of Planningcenter.
7 8 9 10 11 12 13 |
# File 'lib/planningcenter_orbit/planningcenter.rb', line 7 def initialize(params = {}) @pc_app_id = params.fetch(:pc_app_id) @pc_api_secret = params.fetch(:pc_api_secret) @orbit_api_key = params.fetch(:orbit_api_key) @orbit_workspace = params.fetch(:orbit_workspace) @historical_import = params.fetch(:historical_import, false) end |
Instance Method Details
#get_event_checkins(link:) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/planningcenter_orbit/planningcenter.rb', line 76 def get_event_checkins(link:) url = URI(link) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Accept"] = "application/json" request["Content-Type"] = "application/json" request.basic_auth @pc_app_id, @pc_api_secret response = https.request(request) response = JSON.parse(response.body) response["data"] end |
#get_events ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/planningcenter_orbit/planningcenter.rb', line 52 def get_events url = URI("https://api.planningcenteronline.com/check-ins/v2/events") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Accept"] = "application/json" request["Content-Type"] = "application/json" request.basic_auth @pc_app_id, @pc_api_secret response = https.request(request) response = JSON.parse(response.body) if response["data"].nil? || response["data"].empty? return " No new events from your Planning Center organization.\n If you suspect this is incorrect, verify your Planning Center credentials are correct.\n HEREDOC\n end\n\n response\nend\n" |
#process_checkins ⇒ Object
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 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/planningcenter_orbit/planningcenter.rb', line 15 def process_checkins events = get_events return "Something went wrong with the Planning Center API" unless events["data"].is_a?(Array) events["data"].each do |event| checkins = get_event_checkins(link: "#{event["links"]["self"]}/check_ins") next if checkins.nil? || checkins.empty? times = 0 checkins.each do |checkin| unless @historical_import && next if checkin["attributes"]["created_at"] < end unless .nil? || .empty? next if checkin["attributes"]["created_at"] < end times += 1 PlanningcenterOrbit::Orbit.call( type: "checkin", data: { checkin: checkin, title: event["attributes"]["name"], url: "https://check-ins.planningcenteronline.com/events/#{event["id"]}" }, workspace_id: @orbit_workspace, api_key: @orbit_api_key ) end return "Sent #{times} checkins to your Orbit workspace" end end |