Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
basis api with tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
marbball committed Aug 8, 2014
1 parent a8f2634 commit eb2f9e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ gem 'devise-i18n'

# non-digested assets for brimir-plugin js/css
gem 'non-stupid-digest-assets'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ GEM
hike (1.2.3)
http_accept_language (2.0.1)
i18n (0.6.11)
jbuilder (1.5.3)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-rails (3.1.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -213,6 +216,7 @@ DEPENDENCIES
foundation-rails (~> 5.2.2)
foundation_rails_helper
http_accept_language
jbuilder (~> 1.2)
jquery-rails
mysql2
non-stupid-digest-assets
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/api/v1/tickets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Brimir is a helpdesk system to handle email support requests.
# Brimir is a helpdesk system to handle email support requests.
# Copyright (C) 2012-2014 Ivaldi http://ivaldi.nl
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -14,8 +14,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class Api::V1::TicketsController < Api::V1::ApplicationController
before_filter :authenticate_user!

load_and_authorize_resource :ticket

def index
@tickets = Tickets.by_states(:open).viewable_by(current_user)
@tickets = Ticket.by_status(:open).viewable_by(current_user)
end

def show
@ticket = Ticket.find(params[:id])
end
end
3 changes: 2 additions & 1 deletion app/views/api/v1/tickets/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
json.array! @tickets do |ticket|
json.subject ticket.subject
json.id ticket.id
json.subject ticket.subject
end
3 changes: 3 additions & 0 deletions app/views/api/v1/tickets/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
json.id @ticket.id
json.subject @ticket.subject

6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@

root :to => 'tickets#index'

namespace :api do
namespace :v1 do
resources :tickets, only: [ :index, :show ]
end
end

end

0 comments on commit eb2f9e2

Please sign in to comment.