Flickr gem : how to access user details? - ruby-on-rails

https://github.com/ctagg/flickr/tree/master
I'm trying the example in the home page of the GEM Flickr.
require 'flickr'
flickr = Flickr.new('MY_KEY')
user = flickr.users('sco#scottraymond.net')
user.name
user.location
While I'm able to get the user object, I can't get any of the other attributes like name, location etc. How to get those details?

I worked through the problem I was experiencing above in my comment but I am not having difficulty getting people's attributes. The following code works as expected in a ruby script/console session:
require 'flickr'
f = Flickr.new('<<MY_KEY>>')
u = f.users('sco#scottraymond.net')
puts u.name
puts u.location
Substituting my username ('topherfangio') instead of Scott's, the name attribute works, but apparently my location is nil.
Could you describe a little bit more about exactly what you are getting? Any errors or is it just blank? Have you tried multiple users?
Edit 1: Just got your API key and it doesn't work for me either, try the following and see if that makes any difference. Also, are you using a non-commercial key or a commercial key?
f = Flickr.new(:api_key => 'MY_KEY', :shared_secret => 'MY_SECRET')
My guess is that it's not fully authenticating or something like that.
Edit 2: I'm a freaking liar...I was typing f = Flickr.new(...); f.name which was breaking. Your API key is working correctly for me. Perhaps it's your network or something?

To not entirely answer your question, I've been using the Fleakr gem and found it to be extremely straightforward.
Documentation is good and you do everything in the code once it is installed.
No tricks, just sudo gem install fleakr
It depends on the builder gem, so also do sudo gem install builder.
Once I switched to Fleakr my project finished quickly!

It looks like the flickr gem isn't being maintained. Uninstall the gem by doing a gem uninstall flickr, then install a more up to date branch of it by doing a gem install moonpxi-flickr

Related

ApiAuth gem + ActiveResource

I'm trying to get ApiAuth working with ActiveResource and having no luck. The documentation suggests this as the way to use the gem:
class Foo < ActiveResource::Base
with_api_auth("foo", "bar")
end
This results in the following error:
NoMethodError: undefined method `with_api_auth' for Foo:Class
I know that the api_auth library is available because when I do
require 'api_auth'
i get "false", which I believe means that the library/gem was already loaded.
Additionally, I picked out the module/class where with_api_auth is defined and don't get an error:
2.3.8 :004 >
ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
=> ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
2.3.8 :005 >
I found a couple issues for this exact error on the api_auth github project, but neither had solutions that worked for me.
Anyone else see this error or know how to eliminate it?
So in the end it was an ordering of gems in my Gemfile that made the difference. It ended up being an ordering issue in my Gemfile. I found an issue (113) on the gem github issues list that said to make sure the order was right by doing:
gem 'activeresource'
gem 'api-auth'
Originally this hadn't worked and it ended up being because you no longer have to explicitly put activeresource in your Gemfile. So I moved gem 'api-auth' the last line in my Gemfile and everything worked.
I don't know for sure, but I think it has to do with how mixins are loaded on bundle install. "think" being the most important word in that statement.

Will_paginate with mongoid (total_entries issue)

When using mongoid with 'will_paginate' gem, it seems like method called 'total_entries' doesnt work which can affect perfomance
So I was using Mongoid with 'will_paginate' gem and I had this problem with 'total_entries' option, and to be more specific, I dont think it was working at all, which is not very good for perfomance in many situations...
After a while I found this gem but it didnt look like 'total_entries' method was working there so here's what I did:
1) Opened mongoid_paginator in will_paginate_mongoid location
2) Made a little fix, so it looked like this:
WillPaginate::Collection.create(options[:page], options[:per_page]) do |pager|
items_count = options[:total_entries] || self.count
fill_pager_with self.skip(options[:offset]).limit(options[:per_page]), items_count, pager
which I took from here and hallelujah, it works again, no more counts on every load.
Since I am a newbie I could make something foolish and I hope I will be corrected if so and hope it'll be helpful for somebody :)

How to install Alchemist on Ruby on Rails

How do I install the Alchemist gem?
I have added gem 'alchemist' to my Gemfile
bundle install
then I try 10.miles.to.kilometers and get an error: undefined methodmiles'`
according to alchemist I have to add Alchemist.setup somewhere. Where do I add this?
I don't know the gem, but you can try to put it in an initializer, ie in config/initializers/alchemist.rb:
Alchemist.setup
Restart your app after you have added this file.
In terms of your second problem. If you call to_f on an Alchemist::Measurement it gives you the value in terms of the base (in this case meters). If you want to get the number of kilometers you need to call value on it:
irb(main):005:0> 10.miles.to.kilometers.value
=> 16.09344
There might be a useful discussion on if I should change these if they are confusing.

Cannot find gem in controller

I'm sure this is an easy question but I'm having a hard time figuring out what to Google.
I'm trying to use the library ChunkyPNG.
I added it to my Gemfile and did a bundle install.
bundle list | grep "chunky"
* chunky_png (1.2.5)
So far so good.
I try using it in my controller:
image = ChunkyPNG::Canvas.from_data_url(params[:data]).to_image
(The docs for this method are available here)
It results in the following error:
NameError in MyController#create
uninitialized constant MyController::ChunkyPNG
Why is prepending the controller namespace? I imagine that's what is causing the error.
Otherwise, it means that ChunkyPNG is not install (and it clearly is).
Am I not able to use this gem upfront without writing some sort of rails plugin to wrap around it?
Thanks
EDIT:
Question has been answered, see #apneadiving's comment
In your controller, or somewhere else in the app do:
require 'chunky_png'

Sunspot and RSpec fail. The commit doesn't seem to be working

I've got a few tests running with RSpec for a Rails site, but despite
following the instructions things aren't quite behaving themselves.
I create an article via a Factory, run Sunspot.commit and then check
the results. I always seem to draw a blank though. When I test it
manually via the console or through the website it all works find
though.
Any ideas? How can I output the sunspot logs to see what's going on?
My Gemfile has the following, and I'm running Rails 3.1.1
gem 'sunspot', '1.2.1'
gem 'sunspot_rails'
gem 'sunspot_test'
Many thanks,
Graeme
It was my fault for not reading the manual properly.
https://github.com/collectiveidea/sunspot_test/issues/9
It's necessary to add a magic bit to the description to make sure that Solr is started.
describe "my nice test", :search => true do
thing = Factory.create(:thing)
Sunspot.commit
# do my search and test
# now it works!
end
It's the :search => true that's important.
Just to add a little something to the response above; if using FactoryGirl:
FactoryGirl.define do
after(:create) { Sunspot.commit }
...
end
then you won't have to add the commit call on each test file...

Resources