Created
September 26, 2022 20:11
-
-
Save seven1m/fa488a50ebcf7054e4b12382ad1f2c6d to your computer and use it in GitHub Desktop.
Get / Change `remote_id` in Planning Center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: ruby remote_id.rb pco_id [remote_id] | |
# | |
# pco_id Planning Center profile ID | |
# remote_id Specify new remote ID | |
# | |
# get remote id: | |
# ruby remote_id.rb 1234 | |
# | |
# set remote id: | |
# ruby remote_id.rb 1234 5678 | |
require 'net/http' | |
require 'json' | |
APP_ID = 'put your personal access token id here' | |
SECRET = 'put your personal access token secret here' | |
def get(uri, headers: {}) | |
uri = URI(uri) | |
ssl = uri.scheme.downcase == 'https' | |
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http| | |
request = Net::HTTP::Get.new(uri, headers) | |
request.basic_auth(APP_ID, SECRET) | |
response = http.request(request) | |
unless response.code == '200' | |
raise response.body | |
end | |
JSON.parse(response.body) | |
end | |
end | |
def post(uri, body:, headers: {}) | |
uri = URI(uri) | |
ssl = uri.scheme.downcase == 'https' | |
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http| | |
request = Net::HTTP::Post.new(uri, headers) | |
request.basic_auth(APP_ID, SECRET) | |
request.body = body.to_json | |
response = http.request(request) | |
unless response.code =~ /^2../ | |
raise response.body | |
end | |
JSON.parse(response.body) | |
end | |
end | |
def patch(uri, body:, headers: {}) | |
uri = URI(uri) | |
ssl = uri.scheme.downcase == 'https' | |
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http| | |
request = Net::HTTP::Patch.new(uri, headers) | |
request.basic_auth(APP_ID, SECRET) | |
request.body = body.to_json | |
response = http.request(request) | |
unless response.code =~ /^2../ | |
raise response.body | |
end | |
JSON.parse(response.body) | |
end | |
end | |
pco_id, remote_id = ARGV | |
unless (1..2).include?(ARGV.size) | |
puts 'usage: ruby remote_id.rb pco_id [remote_id]' | |
puts | |
puts ' pco_id Planning Center profile ID' | |
puts ' remote_id Specify new remote ID' | |
puts | |
puts 'get remote id:' | |
puts 'ruby remote_id.rb 1234' | |
puts | |
puts 'set remote id:' | |
puts 'ruby remote_id.rb 1234 5678' | |
exit | |
end | |
if remote_id | |
patch("https://api.planningcenteronline.com/people/v2/people/#{pco_id}", body: { | |
data: { | |
attributes: { | |
remote_id: remote_id | |
} | |
} | |
}) | |
end | |
p get("https://api.planningcenteronline.com/people/v2/people/#{pco_id}").dig('data', 'attributes', 'remote_id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment