JSON controller added. /json/package/:name implemented
This commit is contained in:
parent
0c439359b9
commit
b3d0b2dc06
4 changed files with 46 additions and 0 deletions
14
app/controllers/json_controller.rb
Normal file
14
app/controllers/json_controller.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class JsonController < ApplicationController
|
||||
def package
|
||||
@p = Package.find_by_name! params[:name]
|
||||
end
|
||||
|
||||
def packages
|
||||
end
|
||||
|
||||
def screenshots
|
||||
end
|
||||
|
||||
def packages_without_screenshots
|
||||
end
|
||||
end
|
||||
7
app/views/json/package.json.jbuilder
Normal file
7
app/views/json/package.json.jbuilder
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
json.package @p.name
|
||||
|
||||
json.screenshots @p.screenshots do |s|
|
||||
json.small_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:thumb, timestamp: false)}"
|
||||
json.large_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:large, timestamp: false)}"
|
||||
json.version s.version
|
||||
end
|
||||
|
|
@ -35,6 +35,7 @@ Debshots::Application.routes.draw do
|
|||
get 'with_screenshots', to: redirect('/packages?show=with')
|
||||
get 'without_screenshots', to: redirect('/packages?show=without')
|
||||
|
||||
get 'json/package/:name' => 'json#package', as: :json_package, defaults: { format: :json }
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
# See how all your routes lay out with "rake routes".
|
||||
|
||||
|
|
|
|||
24
test/controllers/json_controller_test.rb
Normal file
24
test/controllers/json_controller_test.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
require "test_helper"
|
||||
|
||||
class JsonControllerTest < ActionController::TestCase
|
||||
def test_package
|
||||
get :package
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_packages
|
||||
get :packages
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_screenshots
|
||||
get :screenshots
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_packages-without-screenshots
|
||||
get :packages-without-screenshots
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue