Skip to content

Instantly share code, notes, and snippets.

@camdez
Last active December 16, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camdez/5436237 to your computer and use it in GitHub Desktop.
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…
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