Last active
December 16, 2015 12:39
-
-
Save camdez/5436237 to your computer and use it in GitHub Desktop.
A simple Ruby application demonstrating how to use the OrgSync API. Lists all organizations with more than 20 members (using this API call: https://api.orgsync.com/api/docs/v2/orgs/index). Please note that this simple script disables SSL certificate verification for convenience of example, but SSL verification should be used in a production sett…
This file contains hidden or 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
require 'faraday' | |
require 'json' | |
API_KEY = "dd6b9d2beb614611c5eb9f56c34b743d1d86f385" | |
API_BASE_URL = "https://api.orgsync.com" | |
# Set up the HTTP client | |
conn = Faraday.new(:url => API_BASE_URL, | |
:ssl => {:verify => false}) do |faraday| | |
faraday.adapter Faraday.default_adapter | |
end | |
# Fetch the data | |
ORGS_URL = "/api/v2/orgs" | |
response = conn.get ORGS_URL, :key => API_KEY | |
# Check for success | |
unless response.status == 200 | |
STDOUT.puts "Something went wrong:\nHTTP #{response.status}\n#{response.body}" | |
exit 1 | |
end | |
# Parse the JSON | |
orgs = JSON.parse(response.body) | |
# Process the data | |
large_orgs = orgs.select { |org| org['member_count'] > 20 } | |
large_orgs.sort_by! { |org| org['member_count'] }.reverse! | |
# Output | |
large_orgs.each { |org| puts "#{org['long_name']} - #{org['member_count']}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment