Git Product home page Git Product logo

flickraw's Introduction

Flickraw

Flickraw is a library to access flickr api in a simple way. It maps exactly the methods described in the official api documentation. It also tries to present the data returned in a simple and intuitive way. The methods are fetched from flickr when loading the library by using introspection capabilities. So it is always up-to-date with regards to new methods added by flickr.

The github repository: github.com/hanklords/flickraw

Installation

Type this in a console (you might need to be superuser)

gem install json (This is only necessary on ruby 1.8)
gem install flickraw

This will recreate the documentation by fetching the methods descriptions from flickr and then virtually plugging them in standard rdoc documentation.

$ cd flickraw
$ rake rdoc

Features

  • Minimal dependencies

  • Complete support of flickr API. This doesn’t require an update of the library

  • Ruby syntax similar to the flickr api

  • Flickr authentication

  • HTTPS Support

  • Photo upload

  • Proxy support

  • Flickr URLs helpers

Usage

Getting started

To use FlickRaw, you must first obtain an API key and shared secret from Flickr. You can do this by logging in to Flickr and creating an application here. API keys are usually granted automatically and instantly.

require 'flickraw'

# The credentials can be provided as parameters:

flickr = FlickRaw::Flickr.new "YOUR API KEY", "YOUR SHARED SECRET"

# Alternatively, if the API key and Shared Secret are not provided, FlickRaw will attempt to read them
# from environment variables:
# ENV['FLICKRAW_API_KEY']
# ENV['FLICKRAW_SHARED_SECRET']

flickr = FlickRaw::Flickr.new

# FlickRaw will raise an error if either parameter is not explicitly provided, or avilable via environment variables.

Simple

list   = flickr.photos.getRecent

id     = list[0].id
secret = list[0].secret
info = flickr.photos.getInfo :photo_id => id, :secret => secret

puts info.title           # => "PICT986"
puts info.dates.taken     # => "2006-07-06 15:16:18"

sizes = flickr.photos.getSizes :photo_id => id

original = sizes.find { |s| s.label == 'Original' }
puts original.width       # => "800" -- may fail if they have no original marked image

Authentication

token = flickr.get_request_token
auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')

puts "Open this url in your browser to complete the authentication process : #{auth_url}"
puts "Copy here the number given when you complete the process."
verify = gets.strip

begin
  flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
  login = flickr.test.login
  puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}"
rescue FlickRaw::FailedResponse => e
  puts "Authentication failed : #{e.msg}"
end

If the user has already been authenticated, you can reuse the access token and access secret:

flickr.access_token = "... Your access token ..."
flickr.access_secret = "... Your access secret ..."

# From here you are logged:
login = flickr.test.login
puts "You are now authenticated as #{login.username}"

If you need to have several users authenticated at the same time in your application (ex: a public web application) you need to create separate FlickRaw objects since it keeps the authentication data internally.

flickr = FlickRaw::Flickr.new

Upload

PHOTO_PATH='photo.jpg'

# You need to be authenticated to do that, see the previous examples.
flickr.upload_photo PHOTO_PATH, :title => "Title", :description => "This is the description"

Proxy

require 'flickraw'
FlickRaw.proxy = "http://user:[email protected]:3129/"

Server Certificate Verification

Server certificate verification is enabled by default. If you don’t want to check the server certificate :

require 'flickraw'
FlickRaw.check_certificate = false

CA Certificate File Path

OpenSSL::X509::DEFAULT_CERT_FILE is used as a CA certificate file. If you want to change the path :

require 'flickraw'
FlickRaw.ca_file = '/path/to/cacert.pem'

You can also specify a path to a directory with a number of certifications:

FlickRaw.ca_path = '/path/to/certificates'

Flickr URL Helpers

There are some helpers to build flickr urls :

url, url_m, url_s, url_t, url_b, url_z, url_q, url_n, url_c, url_o

# url_s : Square
# url_q : Large Square
# url_t : Thumbnail
# url_m : Small
# url_n : Small 320
# url   : Medium
# url_z : Medium 640
# url_c : Medium 800
# url_b : Large
# url_o : Original

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_b(info) # => "https://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg"

url_profile

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_profile(info) # => "https://www.flickr.com/people/41650587@N02/"

url_photopage

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_photopage(info) # => "https://www.flickr.com/photos/41650587@N02/3839885270"

url_photoset, url_photosets

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_photosets(info) # => "https://www.flickr.com/photos/41650587@N02/sets/"

url_short, url_short_m, url_short_s, url_short_t

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_short(info) # => "https://flic.kr/p/6Rjq7s"

url_photostream

info = flickr.photos.getInfo(:photo_id => "3839885270")
FlickRaw.url_photostream(info) # => "https://www.flickr.com/photos/41650587@N02/"

See the examples directory to find more examples.

Cached version

You can use

require 'flickraw-cached'

instead of

require 'flickraw'

This way it it doesn’t fetch available flickr methods each time it is loaded. The flickraw-cached gem is on rubygems.org and should be up-to-date with regard to flickr api most of the time.

flickraw's People

Contributors

hanklords avatar cyclotron3k avatar rdp avatar parkr avatar viseztrance avatar mratzloff avatar mendab1e avatar khustochka avatar boncey avatar nitoyon avatar apikas avatar baltazore avatar cpuguy83 avatar chrblabla avatar christopheradams avatar codener avatar freeslugs avatar loeschg avatar gesteves avatar jkraemer avatar kueda avatar zatton avatar tarebyte avatar mtn avatar dentarg avatar octplane avatar netqyq avatar ramin avatar srussking avatar tarko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.