FourSquare: Adding new version parameter to all requests in rails app - ruby-on-rails

I am using devise/omniauth-foursquare and have recently run into difficulties now that foursquare is requesting the version parameter with every request. I get this error on everything:
Foursquare::Error (A required parameter was missing or a parameter was malformed. This is also used if the resource ID in the path is incorrect.):
I know with the recent foursquare update I need to add the v=20131016 parameter to all my requests, but I am not sure how to add it.
My devise configuration looks like this:
require 'omniauth-foursquare'
config.omniauth :foursquare, "[MY_APP_ID]", "[MY_SECRET_ID]"
I also access foursquare like this:
def foursquare
#foursquare ||= Foursquare::Base.new(fs_app_id, fs_secret)
end
Any help would be appreciated!

you need to add the newest omniauth-foursquare version to your gemfile. The branch was just updated a few days ago with:
#raw_info ||= access_token.get('https://api.foursquare.com/v2/. users/self?v=20140128').parsed['response']. ['user']
Then everything should be working like a charm again.

Related

In Ruby on Rails, how to intercept the Devise gem's email sending functionality and change it to call an API instead? [duplicate]

As my reputation is lower than 50, so Im not able to comment below the accepted answer in this post In Rails Devise gem how to modify the send_reset_password_instructions method? for more information.
I want to customize recoverable.rb in devise. I made a copy of it in my folder with path lib/devise/models/recoverable.rb. The problem is when request to send reset password instruction, I got error undefined method activerecord51? for Devise:Module. How do i solve this?
It seems my recoverable is not in Devise module. I tried a bit by making a copy of devise.rb in lib/ folder. But it doesn't help.
Can someone please help?
EDIT
Sorry for any inconvenience. At the moment Im just trying to pass more opts to the method send_reset_password_instructions.
Any idea about this?
How about do it in some rails initializer? Your are possibly overwriting the original class/module so all the other methods are gone.
# config/initalizers/devise.rb
Devise::Models::Recoverable::ClassMethods.module_eval do
def send_reset_password_instructions(your, params)
token = set_reset_password_token
send_reset_password_instructions_notification(token)
token
end
end

Rails finding by params

I'm building a API and want the show page for a user to be found by 'uid' instead of the record ID
I have this in my controller
def show
respond_with User.find_by_uid(params[:uid])
end
When I go to localhost/api/v1/users/8888888 Its returns "Null"
Finding by ID seems to work fine, am I doing something wrong here?
I tried put this in the rails console and it worked
User.find_by_uid("8888888")
I'm new to rails
Thanks
have you tried visiting:
localhost/api/v1/users?uid= 8888888 instead of the url you are using currently, except you are handling that correctly rails would have no knowledge of the uid param alternatively you could add this to your config/routes.rb file
get 'users/:uid', to: 'users#show'
With the hope that your controller is called UsersController then you can call localhost/api/v1/users/8888888 in your browser and it should behave as expected
Rather than just giving you the answer, I'll provide a tip on debugging Ruby applications (including Rails).
Get the pry gem and the pry-debugger gem and include them in your Rails application (there's plenty of posts around Google on how to include pry and pry-debugger in Rails).
put 'binding.pry' (without the quotes) at the beginning of your show method. In the console where your server runs, when show gets executed, execution will halt/pause at binding.pry. Type the following in the pry console to see what is available in the rails params hash.
pry> params
(this will print out the contents of params)
I would start my troubleshooting here, and post the contents of params and any relevant server logging here if you still can't figure it out.
edit
I don't have enough rep to comment, yet. Only really been on this site and using it a day or two.

How do I used the linkedin gem to parse a profile in rails?

I am using the linkedin gem https://github.com/pengwynn/linkedin
I authorize using Omniauth and store the access token and secrets.
I then authorize by access with the client.
I appear to get something useful when I type client.profile -- but it looks like mostly Nokogiri but in a LinkedIn::Profile class.
How do I specifically access fields, and will I be able to use method calls from the View in rails or do I need to do all the parsing in the controller and pass those values to the View from there.
Example of how to access the profile image url, title, name, company that sort of thing once I have established client.profile would be great.
When I use the (:fields =>) I get back something like this:
#<LinkedIn::Profile:0xb682c72c #doc=#<Nokogiri::XML::Document:0x..fdb41630a name="document" children=[#<Nokogiri::XML::Element:0x..fdb415fae name="person" children=[#<Nokogiri::XML::Text:0x..fdb415d88 "\n ">, #<Nokogiri::XML::Element:0x..fdb415d24 name="picture-url" children=[#<Nokogiri::XML::Text:0x..fdb415aae "http://media.linkedis:
I just want the string associated with the node "picture-url"...how do I do that?
From controller:
7 `def show`
8 #user = User.find(params[:id])
9 #client = LinkedIn::Client.new(ENV["LINKEDIN_KEY"], ENV["LINKEDIN_SECRET"])
10 #client.authorize_from_access(#user.atoken, #user.asecret)
11 #client.profile(:id => #user.uid, :fields => ["picture-url", "headline"])
12
13 end
New error:
undefined method `downcase' for nil:NilClass
Here is a related question: "https://stackoverflow.com/questions/5821549/how-do-i-pass-a-a-tag-through-ruby-to-linkedin-using-the-gem"
I did it by adding:
client.profile(:fields => [:positions]).positions
This would then allow me to access specific positions or fields without going into the raw xml, just using the methods in the gem. The gem works nicely once I get the format...
I suggest you get the latest version of linked_in gem from github. It uses Hashie/Mashie syntax which is much simpler than dealing with Nokogiri output and XPath.
If youre using bundler add this to your Gemfile(removing any other linked_in gem reference)
gem 'linkedin', :git => "git://github.com/pengwynn/linkedin.git"
this version of the gem basically sticks the output of your Linked In search into a hash, so you would access your picture-url string as follows: profileHash["picture-url"]
P.S. if you do decide to stick with your version of linked_in gem, get familiarized with XPath syntax, you will need it. Based on the information you provided, the picture url string will be available via profileXML.xpath("//person/picture-url").first.text

flickr-fu simple example not working

I'm using flickr-fu gem within a rails application for flickr api integration. I'm following the sample code for setting up a web app shown below:
def flickr_create
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
redirect_to flickr.auth.url(:read)
end
def flickr_callback
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
flickr.auth.frob = params[:frob]
current_user.update_attribute :flickr_token, flickr.auth.token.token
flash[:notice] = "Succesfully authenticated with Flickr"
redirect_to :flickr_stream
end
I've registered flickr_callback as the callback method that flickr calls after the authorization process.
The problem is with the line in flickr_callback when I try and assign params[:frob] to flickr.auth.frob. I get the following error:
undefined method `frob=' for Flickr::Auth:0x24b3640
Even if I just require 'flickr_fu' from within console, create a new flickr instance, and attempt to assign to frob, I get the same error. I took a look at the gem source on github, and the setter frob= is set within the Flickr::Auth module, so I'm clueless as to where the error is. The API calls work successfully and the flickr object is initialized fine.
The issue is that the flickr-fu gem from gemcutter or github is at version 0.1.4, and the frob setter method wasn't implemented until subsequent version. Instead install the gem commonthread-flickr_fu v0.3.0 from github, and the frob is writeable.

Ruby on Rails 2.1 Subdomain-Cookie issues

When using a subdomain and trying to view anything related to current_user. user is sent to a new session page, the page shows the session is created and gives the option to logout. I can use no subdomain and it works fine.
Set it in your environment.rb (or environments/*.rb if you'll use different domains for each environment):
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update( :session_domain => '.domain.com')
FYI... as of Rails 2.3, this setting has changed. The rails 2.3+ version looks like:
ActionController::Base.session_options[:domain] = '.domain.com'
Just in case anyone else lands here from Google and gets confused like I did.
#jkrall - to add to that, the whole options hash moved to :key, :secret, and :domain vs :session_key, :session_domain, etc.

Resources