Sinatra and Foursquare - undefined method `web_server' - ruby

I'm trying to run a simple Foursquare auth in Ruby with Sinatra. I am using the example here.
When I try to run this code on my local server, I get this error
NoMethodError at /
undefined method `web_server' for #<OAuth2::Client:0x16168bc>
I can't figure out how to fix this... Ideas?

the web_server method was removed in v0.5.0 of the OAuth2 ruby gem.
install a prior version of the gem to make use of the missing method:
gem install oauth2 -v 0.4.1
and modify your script by adding the following line before the require 'oauth2' so it will only accept that particular version of the gem:
gem 'oauth2', '=0.4.1'
edit: looks like the example hasn't been updated for a while -- I forked it and included the above suggested workaround (which has since been merged into the original repository).

Related

How to get started with the gmail-ruby-api gem

I working with Gmail using the Gmail for Ruby gem, but can't figure out how to get started with it.
The documentation say: I could do something like:
require "gmail"
Gmail.client_id = "...Your app client id..."
Gmail.client_secret = "…app secret…"
Gmail.refresh_token = "...refresh token…"
Gmail::Message.all
But then I got this error:
undefined method `client_id=' for Gmail:Module (NoMethodError)
I also tried initializing it like this:
require 'Gmail'
Gmail.new
Gmail.client_id = "...Your app client id..."
Gmail.client_secret = "…app secret…"
Gmail.refresh_token = "...refresh token…"
Gmail::Message.all
But then got:
`initialize': wrong number of arguments (given 0, expected 2..3) (ArgumentError)
I can't tell what arguments it's looking for.
You may follow this official documentation for a sample simple Ruby command-line application that makes requests to the Gmail API..
Installing the google-api-client gem
If you haven't installed the Google API Client Library for Ruby before, open a terminal and install using RubyGems:
$ gem install google-api-client
If you already have the gem installed and would simply like to update to the latest version:
$ gem update -y google-api-client
Depending on your system, you may need to prepend these commands with sudo.
Be sure to check the extensive Getting started guide for a quick overview of how to make your first request.

Methods from Tree::TreeNode not working

I have a question about ruby gems. I'm writing some code in ruby and I want to use a tree. I decided to use the Tree::TreeNode class. See here http://www.rubydoc.info/github/evolve75/RubyTree/Tree/TreeNode for documentation.
This is my first time using a gem. I ran sudo gem install tree in the terminal and added require 'tree' to the beginning of my ruby file. For the most part it works. I can initialize nodes and most of the methods work. However, some methods such as #each_leaf and #children don't work. Here's example code:
require 'tree'
node1 = Tree::TreeNode.new('node1',1)
node2 = Tree::TreeNode.new('node2',2)
node1.add(node2)
node1.each_leaf { |node| puts "name: #{node.name}, content: #{node.content}"}
When I run it I get the following error message:
test.rb:5:in `<main>': undefined method `each_leaf' for #<Tree::TreeNode:0x007fc2a905e560> (NoMethodError)
but when I run the code with each_leaf replaced by each it works perfectly (of course I get info for nodes 1 and 2, whereas if it worked each_leaf should only get me the info for node 2).
Looking through the documentation for TreeNode I've noticed that all the methods that don't work for me are listed next to Tree::TreeNode+ rather than Tree::TreeNode. I haven't been able to figure out what this means. Do I have to do something extra or install some other gem to get those methods? Thanks for any help!
This is because the version of the gem on rubygems.org lags behind the latest version on github (from which the documentation is generated). You can install the github version using:
gem install specific_install
gem specific_install -l https://github.com/evolve75/RubyTree.git
or just add it to your Gemfile:
gem 'tree', github: 'evolve75/RubyTree'
Update: looks like it does have the latest version on rubygems, but it's renamed to rubytree, hence
gem uninstall tree
gem install rubytree
but require 'tree' as you did before.

Ruby Shoes App, Gem Chef: bad response Not Found 404

I'm trying to write a Shoes app that will call Chef classes and modules. To accomplish this, I'm using Shoes 3.2.21-gtk2 and using the following code before my Shoes app code:
Shoes.setup do
gem 'chef'
end
Shoes.app do
...
end
When I run the app from Shoes, it attempts to install chef, and even determines the latest version (12.0.3) however, I get the following error during the installation:
bad response Not Found 404 (https://rubygems.global.ssl.fastly.net/quick/Marshal.4.8/pry-0.10.1-x86-mingw32.gemspec.rz)
This version of Shoes is using Ruby 2.1.5-p273, which satisfies the minimum requirement of the Chef gem: https://rubygems.org/gems/chef
Is there some bug in Shoes with its ssl code? Or am I missing something else?
I got this error too.
The error occurs when trying to install the "pry gem". In my case was a bug that happened in my old version of rubygems (2.4.6).
FIX:
1 - Install another version of rubygems
gem update --system 2.4.4
2 - Install pry
gem install pry
The error also happens with the 2.4.5 version of rubygems: https://github.com/rubygems/rubygems/issues/1120

How to get has_secure_password to work in production?

I'm using has_secure_password in a new application and it works great locally. However, when I deploy to our server and try to run it I get the following error message:
undefined local variable or method `has_secure_password' for
WorkerLogin:Class
I did a bundle install and everything so I'm not sure what's missing. I'm on ruby 1.9.2p290 but I don't think that would be the problem.
Thoughts?
I eventually realized I didn't have my latest code pushed to GitHub yet when I did the Capistrano deployment. I had include ActiveModel::SecurePassword added to my WorkerLogin class but not checked in. This line is required because I'm using MongoDB/MongoMapper and it doesn't automatically include ActiveModel::SecurePassword like ActiveRecord does.
In Gemfile uncomment or add this line:
gem 'bcrypt-ruby', '~> 3.0.0'
and run bundle install

Why am I getting a NameError out of the box with rails SimpleRecord?

I installed the simple_record gem to use as an ActiveRecord replacement for my rails app. I followed the instructions from http://sites.appoxy.com/simple_record/ and setup an initializer to include the following:
SimpleRecord.establish_connection(AWS_CONFIG['access_key_id'], AWS_CONFIG['secret_access_key'])
When I fire up the rails server (rails s) with I get the following error:
.../.rvm/gems/ruby-1.9.3-p125/gems/simple_record-2.2.0/lib/simple_record/active_sdb.rb:121:in `establish_connection': uninitialized constant SimpleRecord::ActiveSdb::ActiveSdbConnect::Aws (NameError)
It seems that it is trying to find the class name "SimpleRecord::ActiveSdb::ActiveSdbConnect::Aws" but Aws doesn't existing within that namespace. SimpleRecord does require Aws, but it is separate from SimpleRecord. Why would rails be prepending Aws with the SimpleRecord::... namespace?
I'm fairly new to ruby and rails, so maybe my knowledge of name-spacing is lacking and this is an easy fix, but I've been searching for hours and I can't find any answers to my question.
Ruby version: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Rails version: Rails 3.2.1
SimpleRecord version: 2.2.0
I appreciate the help, but after a couple hours of testing things out, I realized that the issue was a conflict between the simple_record gem and the aws-sdk gem. I was trying to use both separately, but apparently that causes issues.
So, I disabled the aws-sdk gem and everything works as expected.
So reading the error message we can get the following, that in here: active_sdb.rb:121 https://github.com/appoxy/simple_record/blob/master/lib/simple_record/active_sdb.rb#L121
the following method requires aws_access_key_id, aws_secret_access_key and some other params
def establish_connection(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
#connection = Aws::SdbInterface.new(aws_access_key_id, aws_secret_access_key, params)
end
So I suspect that Amazon web services access key/secret access key haven't been set up yet or were set up wrongly.
You might want to dig into the code deeper and see where the method was called and what else may cause the problem

Resources