Skip to content

Commit

Permalink
Merge 1c89749 into 514633b
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmcfarl committed Sep 10, 2014
2 parents 514633b + 1c89749 commit 4550f50
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
19 changes: 19 additions & 0 deletions app/controllers/api/v1/api_controller.rb
@@ -0,0 +1,19 @@
class API::V1::ApiController < ApplicationController
respond_to :json, :xml

# The stats API only requires an api_key for the given app.
skip_before_filter :authenticate_user!
before_filter :require_api_key_or_authenticate_user!

protected

def require_api_key_or_authenticate_user!
if params[:api_key].present?
if @app = App.where(:api_key => params[:api_key]).first
return true
end
end

authenticate_user!
end
end
9 changes: 9 additions & 0 deletions app/controllers/api/v1/apps_controller.rb
@@ -0,0 +1,9 @@
class API::V1::AppsController < API::V1::ApiController
def index
@apps = App.all
end

def show
@app = App.find(params[:id])
end
end
22 changes: 1 addition & 21 deletions app/controllers/api/v1/stats_controller.rb
@@ -1,10 +1,4 @@
class Api::V1::StatsController < ApplicationController
respond_to :json, :xml

# The stats API only requires an api_key for the given app.
skip_before_filter :authenticate_user!
before_filter :require_api_key_or_authenticate_user!

class API::V1::StatsController < API::V1::ApiController
def app
if problem = @app.problems.order_by(:last_notice_at.desc).first
@last_error_time = problem.last_notice_at
Expand All @@ -22,18 +16,4 @@ def app
format.xml { render :xml => stats }
end
end


protected

def require_api_key_or_authenticate_user!
if params[:api_key].present?
if @app = App.where(:api_key => params[:api_key]).first
return true
end
end

authenticate_user!
end

end
1 change: 1 addition & 0 deletions app/views/api/v1/apps/index.json.jbuilder
@@ -0,0 +1 @@
json.apps @apps, :id, :name, :github_repo
4 changes: 4 additions & 0 deletions app/views/api/v1/apps/show.json.jbuilder
@@ -0,0 +1,4 @@
json.(@app, :id, :name)
json.errors @app.problems do |json, problem|
json.(problem, :message, :last_noticed_at, :notices_count)
end
13 changes: 3 additions & 10 deletions config/initializers/inflections.rb
@@ -1,11 +1,4 @@
# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym 'API'
end

1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -52,6 +52,7 @@
namespace :v1 do
resources :problems, :only => [:index, :show], :defaults => { :format => 'json' }
resources :notices, :only => [:index], :defaults => { :format => 'json' }
resources :apps, :only => [:index, :show], :defaults => { :format => 'json' }
resources :stats, :only => [], :defaults => { :format => 'json' } do
collection do
get :app
Expand Down

0 comments on commit 4550f50

Please sign in to comment.