lib/ass.rb in ass-0.0.19 vs lib/ass.rb in ass-0.0.20
- old
+ new
@@ -7,10 +7,11 @@
require 'openssl'
require 'cgi'
require 'rufus/scheduler'
require 'eventmachine'
require 'sinatra/base'
+require 'rack/mobile-detect'
require 'yaml'
require 'uri-handler'
require 'net/http'
require 'active_support'
require 'json'
@@ -166,28 +167,42 @@
############################################################
## Apple Service Server based on Sinatra
############################################################
class App < Sinatra::Base
+ use Rack::MobileDetect
set :root, File.expand_path('../../', __FILE__)
set :port, "#{$port}".to_i
set :public_folder, File.dirname(__FILE__) + '/../public'
set :views, File.dirname(__FILE__) + '/../views'
- def authorized?
- @auth ||= Rack::Auth::Basic::Request.new(request.env)
- @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ["#{$user}", "#{$pass}"]
- end
+ helpers do
+
+ def iOS?
+ ret = case request.env['X_MOBILE_DEVICE']
+ when /iPhone|iPod|iPad/ then
+ true
+ else false
+ end
+ return ret
+ end
- def protected!
- unless authorized?
- response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
- throw(:halt, [401, "Oops... we need your login name & password\n"])
+ def authorized?
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
+ @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ["#{$user}", "#{$pass}"]
end
- end
+ def protected!
+ unless authorized?
+ response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
+ throw(:halt, [401, "Oops... we need your login name & password\n"])
+ end
+ end
+
+ end
+
configure :production, :development do
if "#{$log}".strip == 'on' then
enable :logging
end
end
@@ -256,16 +271,18 @@
$apps.each { |app|
## register token api
get "/v1/apps/#{app}/:token" do
- puts "[#{params[:token]}] was added to '#{app}'" if "#{$mode}".strip == 'development'
- o = Token.first(:app => app, :token => params[:token])
- unless o
- Token.insert(
- :app => app,
- :token => params[:token]
- )
+ if (("#{params[:token]}".length == 64) and iOS? ) then
+ puts "[#{params[:token]}] was added to '#{app}'" if "#{$mode}".strip == 'development'
+ o = Token.first(:app => app, :token => params[:token])
+ unless o
+ Token.insert(
+ :app => app,
+ :token => params[:token]
+ )
+ end
end
end
## http POST method push api
post "/v1/apps/#{app}/push" do
\ No newline at end of file