Browse Source

Support JSON rendering for API

master
Aeris 3 years ago
parent
commit
51f478125a
1 changed files with 19 additions and 2 deletions
  1. 19
    2
      app/controllers/check_controller.rb

+ 19
- 2
app/controllers/check_controller.rb View File

@@ -5,8 +5,19 @@ class CheckController < ApplicationController
5 5
 	def show
6 6
 		enqueue_host unless @result
7 7
 		@host = SimpleIDN.to_unicode @host
8
-		return render :processing if @result.pending
9
-		return render :no_tls if @result.no_tls
8
+		respond_to do |format|
9
+			format.html do
10
+				return render :processing if @result.pending
11
+				return render :no_tls if @result.no_tls
12
+			end
13
+			format.json do
14
+				render json: case
15
+					when @result.pending then :pending
16
+					when @result.no_tls then :no_tls
17
+					else @result
18
+				end
19
+			end
20
+		end
10 21
 	end
11 22
 
12 23
 	def refresh
@@ -30,6 +41,12 @@ class CheckController < ApplicationController
30 41
 
31 42
 	def check_host
32 43
 		@id = params[:id]
44
+
45
+		if @id.end_with? '.json'
46
+			@id = @id.sub /\.json$/, ''
47
+			request.format = :json
48
+		end
49
+
33 50
 		@host, @port = @id.split ':'
34 51
 		@host = SimpleIDN.to_ascii @host.downcase
35 52
 		if /[^a-zA-Z0-9.-]/.match @host

Loading…
Cancel
Save