RSS

Forums / Tips & Tricks / Consuming Zendesk data us...

Consuming Zendesk data using Rails ActiveResource

Submitted Jun 12 by Morten Primdahl

Want to extract Zendesk data from your Rails application? Here's how to get started.

DOMAIN   = 'your account subdomain'
LOGIN    = 'email address of the user logging in'
PASSWORD = 'and his password'
class ZendeskResource < ActiveResource::Base
  self.site = "http://#{DOMAIN}.zendesk.com"
  def (self.site).user
    LOGIN
  end
  
  def (self.site).password
    PASSWORD
  end    
end

class User < ZendeskResource
end

class Organization < ZendeskResource
end

def users_by_organization
  returning result = {} do
    orgs = Organization.find(:all)
    User.find(:all).group_by(&:organization_id).each do |id, users|
      key = id.nil? ? 'No organization' : orgs.find {|o| o.id == id }.name
      result[key] = users.collect {|u| [u.name, u.email]}
    end
  end  
end

puts users_by_organization.inspect
 
or cancel