I have the apn_for_rails gem installed and configured correctly, the problem I’m running into is probably a syntax problem due to my newness to Ruby on Rails.
I have this in /models under the file push_notification.rb
class ApnDevice < ActiveRecord::Base
end
in routes.rb
match '/api/v2.0/RegisterIOSDevice', :to => Api::V_2_0::ApiNotifications
and then I have another file in /lib/api/v_2_0 called api_notifications.rb
require 'rubygems'
require 'sinatra/base'
require 'nokogiri'
require 'apn_on_rails'
module Api
module V_2_0
class ApiPushNotification < sinatra::Base
include ApplicationHelper
include Api::V_2_0::ApiResponse
include ApiUtil
def push_notification(params)
status = -1
error = nil
begin
if params[:device_token].blank?
return status_respnse(params,status,'device_token cant be blank')
end
existing_device_token = ApnDevice.find_by_token(params[:device_token])
if existing_device_token
return status_response(params,status,'Token already exists for device')
end
token = ApnDevice.create!(:token => params[:device_token])
rescue Exception => e
error = e.message
Rails.logger.info "#{e.class} : #{e.message}"
Rails.logger.info e.backtrace.join("\n")
rescue => e
error = e
Rails.logger.info "Caught exception: #{e}"
Rails.logger.info e.backtrace.join("\n")
end #end of rescue
status_response(params,status,error)
end
get '/api/v2.0/RegisterIOSDevice.:format' do
push_notification(params)
end
post '/api/v2.0/RegisterIosDevice.:format' do
push_notification(params)
end
end #end of class ApiPushNotification
end #end of module V_2_0
end #end of module Api
but it gives me this huge error when I run my server, I won’t post the whole thing, but it says this basically
/lib/api/v_2_0/api_notifications.rb:7: invalid multibyte char (US-ASCII) (SyntaxError)
/lib/api/v_2_0/api_notifications.rb:7: syntax error, unexpected $end, expecting keyword_end
this is followed by a stack trace which I will not post but I can’t seem to find the problem, any ideas?
Edit:
ok I added the utf-8 suggestion, now I’m getting a new error:
lib/api/v_2_0/api_notifications.rb:46: syntax error, unexpected keyword_end, expecting $end (SyntaxError)
I don’t know what you are doing there, but why are you using Rails if you use Sinatra instead in lib?
To your error, add the following code at the first line: