Skip to content

Instantly share code, notes, and snippets.

@radar
Created June 15, 2018 05:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save radar/f19375fcd0a642cf4eae65be418e3e24 to your computer and use it in GitHub Desktop.
Problematic code
<table>
<tr>
<th>Subject</th>
<th>Created At</th>
<th>Status</th>
</tr>
<% @tickets.each do |ticket| %>
<tr>
<td><a href="/ticket/<%= ticket.id %>"><%= ticket.subject %></a></td>
<td><%= parse_time(ticket.created_at) %></td>
<td><%= ticket.status %></td>
</tr>
<% end %>
</table>
require 'zendesk_api'
require 'json'
class Ticket
attr_accessor :id,
:subject,
:description,
:requester_id,
:assignee_id,
:created_at,
:updated_at,
:status
PAGE_LIMIT = 25
ZENDESK_RESPONSE = 100
def initialize(id, subject, description, requester_id, assignee_id, created_at, updated_at, status)
@id = id
@subject = subject
@description = description
@requester_id = requester_id
@assignee_id = assignee_id
@created_at = created_at
@updated_at = updated_at
@status = status
end
def self.ticket_list
api = ZendeskApi.new
tickets = JSON.parse(api.get(ZendeskApi::BASE_URL + 'tickets.json?sort_by=id&sort_order=desc').body)
tickets['tickets'].each do |ticket|
[ticket['id'], ticket['subject'], ticket['description'], ticket['requester_id'],
ticket['assignee_id'], ticket['created_at'], ticket['updated_at'], ticket['status']]
end
tickets
end
def self.single_ticket(id)
api = ZendeskApi.new
ticket = JSON.parse(api.get(ZendeskApi::BASE_URL + "tickets/#{id}.json").body)
[ticket['id']]
end
end
require 'ticket'
class TicketsController < ApplicationController
rescue_from HTTParty::Error, with: :error
def index
@tickets = Ticket.ticket_list
end
def show
@ticket = Ticket.single_ticket(params[:id])
end
def error
render :error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment