Pubnub and Rails 4 - ruby-on-rails

I'm following a twitter tutorial for a class project and I'm stuck at the part where the tutorial is using PUBNUB. I'm getting the following error:
Showing C:/RubyProjects/twitter/app/views/layouts/application.html.erb where line #93 raised:
**wrong number of arguments(1 for 0)**
Extracted source (around line #93):
PUBNUB.subscribe({
channel : "<%= Digest::SHA1.hexdigest(current_user.username, current_user.created_at) %>",
callback : function(message) { updateTimeline(message) }
I found on stackoverflow and found that EventMachine helped some folks and I tried that but still nada :(
I checked the PUBNUB page on Github and saw that it has changed the way channel and callback was written so I tried doing that but it did not help either. Im still getting the same error about wrong number of arguments(1 for 0).
Notify.rb
class Notify
def self.deliver_message_to_user(params)
post = Post.find(params[:post_id])
user = User.find(params[:user_id])
user.channel ||= Channel.new(
:channel_ident =>
Digest::SHA1.hexdigest(user.username, user.created_at.to_s))
Pubnub.publish({
:channel => user.channel.channel_ident,
:message => post.to_json(:include => :user)
})
end
end
application.html.erb
<script>
function updateTimeline(message) {
var html = JST['post'](jQuery.parseJSON(message));
$('#timeline').prepend(html);
}
Pubnub.subscribe({
:channel => "<%= Digest::SHA1.hexdigest(current_user.username, current_user.created_at) %>",
:callback => function(message) { updateTimeline(message) }
})
</script>
I put require 'digest' in my application.rb file and it still din't help. Could it be the syntax? If it is, i'm not sure what the correct syntax would be.

Publishing PubNub Messages in Ruby on Rails 4.0+
I'm pulling the following details from the PubNub Ruby README.md file - https://github.com/pubnub/ruby/blob/master/README.md
First you need to require PubNub lib from the PubNub Gem in Ruby.
## Require PubNub Gem
require 'pubnub'
## Instantiate a new PubNub instance.
pubnub = Pubnub.new(
:publish_key => 'demo', # publish_key only required if publishing.
:subscribe_key => 'demo', # required
:secret_key => nil, # optional, if used, message signing is enabled
:cipher_key => nil, # optional, if used, encryption is enabled
:ssl => nil # true or default is false
)
## Create a callback for checking response of Publish
#my_callback = lambda { |message| puts(message) }
## Execute Publish
pubnub.publish(
:channel => :hello_world,
:message => "hi",
:callback => #my_callback
)
## Sometimes you need a sleep depending on your server type
sleep(1)

Related

How to solve this error " (pre:svcFault) Service Fault"?

I am trying to call a SOAP api using Savon gem. I am getting the following error: "(pre:svcFault) Service Fault"
I created both the header and message for the request.
Here is the request sent from SoapUI: SoapUI request.
i am getting a true response from SoapUI.
My code is shown below:
class SoapApi
require 'savon'
def self.initialize
header = {
"ebmCID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmMID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmRTID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmSID" => "FMobile-FCUBS",
"ebmTimestamp" => "2019-06-10T12:27:46.1623586Z",
}
message = {
customerId: '00653473'
}
client = Savon.client(
:wsdl => "https://192.168.176.103:8012/tevs/pp.pm.evs.Customer_1.2?wsdl",
:ssl_verify_mode => :none
)
response = client.call(
:get_account_list,
:soap_header => header,
:message => message
)
return response
end
end
And here i am calling the above method:
#index.html.erb
<%=
SoapApi.initialize
puts #response
%>
Where you able to create a valid call using SoapUI (https://www.soapui.org.)? Try this first and make it work.
Next create a call from a plain ruby script - without Rails - which sends the same functional XML as you did in SoapUI before.
Third embed this code into your RoR application.
You can put the following in your client definition for better logging:
client = Savon.client(
:wsdl => "https://192.168.176.103:8012/tevs/pp.pm.evs.Customer_1.2?wsdl",
:ssl_verify_mode => :none,
log: true,
log_level: :debug,
pretty_print_xml: true
)
Compare the output with your working SoapUI example.

private method issues

I am having issues with private method capabilities.
Here is a my sample env.rb file
require 'rspec/expectations'
require 'selenium-webdriver'
#APP_PATH = 'PlainNote.app'
def capabilities
{
'automationName' => 'XCUITest',
'platformName' => 'iOS',
'deviceName' => 'iPhone Simulator',
'platform' => 'Mac',
'version' => '9.2',
'app' => '/Users/shafiq.malik/Documents/Projects/nuff-class-booking-mobile/platforms/ios/build/emulator/HelloCordova.app'}
end
#def absolute_app_path
# File.join(File.dirname(__FILE__), APP_PATH)
#end
def server_url
"http://localhost:8000/index.html"
end
def selenium
#driver ||= Selenium::WebDriver.for(:remote, :desired_capabilities =>
capabilities, :url => server_url)
end
After { #driver.quit }
However I am getting the below error message
Given I load the hello world app # features/step_definitions/hello_world.rb:1
private method `capabilities' called for #<Hash:0x007fb9b07c7da8> (NoMethodError)
./features/support/env.rb:25:in `selenium'
I completely new to mobile testing. So it may be a very straight forward solution. Can somebody please be kind enough to advise where I am going wrong.
You should not use capabilities as method name in that situation.
Maybe it's defined in Kernel or anywhere else.
Sometimes that could happen when we use some reserved names for our needs. You could check where that method come from via p method(:capabilities) before your definition.

Pushmeup Gem - Can't send push notifications in Active Admin model

I'm creating a CRM/CMS in Rails using Active Admin.
I've used Pushmeup Gem for the APNS(Apple Push notification service) functionality but I can't seem to make it work.
Here's what I did.
Forked the Pushmeup Gem to create my own repository. I've edited the configurations to match my credentials.
gem 'pushmeup', :git => 'git://github.com/thisisnotme/pushmeup.git'
I've followed the instructions here.
Here's my app/admin/token.rb file.
collection_action :apns, method: :get do
device_token = '7eb2c5fa7f3b0be45cb3613b1d05470c5b76b90929a8ce49d2e511d7b1245d8a'
APNS.send_notification(device_token, 'Hello iPhone!' )
APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
end
This came up on my screen:
NoMethodError in Admin::DeviceTokensController#apns
undefined method `close' for nil:NilClass
Extracted source (around line #19):
17
18
19
20
21
22
collection_action :apns, method: :get do
device_token = '7eb2c5fa7f3b0be45cb3613b1d05470c5b76b90929a8ce49d2e511d7b1245d8a'
APNS.send_notification(device_token, 'Hello iPhone!' )
APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
end
It seems that the APNS class is missing. I'm kinda lost. Sorry Rails Newbie.
I've found that the host and port are defined as follows:
module APNS
#host = 'gateway.sandbox.push.apple.com'
#port = 2195
class << self
attr_accessor :host, :pem, :port, :pass
end
end
So you just can redefine APNS variables, as it is shown in the README:
APNS.host = 'gateway.push.apple.com'
APNS.port = 2195
APNS.pem = '/path/to/pem/file'
APNS.pass = ''
Maybe this is kinda late but I had the same error. It was thrown because I did not extract the certificate AND the key from the keychain into a single PEM file.

NoMethodError: undefined method `const_defined?' when referring to class methods

I am building an email sending system into an already fairly complex rails app.
From a controller I'm trying to call a method that builds an email and then delivers it.
In controller:
response_for :create, :update do
estimate = current_object.estimate.reload
flash[:success] = "Tier Save Successful. "
flash[:success] += send_estimate_email if estimate.verify && estimate.tiers.select{|t| !t.verified?}.empty?
flash[:notice] = "This service bundle was changed for a previously verified service bundle. Please re-verify after changes are complete" if current_object.auto_unverified
redirect_to [current_object.estimate]
end
def send_estimate_email
return "" if current_object.estimate.requestor_email.blank? || !current_object.estimate.requestor_notified_at.blank?
begin
estimate = current_object.estimate
host = request.host_with_port
binding.pry
success = EstimateEmailer.deliver_verification_complete(estimate, host)
current_object.estimate.notes.create!(:user_id => User.find(:first, :conditions => {:user_type_id => UserType::ROOT.id}).id, :title => "Verification Complete Email Sent", :body => "TO: #{success.to}\nSUBJECT: #{success.subject}\nBODY: #{success.body}")
rescue Exception => e
logger.warn(e)
success = false
end
if success
current_object.estimate.update_attribute(:requestor_notified_at, Time.now)
current_object.estimate.notes.create!(:title => "Auto-email sent to requestor", :body => "TO: #{success.to}\nSUBJECT: #{success.subject}\nBODY: #{success.body}", :user_id => current_user.id)
return "Automatic estimate email was successfully sent to #{current_object.estimate.requestor_email}"
else
return "However, automatic estimate email could not be sent due to an error"
end
end
I don't think there's anything wrong with the email code itself, but for some reason I get this error on the EstimateEmailer.deliver_verification_complete(estimate, host) call:
NoMethodError: undefined method `const_defined?' for "estimate":String
setting a breakpoint in the controller before the EstimateEmailer call I notice that I get the error whenever I try to refer to other classes. Just calling EstimateEmailer or any other class name returns the same error.
I've run into issues with undefined method const_defined? in the past. I'm guessing the issue isn't specific to emailing, but I haven't the slightest idea where to begin debugging.
def verification_complete(estimate, host)
request_id = estimate.integration_transactions.empty? ? "Internal ID #{estimate.id}" : estimate.integration_transactions.last.source_id
#estimate = estimate
#estimate_url = public_estimate_url(estimate.public_id, :host => host, :protocol => 'https')
mail(
subject: "Ref ##{estimate.project_code} Application Hosting Estimate Available for Review: #{request_id}",
to: [estimate.requestor_email, estimate.project_manager_email].reject{|email| email.blank? }.join(','),
from: SUPPORT_ADDRESS
)
end
You're using make_resourceful which has an incompatibility with current versions of ActiveSupport. I've just lodged a PR that addresses it: https://github.com/hcatlin/make_resourceful/pull/16.
Alternatively, you can point to the remote branch in your Gemfile:
gem 'make_resourceful', github: 'carpodaster/make_resourceful', branch: 'fix/incompatibility-with-active-support-dependencies'
I assume this problem only occurs in your development environment, right? In that case, you should be able to avoid it by setting config.eager_load = true in config/environments/development.rb.

rails twitter_oauth library uninitialized constant

I'm trying to use the twitter_oauth gem : http://github.com/moomerman/twitter_oauth
In my model I have:
require 'twitter_oauth'
And within a function I have:
def example
client = TwitterOAuth::Client.new(
:consumer_key => 'xxxx',
:consumer_secret => 'xxxx',
:token => "xxxx",
:secret => "xxxx")
return client
end
This seems fairly straight forward, but I can't seem to find out why I'm getting this error:
(Event being the name of the model)
uninitialized constant Event::TwitterOAuth
I can't seem to locate any conflicts with the TwitterOAuth namespace, any other thoughts?
Decided to use Grackle instead, seems to work fine

Resources