rails twitter_oauth library uninitialized constant - ruby-on-rails

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

Related

keep getting 'client' method undefined when running rails app

trying to add this to my rails project https://github.com/adelevie/parse-ruby-client
so i first obviously bundle installed the gem, then i created a parse.rb file in config/initializers with this code :
require 'parse-ruby-client'
client = Parse.create :application_id => 'API_KEY',
:api_key => 'API_KEY',
when i call client anywhere i get a error that its undefined
In your example client is a local variable. By the time you try to access it, it has already left the scope. What you should do is create or use a globally visible object. One example:
require 'parse-ruby-client'
::MyParse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
You can access such object as MyParse in the code.
Another example:
require 'parse-ruby-client'
MyApp::Application.configure do
config.parse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
end
And use it like this:
MyApp::Application.config.parse

uninitialized constant Name_of_controller::Savon

I am using savon gem to interact with a SOAP API.
client = Savon.client(wsdl: "http://karvymfs.com/CP_STP_SERVICE/STPService.svc?singleWsdl")
xmlkarvy = "<file>...........</file>"
#response = client.call(:stp_upload, message: {"FundCode" =>"AXF","UserID" => ".............", "Password"=> "..................", "ARNCode" => "..........", "IPAddress" => "..............", "XMLFile" => xmlkarvy , "Branch" => "?"})
Works absolutely fine in IRB but when the same code is used in a controller I get the error.
uninitialized constant ControllerName::Savon
write following before controller class
require 'savon'
This is mentioned in the gem documentation too.

accesing contacts via omnicontacts gem routing error

hey i'm trying to access contacts from gmail/yahoo etc using omnicontacts gem,
https://github.com/Diego81/omnicontacts
i'm able to get the responce from the site but not able to rout to my page and getting routing errors
Internal Server Error
uninitialized constant ContactsLists
and
uninitialized constant ContactsListsController
or
The action 'gmail' could not be found for InvitesController
config files are below
Rails.application.middleware.use OmniContacts::Builder do
importer :gmail, "client_id", "client_secret", {:redirect_path => "/contact_callback"}
end
in google console
Redirect URIs is set to
mylocaldomain.com/contact_callback
and i want t oroute the data to my contact_list controller and invite method so in routes i have defined
match "contact_callback" => '/contacts_lists/invitenew'
and i'm getting http://mylocaldomain.com/contact_callback?code=4/jGYoPAYuZiuW5uR2UjDPmqF6Hjtj.4oxoCiD-BVUQXE-sT2ZLcbShVA5nhwI
let me know what i'm doing wrong.
** EDIT **
omnicontacts.rb
#check https://github.com/Diego81/omnicontacts for more info
Rails.application.middleware.use OmniContacts::Builder do
importer :gmail, "XXX", "****", {:redirect_path => "/contact_lists/gmail/contact_callback"}
importer :yahoo, "XXX", "****", {:callback_path => "/conta"215641561956751", "86245e1a6e7ce9b9e59cf440d5262e12",ct_lists/yahoo/contact_callback"}
importer :hotmail, "000000004011440B", "ah89ykZYvM1CcohvJhdcfEKaJL9Oktjt" , {:redirect_path => "/contact_lists/hotmail/contact_callback"}
importer :facebook, "XXX", "****", {:redirect_path => "/contact_lists/facebook/contact_callback"}
end
routes.rb
get "/contact_lists/facebook/contact_callback" => "contact_lists#getfbinvite"
# get "/contact_lists/:provider/contact_callback" => "contact_lists#getinvite" #commented temp
get "/contact_lists/gmail/contact_callback" => "contact_lists#getinvite"
get "/contact_lists/yahoo/contact_callback" => "contact_lists#getinvite"
get "/contact_lists/hotmail/contact_callback" => "contact_lists#getinvite"
This will solve the problem for me.now i have all diff function for all sites as per requirement. Hope this helps you .

Pubnub and Rails 4

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)

How to implement badgeville in ruby on rails

Can anyone tell me how to implement badgeville in ruby on rails?
EDIT:
how can I apply this on ruby on rails?
https://github.com/badgeville/badgeville-ruby
I'm not sure how this particular gem work, but normally it should work with following steps
create a file called 'badgeville.rb' inside app/config/initializers
add the following code to badgeville.rb
BadgevilleBerlin::Config.conf(
:host_name => "http://example.com",
:api_key => MY_API_KEY)
restart
then you should be able to use the following commands inside your
controllers/ models
Ex:
new_site = BadgevilleBerlin::Site.new(
:name => "My Website",
:url => "mydomain.com",
:network_id => MY_NETWORK_ID )
success = new_site.save

Resources