Skip to content

Instantly share code, notes, and snippets.

@luke-barnett
Created March 21, 2015 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luke-barnett/fff62c8cfc3dbd30e020 to your computer and use it in GitHub Desktop.
Save luke-barnett/fff62c8cfc3dbd30e020 to your computer and use it in GitHub Desktop.
#https://services.planningcenteronline.com/oauth/authorize?oauth_token=g4FtOqgGZfpr6NRl3Y1D
client = PlanningCenter::Client.new do |c|
c.consumer_key = 'y4sgTnxkbuZb53ITfuuE'
c.consumer_secret = ENV["planningCenterTrelloSyncConsumerSecret"]
c.access_token = ENV["planningCenterTrelloSyncAccessToken"]
c.access_token_secret = ENV["planningCenterTrelloSyncAccessTokenSecret"]
end
puts "Getting custom fields"
customFields = client.get("/songs/custom_fields.json")
songListStatusField = customFields.select { |field| field["name"] == "Song list status" }.first
statusOptions = songListStatusField["properties"]
consumer = OAuth::Consumer.new(
'y4sgTnxkbuZb53ITfuuE',
ENV["planningCenterTrelloSyncConsumerSecret"],
site: 'https://services.planningcenteronline.com'
)
oauth = OAuth::AccessToken.new(
consumer,
ENV["planningCenterTrelloSyncAccessToken"],
ENV["planningCenterTrelloSyncAccessTokenSecret"]
)
songs.each do |song|
if song.list == "Song List"
status = "Approved"
elsif song.list == "On Hold"
status = "On-hold"
elsif song.list == "No"
status = "No"
else
status = "Pending"
end
statusOption = statusOptions.select { |option| option["name"] == status }.first
planningCenterSong = client.get("/songs/#{song.planningCenterId}.json")
songStatus = planningCenterSong["properties"].select { |field| field["field_id"] == statusOption["custom_field_id"]}.first
if songStatus["option_id"] != statusOption["id"]
puts "#{planningCenterSong["title"]} [#{songStatus["option"]}] -> [#{statusOption["name"]}]"
songStatus["option"] = statusOption["name"]
songStatus["option_id"] = statusOption["id"]
json = {
"song" =>
{
"id" => planningCenterSong["id"],
"properties" => planningCenterSong["properties"]
}
}.to_json
response = oauth.put(
"/songs/#{song.planningCenterId}.json",
json
)
p response
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment