Skip to content

Instantly share code, notes, and snippets.

@ewlarson
Last active January 4, 2023 21:47
Show Gist options
  • Save ewlarson/5b99e0a5f2a17346bec749c160531186 to your computer and use it in GitHub Desktop.
Save ewlarson/5b99e0a5f2a17346bec749c160531186 to your computer and use it in GitHub Desktop.
Gimlet - API - All Questions call with start_date and end_date
require 'date'
require 'faraday' # Faraday v2
require 'json'
#
# List all Questions from an account via start_date and end_date params as JSON
#
# Required API Variables
DOMAIN = 'foo' # Without .gimlet.us
EMAIL = '[email protected]'
API_KEY = 'your api key here'
# Report Dates
today = '2023-01-04' # Or something dyanmic like: Date.today
days_ago = '2019-09-25' # Or something dynamic like: today - 1200
# URL and Path
url = "https://#{DOMAIN}.gimlet.us"
path = "/api/v1/questions.json?start_date=#{days_ago.to_s}&end_date=#{today.to_s}"
# New connection with base URL
Faraday.new(url: url) do |conn|
conn.request :authorization, :basic, EMAIL, API_KEY # Set the authentication header
response = conn.get(path) # GET API request
# Print the results
results = JSON.parse(response.body)
puts "RESULTS: #{results.inspect}"
puts "RESULT COUNT: #{results["questions"].size}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment