Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Find flickr photos using tags from rails

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> API
View previous topic :: View next topic  
Author Message
Raghu



Joined: 12 Mar 2009
Posts: 29

PostPosted: Tue Jul 28, 2009 7:27 am    Post subject: Find flickr photos using tags from rails Reply with quote

Flickr is an image and video hosting website, web services suite, and online community platform.

Using API key we integrate flickr to our rails application as follows.

(You may need to login to Flickr first.)
You must have an API key to make use of the Flickr API.

You can get api key below url
url: http://www.flickr.com/services/api/misc.api_keys.html

• Click on Apply for your api key
• Click on Apply for a Non-Commercial API Key
Once submitting all required information you will get the following API key and Secret

Sample
Key:
5c211baf9bd705496b21522132c80148
Secret:
bb6500467b1af07f

Click on - Edit key details and select the Authentication Type: Web Application.

Once all the settings have been completed its time to create and rails application.

You must have need Flickr gem, now install the
>gem install flickr

Create a sample rails application for flickr
>rails flickr-demo

Add the following code at the bottom of the environment.rb file

require 'rubygems'
require 'flickr'
MY_KEY='Enter your Flicker API Key'
class Flickr
alias old_initialize initialize
def initialize(api_key=MY_KEY, email=nil, password=nil)
puts "new_initialize " + MY_KEY
old_initialize(api_key, email, password)
@host="http://api.flickr.com"
@activity_file='flickr_activity_cache.xml'
end
end

Add the following rhtml code at application.rhtml in your sample rails application

<html>
<head>
<title>Flickr</title>
<%= javascript_include_tag :defaults %>
<%= stylesheet_link_tag 'flickr' %>
</head>
<body>
<%= yield %>
</body>
</html>



Add the following styles at public\stylesheets\flickr.css

body {
background-color: #888;
font-family: Lucida Grande;
font-size: 11px;
margin: 25px;
}

form {
margin: 0;
margin-bottom: 10px;
background-color: rgb(222,231,236);
border: 5px solid #333;
padding: 25px;
}


fieldset {
border: none;
}

#spinner
{
float:right;
margin:10px;
}

#photos img {
border: 1px solid #000;
width: 75px;
height: 75px;
margin: 5px;
}




Now generate the controller
>ruby script/generate controller flickr

Add the following code to your index.rhtml

<% form_remote_tag :url => {:action => 'search'}, :update => 'photos',
:complete => visual_effect(:blind_down, 'photos'),
:before => %(Element.show('spinner')),
:success => %(Element.hide('spinner')) do %>
<%= image_tag 'spinner.gif', :id => 'spinner', :style => 'display: none' %>
<label for="tags">Tags:</label>
<%= text_field_tag 'tags' %>
<%= submit_tag 'Find' %>
<div id="photos" style="display: none"></div>
<% end %>

Add the following code in your controller.rb
def search
flickr = Flickr.new
if params[:tags].empty?
render :text => '<h2>Please enter a search string</h2>'
else
begin
photos = flickr.photos(:tags => params[:tags], :per_page => '24')
render :partial => 'photo', :collection => photos
rescue NoMethodError
render :text => '<h2>No matching photos found</h2>'
end
end
end


Add the following line in _photo.rhtml
<img class='photo' src="<%= photo.sizes[0]['source'] %>">

restart your server, and try it:
http://localhost:3000/flickr and find the photos using your flickr tags


thanq
Raju
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> API
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts validates_multiparameter_assignments plugin usage:
0 vijayalakshmi 27 Wed Jul 28, 2010 4:24 am
vijayalakshmi View latest post
No new posts paperclip plugin usage in rails:
0 vijayalakshmi 23 Wed Jul 28, 2010 4:07 am
vijayalakshmi View latest post
No new posts Polymorphism
1 phani.galla 46 Tue Jul 27, 2010 3:27 pm
umamahesh_nyros View latest post
No new posts Deploying Ruby on Rails Application with Passenger
2 sivakrishna.m 630 Tue Jul 27, 2010 2:16 pm
criether View latest post
No new posts Steps to implement star-rating using acts_as_rateable plugin
0 vijayalakshmi 46 Mon Jul 26, 2010 5:47 am
vijayalakshmi View latest post
No new posts Twitter Retweet Integartion
0 Anu 41 Thu Jul 22, 2010 12:27 pm
Anu View latest post
No new posts Usage of build method in rails
0 ktulasi 30 Thu Jul 22, 2010 12:19 pm
ktulasi View latest post
No new posts Facebook Like Integration in Rails
0 Anu 53 Thu Jul 22, 2010 12:16 pm
Anu View latest post
No new posts Fshare in your Rails Application.
0 Anu 39 Thu Jul 22, 2010 12:10 pm
Anu View latest post
No new posts Installation of Postgresql in windows.
1 swaminadhan 198 Thu Jul 15, 2010 10:17 am
proximity3 View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More