Created
April 27, 2017 02:51
-
-
Save patcable/732ce3f133529a6c9064886fff6d29de to your computer and use it in GitHub Desktop.
Submittable API Demo
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
#!/usr/bin/env ruby | |
require 'httparty' | |
apikey = ENV['SM_API_KEY'] | |
if apikey.nil? | |
puts "Need to set $SM_API_KEY - see https://<your_submission_site>.submittable.com/settings/api" | |
exit 1 | |
end | |
### API SETTINGS | |
per_api_call = 200 | |
category = 123445 # will need to do a initial API call on a test to figure this out | |
length_form_field = 544321 # same for this - in this case, this is what this script does. | |
sub30min = 0 | |
sub45min = 0 | |
items = Array.new | |
# Initial call | |
url = "https://#{apikey}:@api.submittable.com/v1/submissions?count=#{per_api_call}&category_id=#{category}" | |
response = HTTParty.get(url) | |
req = response.parsed_response | |
items[0] = req['items'] | |
# Do we need more pages? If so, loop through the rest and add them to the array | |
if req['current_page'] < req['total_pages'] | |
current = req['current_page'] | |
total = req['total_pages'] | |
while current < total | |
current += 1 | |
url = "https://#{apikey}:@api.submittable.com/v1/submissions?count=#{per_api_call}&page=#{current}&category_id=#{category}" | |
response = HTTParty.get(url) | |
req = response.parsed_response | |
items[current-1] = req['items'] | |
end | |
end | |
# Get value and count number of submissions that are submitted for certain times. | |
# You'd customize this part for what you want to do with the submissions. | |
items.flatten.each do |s| | |
s['form']['items'].each do |i| | |
next unless i['form_field_id'] == length_form_field | |
case i['data'] | |
when '45 Minutes (Incl. Q&A)' | |
sub45min += 1 | |
when '30 Minutes (Incl. Q&A)' | |
sub30min += 1 | |
end | |
end | |
end | |
puts 'Talk Submission Length' | |
puts '======================' | |
puts "30m: #{sub30min}, 45m: #{sub45min}, total returned: #{sub30min+sub45min}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment