Problem with gem usage / installation
nbastoWM opened this issue · comments
Hi,
I've installed the gem as instructed, confirmed that the command line tool is working correctly with my certificate file, but when I add the usage sample code to a controller I get a couple of errors.
At first, if I use "APN" capitalized I get this error:
"dynamic constant assignment APN = Houston::Client.development ^"
So I changed to lower case "apn".
Then I get this error:
"cannot load such file -- houston"
I found out that the gem was not in Gemfile so I wrote a line with "gem 'houston' ". I also tried forcing the version - "gem 'houston', "~>2.2.3" " but the error persists.
I just use the code as instructed:
class Api::Mobile::PushController < SmileController
require 'houston'
def test
# use `Houston::Client.development` or `Houston::Client.production`.
apn = Houston::Client.development
# Dev.log apn
apn.certificate = File.read("../../../../apple/PushCertificate.pem")
token = "4ab587e47b612b7c678e76265443b75f848acde996680b87ed9fc06ac9ccece1"
notification = Houston::Notification.new(device: token)
notification.alert = "Hello, World!"
notification.badge = 1
notification.sound = "sosumi.aiff"
notification.category = "INVITE_CATEGORY"
notification.content_available = true
notification.custom_data = {foo: "bar"}
# And... sent! That's all it takes.
apn.push(notification)
render :json => {test: "asdasd"}
end
end
What am I doing wrong?
Thanks.
+1
same problem
Hey, how did you solved this problem?
Hi.
My code is working like this:
Before the class declaration:
require 'houston'
Then:
def send_ios_push_notification(title, text, type, param, sent_notification_id)
apn = Houston::Client.development
# manter este ficheiro na raiz do projecto
file = File.join(Rails.root, 'mycity_certificate.pem')
apn.certificate = File.read(file)
# Create a notification that alerts a message to the user, plays a sound, and sets the badge on the app
notification = Houston::Notification.new(device: self.token)
notification.alert = title
# Notifications can also change the badge count, have a custom sound, have a category identifier, indicate available Newsstand content, or pass along arbitrary data.
unviewed_notifications = user.sent_push_notifications.where('viewed = false').count
notification.badge = unviewed_notifications
notification.sound = "default"
notification.category = "REACT_NATIVE"
notification.content_available = true
notification.custom_data = { text: text,
type: type,
param: param,
sent_notification_id: sent_notification_id
}
# And... send!
apn.push(notification)
end
Thanks for your response I put require 'houston'
before the class declaration but I still get the error "cannot load such file -- houston". Do you any idea why is this happening?
It is working fine in my local machine but when I deployed it to the server it is then I am getting this error.
@genarolaunchlabs can you show your Gemfile and how you add gem houston in it?
here's my Gemfile
`source 'https://rubygems.org'
Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
gem 'pg', '>= 0.14.1'
gem 'devise', '> 4.1', '>= 4.1.1'> 1.6', '>= 1.6.1'
gem 'geocoder'
gem 'mailboxer', :git => 'git://github.com/div/mailboxer.git', :branch => 'rails42-foreigner'
gem 'unicorn'
gem 'houston'
gem 'awesome_print', '
gem 'sass-rails', '> 5.0'> 4.1.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '> 2.0'> 0.4.0', group: :doc
gem 'sdoc', '
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
`
I check houston if it is installed by gem list houston
and the result:
`*** LOCAL GEMS ***
houston (2.2.3)`