#!/usr/bin/env ruby require 'oauth' # All of the following configuration variables must be filled out! configuration = { # Desk.com API Credentials. api_consumer_key: '', api_consumer_secret: '', access_token: '', access_token_secret: '', # General config. site_uri: '', search_params: 'status=new,open&assigned_user=none' } # Authorize to the Desk.com API. consumer = OAuth::Consumer.new( configuration[:api_consumer_key], configuration[:api_consumer_secret], site: configuration[:site_uri], scheme: :header ) access_token = OAuth::AccessToken.from_hash( consumer, :oauth_token => configuration[:access_token], :oauth_token_secret => configuration[:access_token_secret] ) SCHEDULER.every '5m', first_in: 0 do |job| # Construct the full API URI. uri = configuration[:site_uri] + '/api/v2/cases/search?page=1&per_page=1&' + configuration[:search_params] # Connect to the API and get me some cases! response = access_token.get(uri) # Parse the JSON response. json = JSON.parse(response.body) # Send the total number of cases to the dashboard. send_event(:desk_cases, count: json['total_entries']) end