flickr_fu 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gemspec
7
-
8
6
  # Add dependencies to develop your gem here.
9
7
  # Include everything needed to run rake, tests, features, etc.
10
8
  group :development do
@@ -15,3 +13,8 @@ group :development do
15
13
  gem "rdoc"
16
14
  # gem "rcov", ">= 0"
17
15
  end
16
+
17
+ gem "mime-types"
18
+ gem "xml-magic"
19
+
20
+ #gemspec
data/Gemfile.lock CHANGED
@@ -1,11 +1,3 @@
1
- PATH
2
- remote: .
3
- specs:
4
- flickr_fu (0.3.1)
5
- flickr_fu
6
- mime-types (> 0.0.0)
7
- xml-magic (> 0.0.0)
8
-
9
1
  GEM
10
2
  remote: http://rubygems.org/
11
3
  specs:
@@ -35,7 +27,8 @@ PLATFORMS
35
27
 
36
28
  DEPENDENCIES
37
29
  bundler (~> 1)
38
- flickr_fu!
39
30
  jeweler (~> 1.6.4)
31
+ mime-types
40
32
  rdoc
41
33
  rspec
34
+ xml-magic
data/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # flickr-fu
2
+
3
+ ## Contact
4
+
5
+ Author: Ben Wyrosdick
6
+ Email: ben [at] commonthread.com
7
+ Issue tracker: https://github.com/commonthread/flickr_fu/issues
8
+ Code Repository: http://github.com/commonthread/flickr_fu/tree/master
9
+
10
+ ## Getting Started
11
+
12
+ You need to first get an API key as detailed here:
13
+
14
+ http://www.flickr.com/services/api/misc.api_keys.html
15
+
16
+ ## Installation
17
+
18
+ <code>sudo gem install flickr-fu</code>
19
+
20
+ ## Documentation
21
+
22
+ Documentation can be found here:
23
+ http://rubydoc.info/gems/flickr_fu/
24
+
25
+ ### Example flickr.yml
26
+ <pre>
27
+ --- !map:HashWithIndifferentAccess
28
+ key: "YOUR KEY"
29
+ secret: "YOUR SECRET"
30
+ token_cache: "token_cache.yml"
31
+ </pre>
32
+
33
+ ### Authorization
34
+
35
+ To authorise your application to access Flickr using your API key you will need to access a specific URL.
36
+
37
+ To generate this URL run the following and when presented with the URL access it from your browser. Confirm the application has permission at the level you have specified.
38
+
39
+ Note that flickr has different types of keys. If you use one for a webapplication, which is most likely, you need to define a callback and somehow make sure that you connect the parameter :frob that flickr send via the callback is assigned to the right user account. The best way to do this is to loop over all the current user's flickr accounts and try flickr.auth.token with the :frob.
40
+
41
+ Finally, cache the token (this will create the token cache file)
42
+
43
+ If you have an invalid API key you will see errors such as:
44
+
45
+ <code>"100: Invalid API Key"</code>
46
+
47
+ If you don't follow the process below to authorise your application you will see errors such as:
48
+
49
+ <pre>
50
+ "98: Login failed / Invalid auth token" or
51
+ "99: User not logged in / Insufficient permissions"
52
+ </pre>
53
+
54
+ ### Authorization Example for non-webapplication
55
+
56
+ <pre>
57
+ require 'flickr_fu'
58
+
59
+ flickr = Flickr.new('flickr.yml')
60
+
61
+ puts "visit the following url, then click <enter> once you have authorized:"
62
+
63
+ # request write permissions
64
+ puts flickr.auth.url(:write)
65
+
66
+ gets
67
+
68
+ flickr.auth.cache_token
69
+ </pre>
70
+
71
+ ### Authorization Example for a webapplication
72
+
73
+ flickr.auth.token also contains the nsid and username, this example only stores the token and no other userdata.
74
+
75
+ <pre>
76
+ require 'flickr_fu'
77
+ class FlickrController < ActionController::Base
78
+ def create
79
+ flickr = Flickr.new('flickr.yml')
80
+ redirect_to flickr.auth.url(:write)
81
+ end
82
+ def flickr_callback
83
+ flickr = Flickr.new('flickr.yml')
84
+ flickr.auth.frob = params[:frob]
85
+ current_user.update_attribute :flickr_token, flickr.auth.token.token
86
+ end
87
+ def something_else_with_flickr
88
+ flickr = Flickr.new(YAML.load_file('flickr.yml').merge(:token => current_user.flickr_token))
89
+ # now you have full access on the user's data :)
90
+ end
91
+ end
92
+ </pre>
93
+
94
+ ### Search Example
95
+
96
+ <pre>
97
+ require 'flickr_fu'
98
+
99
+ flickr = Flickr.new('flickr.yml')
100
+
101
+ photos = flickr.photos.search(:tags => 'ruby-flickr')
102
+
103
+ puts "found #{photos.size} photo(s)"
104
+
105
+ photos.each do |photo|
106
+ puts photo.title
107
+ puts photo.description unless [nil, ''].include?(photo.description)
108
+ [:square, :thumbnail, :small, :medium, :large, :original].each do |size|
109
+ puts "#{size}: #{photo.url(size)}"
110
+ end
111
+ puts "comments: #{photo.comments.size}"
112
+ photo.comments.each do |comment|
113
+ intro = "#{comment.author_name} says - "
114
+ puts "#{intro}\"#{comment.comment.gsub("\n", "\n"+(" "*intro.length))}\""
115
+ end
116
+ puts "notes: #{photo.notes.size}"
117
+ photo.notes.each do |note|
118
+ puts "[#{note.x},#{note.y} ~ #{note.width}x#{note.height}] - \"#{note.note}\""
119
+ end
120
+ puts
121
+ puts
122
+ end
123
+ </pre>
124
+
125
+ ### Another Search Example
126
+
127
+ If searching for photos by user id then you need to specify the 'alias' - without intervention this is usually set by Flickr and is an alphanumeric string.
128
+
129
+ To find out the user id for a given user, you can use the tool at:
130
+
131
+ http://idgettr.com/
132
+
133
+ And replace the line in the above sample to query on user id:
134
+
135
+ <code>photos = flickr.photos.search(:user_id => 'your_user_id_here')</code>
136
+
137
+ ## Patch Contributers
138
+
139
+ - Chris Ledet
140
+ - Maciej Biłas
141
+ - Mike Perham
142
+ - Chris Anderton
143
+ - Luke Francl
144
+ - Thomas R. Koll
145
+ - P. Mark Anderson
146
+ - Josh Nichols
data/Rakefile CHANGED
@@ -22,8 +22,8 @@ Jeweler::Tasks.new do |s|
22
22
  s.authors = ["Ben Wyrosdick", "Maciej Bilas"]
23
23
  s.rdoc_options = ["--main", "README"]
24
24
  s.extra_rdoc_files = ["README"]
25
- s.add_dependency("mime-types", ["> 0.0.0"])
26
- s.add_dependency("xml-magic", ["> 0.0.0"])
25
+ # s.add_dependency("mime-types", ["> 0.0.0"])
26
+ # s.add_dependency("xml-magic", ["> 0.0.0"])
27
27
  s.files.exclude("spec/spec.local.opts")
28
28
  end
29
29
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 1
5
- :build: !!null
4
+ :patch: 2
5
+ :build:
data/flickr_fu.gemspec CHANGED
@@ -5,21 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flickr_fu"
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Wyrosdick", "Maciej Bilas"]
12
- s.date = "2012-01-17"
12
+ s.date = "2012-08-11"
13
13
  s.description = "Provides a ruby interface to flickr via the REST api"
14
14
  s.email = "ben@commonthread.com"
15
- s.extra_rdoc_files = [
16
- "README"
17
- ]
18
15
  s.files = [
19
16
  "Gemfile",
20
17
  "Gemfile.lock",
21
18
  "LICENSE",
22
- "README",
19
+ "README.md",
23
20
  "Rakefile",
24
21
  "VERSION.yml",
25
22
  "flickr_fu.gemspec",
@@ -56,6 +53,7 @@ Gem::Specification.new do |s|
56
53
  "spec/fixtures/flickr/photos/get_sizes-0.xml",
57
54
  "spec/fixtures/flickr/photos/get_sizes-1.xml",
58
55
  "spec/fixtures/flickr/photos/licenses/get_info.xml",
56
+ "spec/fixtures/flickr/photosets/create-0.xml",
59
57
  "spec/fixtures/flickr/photosets/get_list-0.xml",
60
58
  "spec/fixtures/flickr/photosets/get_photos-0.xml",
61
59
  "spec/fixtures/flickr/test/echo-0.xml",
@@ -88,61 +86,34 @@ Gem::Specification.new do |s|
88
86
  s.homepage = "http://github.com/commonthread/flickr_fu"
89
87
  s.rdoc_options = ["--main", "README"]
90
88
  s.require_paths = ["lib"]
91
- s.rubygems_version = "1.8.10"
89
+ s.rubygems_version = "1.8.24"
92
90
  s.summary = "Provides a ruby interface to flickr via the REST api"
93
91
 
94
92
  if s.respond_to? :specification_version then
95
93
  s.specification_version = 3
96
94
 
97
95
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
98
- s.add_runtime_dependency(%q<flickr_fu>, [">= 0"])
96
+ s.add_runtime_dependency(%q<mime-types>, [">= 0"])
97
+ s.add_runtime_dependency(%q<xml-magic>, [">= 0"])
99
98
  s.add_development_dependency(%q<bundler>, ["~> 1"])
100
99
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
101
100
  s.add_development_dependency(%q<rspec>, [">= 0"])
102
101
  s.add_development_dependency(%q<rdoc>, [">= 0"])
103
- s.add_development_dependency(%q<bundler>, ["~> 1"])
104
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
105
- s.add_development_dependency(%q<rspec>, [">= 0"])
106
- s.add_development_dependency(%q<rdoc>, [">= 0"])
107
- s.add_development_dependency(%q<bundler>, ["~> 1"])
108
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
109
- s.add_development_dependency(%q<rspec>, [">= 0"])
110
- s.add_development_dependency(%q<rdoc>, [">= 0"])
111
- s.add_runtime_dependency(%q<mime-types>, ["> 0.0.0"])
112
- s.add_runtime_dependency(%q<xml-magic>, ["> 0.0.0"])
113
102
  else
114
- s.add_dependency(%q<flickr_fu>, [">= 0"])
115
- s.add_dependency(%q<bundler>, ["~> 1"])
116
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
117
- s.add_dependency(%q<rspec>, [">= 0"])
118
- s.add_dependency(%q<rdoc>, [">= 0"])
103
+ s.add_dependency(%q<mime-types>, [">= 0"])
104
+ s.add_dependency(%q<xml-magic>, [">= 0"])
119
105
  s.add_dependency(%q<bundler>, ["~> 1"])
120
106
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
121
107
  s.add_dependency(%q<rspec>, [">= 0"])
122
108
  s.add_dependency(%q<rdoc>, [">= 0"])
123
- s.add_dependency(%q<bundler>, ["~> 1"])
124
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
125
- s.add_dependency(%q<rspec>, [">= 0"])
126
- s.add_dependency(%q<rdoc>, [">= 0"])
127
- s.add_dependency(%q<mime-types>, ["> 0.0.0"])
128
- s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
129
109
  end
130
110
  else
131
- s.add_dependency(%q<flickr_fu>, [">= 0"])
132
- s.add_dependency(%q<bundler>, ["~> 1"])
133
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
134
- s.add_dependency(%q<rspec>, [">= 0"])
135
- s.add_dependency(%q<rdoc>, [">= 0"])
136
- s.add_dependency(%q<bundler>, ["~> 1"])
137
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
138
- s.add_dependency(%q<rspec>, [">= 0"])
139
- s.add_dependency(%q<rdoc>, [">= 0"])
111
+ s.add_dependency(%q<mime-types>, [">= 0"])
112
+ s.add_dependency(%q<xml-magic>, [">= 0"])
140
113
  s.add_dependency(%q<bundler>, ["~> 1"])
141
114
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
142
115
  s.add_dependency(%q<rspec>, [">= 0"])
143
116
  s.add_dependency(%q<rdoc>, [">= 0"])
144
- s.add_dependency(%q<mime-types>, ["> 0.0.0"])
145
- s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
146
117
  end
147
118
  end
148
119
 
data/lib/flickr/auth.rb CHANGED
@@ -7,43 +7,47 @@ class Flickr::Auth < Flickr::Base
7
7
  def frob
8
8
  @frob ||= get_frob
9
9
  end
10
-
10
+
11
11
  # set the frob
12
12
  def frob= frob
13
13
  @frob=frob
14
14
  end
15
15
 
16
16
  # generates the authorization url to allow access to a flickr account.
17
- #
17
+ #
18
18
  # Params
19
19
  # * perms (Optional)
20
20
  # sets the permision level to grant on the flickr account.
21
21
  # :read - permission to read private information (DEFAULT)
22
22
  # :write - permission to add, edit and delete photo metadata (includes 'read')
23
23
  # :delete - permission to delete photos (includes 'write' and 'read')
24
- #
25
- def url(perms = :read)
26
- options = {:api_key => @flickr.api_key, :perms => perms, :frob => self.frob}
24
+ # * options (Optional)
25
+ # additional parameters to pass to flickr. The most common use-case for
26
+ # this is to pass the (undocumented) :extra parameter that is returned
27
+ # back from flickr during the callback.
28
+ #
29
+ def url(perms = :read, options = {})
30
+ options.merge!(:api_key => @flickr.api_key, :perms => perms, :frob => self.frob)
27
31
  @flickr.sign_request(options)
28
- Flickr::Base::AUTH_ENDPOINT + "?" + options.collect{|k,v| "#{k}=#{v}"}.join('&')
32
+ Flickr::Base::AUTH_ENDPOINT + "?" + options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
29
33
  end
30
34
 
31
35
  # gets the token object for the current frob
32
- #
36
+ #
33
37
  # Params
34
38
  # * pass_through (Optional)
35
39
  # Boolean value that determines if a call will be made to flickr to find a taken for the current frob if empty
36
- #
40
+ #
37
41
  def token(pass_through = true)
38
42
  @token ||= get_token(pass_through) rescue nil
39
43
  end
40
44
 
41
45
  # saves the current token to the cache file if token exists
42
- #
46
+ #
43
47
  # Param
44
48
  # * filename (Optional)
45
49
  # filename of the cache file. defaults to the file passed into Flickr.new
46
- #
50
+ #
47
51
  def cache_token(filename = @flickr.token_cache)
48
52
  if filename and self.token
49
53
  cache_file = File.open(filename, 'w+')
@@ -73,4 +77,4 @@ class Flickr::Auth < Flickr::Base
73
77
  Token.new(:token => rsp.auth.token.to_s, :permisions => rsp.auth.perms.to_s, :user_id => rsp.auth.user[:nsid], :username => rsp.auth.user[:username], :user_real_name => rsp.auth.user[:fullname])
74
78
  end
75
79
  end
76
- end
80
+ end
data/lib/flickr/photo.rb CHANGED
@@ -30,9 +30,13 @@ class Flickr::Photos::Photo
30
30
  # * size (Optional)
31
31
  # the size of the size instance to return. Optional sizes are:
32
32
  # :square - square 75x75
33
+ # :large_square - square 150x150
33
34
  # :thumbnail - 100 on longest side
34
35
  # :small - 240 on longest side
36
+ # :small_320 - 320 on longest side
35
37
  # :medium - 500 on longest side
38
+ # :medium_640 - 640 on longest side
39
+ # :medium_800 - 800 on longest side
36
40
  # :large - 1024 on longest side (only exists for very large original images)
37
41
  # :original - original image, either a jpg, gif or png, depending on source format
38
42
  # Examples
@@ -48,9 +52,13 @@ class Flickr::Photos::Photo
48
52
  # * size (Optional)
49
53
  # the size of the image to return. Optional sizes are:
50
54
  # :square - square 75x75
55
+ # :large_square - square 150x150
51
56
  # :thumbnail - 100 on longest side
52
57
  # :small - 240 on longest side
58
+ # :small_320 - 320 on longest side
53
59
  # :medium - 500 on longest side
60
+ # :medium_640 - 640 on longest side
61
+ # :medium_800 - 800 on longest side
54
62
  # :large - 1024 on longest side (only exists for very large original images)
55
63
  # :original - original image, either a jpg, gif or png, depending on source format
56
64
  #
@@ -86,10 +94,14 @@ class Flickr::Photos::Photo
86
94
  # name of the new file omiting the extention (ex. photo_1)
87
95
  # * size (Optional)
88
96
  # the size of the image to return. Optional sizes are:
89
- # :small - square 75x75
97
+ # :square - square 75x75
98
+ # :large_square - square 150x150
90
99
  # :thumbnail - 100 on longest side
91
100
  # :small - 240 on longest side
101
+ # :small_320 - 320 on longest side
92
102
  # :medium - 500 on longest side
103
+ # :medium_640 - 640 on longest side
104
+ # :medium_800 - 800 on longest side
93
105
  # :large - 1024 on longest side (only exists for very large original images)
94
106
  # :original - original image, either a jpg, gif or png, depending on source format
95
107
  #
@@ -106,7 +118,14 @@ class Flickr::Photos::Photo
106
118
  f
107
119
  end
108
120
  end
109
-
121
+
122
+ # Delete this photo
123
+ #
124
+ def delete()
125
+ @flickr.send_request('flickr.photos.delete', {:photo_id => self.id}, :post)
126
+ true
127
+ end
128
+
110
129
  # Add tags to a photo.
111
130
  #
112
131
  # Params
@@ -282,9 +301,13 @@ class Flickr::Photos::Photo
282
301
  def size_key(size)
283
302
  case size.to_sym
284
303
  when :square then 's'
304
+ when :large_square then 'q'
285
305
  when :thumb, :thumbnail then 't'
286
306
  when :small then 'm'
307
+ when :small_320 then 'n'
287
308
  when :medium then ''
309
+ when :medium_640 then 'z'
310
+ when :medium_800 then 'c'
288
311
  when :large then 'b'
289
312
  when :original then 'o'
290
313
  else ''
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <photoset id="1234" url="http://www.flickr.com/photos/bees/sets/1234/" />
@@ -5,91 +5,105 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  module PhotoSpecHelper
6
6
  def valid_photo_attributes
7
7
  {
8
- :id => 2984637736,
9
- :owner => "80755658@N00",
10
- :secret => "9e5762e027",
11
- :server => 3180,
12
- :farm => 4,
13
- :title => "Demolition of Hotel Rzeszów",
14
- :is_public => 1,
15
- :is_friend => 0,
16
- :is_family => 0
8
+ :id => 2984637736,
9
+ :owner => "80755658@N00",
10
+ :secret => "9e5762e027",
11
+ :server => 3180,
12
+ :farm => 4,
13
+ :title => "Demolition of Hotel Rzeszów",
14
+ :is_public => 1,
15
+ :is_friend => 0,
16
+ :is_family => 0
17
17
  }
18
18
  end
19
19
  end
20
20
 
21
21
  describe Flickr::Photos::Photo do
22
-
22
+
23
23
  include PhotoSpecHelper
24
-
24
+
25
25
  before :all do
26
26
  @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_info-0.xml")
27
27
  @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_sizes-0.xml")
28
28
  end
29
-
29
+
30
30
  before :each do
31
31
  @flickr = SpecHelper.flickr
32
32
  #@flickr.stub!(:request_over_http).and_return(info_xml)
33
33
  @photo = Flickr::Photos::Photo.new(@flickr, valid_photo_attributes)
34
34
  end
35
-
35
+
36
36
  describe ".description" do
37
37
  it "should return the description" do
38
38
  @flickr.should_receive(:request_over_http).and_return(@info_xml)
39
- @photo.description.should ==
40
- "The last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów."
39
+ @photo.description.should ==
40
+ "The last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów."
41
41
  end
42
42
  end
43
43
 
44
44
  describe ".photo_size" do
45
+
46
+ before :each do
47
+ sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_sizes-0.xml")
48
+ @flickr.stub!(:request_over_http).and_return(sizes_xml)
49
+ end
50
+
45
51
  it "should return the appropriate Flickr::Photos::Size instance when requested by symbol" do
46
- @photo.photo_size(:square).class.should == Flickr::Photos::Size
47
- @photo.photo_size(:square).label.should == "Square"
52
+ @photo.photo_size(:square).class.should == Flickr::Photos::Size
53
+ @photo.photo_size(:square).label.should == "Square"
48
54
  end
49
55
 
50
56
  it "should return the appropriate Flickr::Photos::Size instance when requested by string" do
51
- @photo.photo_size('square').class.should == Flickr::Photos::Size
52
- @photo.photo_size('square').label.should == "Square"
57
+ @photo.photo_size('square').class.should == Flickr::Photos::Size
58
+ @photo.photo_size('square').label.should == "Square"
53
59
  end
54
60
 
55
61
  it "should return the :medium Flickr::Photos::Size instance invalidly requested" do
56
- @photo.photo_size(:doubleplusbig).class.should == Flickr::Photos::Size
57
- @photo.photo_size(:doubleplusbig).label.should == "Medium"
62
+ @photo.photo_size(:doubleplusbig).class.should == Flickr::Photos::Size
63
+ @photo.photo_size(:doubleplusbig).label.should == "Medium"
58
64
  end
59
65
  end
60
66
 
61
67
  describe ".image_url" do
62
68
  it "should return all standard sizes (thumbnail, square, small, medium and large) when requested" do
63
- @photo.image_url(:square).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_s.jpg"
69
+ @photo.image_url(:square).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_s.jpg"
70
+ @photo.image_url(:large_square).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_q.jpg"
64
71
  @photo.image_url(:thumbnail).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_t.jpg"
65
72
  @photo.image_url(:small).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_m.jpg"
66
- @photo.image_url(:medium).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027.jpg"
67
- @photo.image_url(:large).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_b.jpg"
68
- end
69
-
70
- it "should return the same image even if you pass a string as an argument" do
71
- @photo.image_url("square").should == @photo.image_url(:square)
72
- @photo.image_url("large").should == @photo.image_url(:large)
73
- end
74
-
75
- it "should not call getSizes if not requested the url of the original image" do
76
- @flickr.should_not_receive(:request_over_http)
77
- @photo.image_url :square
78
- @photo.image_url :thumbnail
79
- @photo.image_url :small
80
- @photo.image_url :medium
81
- @photo.image_url :large
82
- end
83
-
84
- it "should call getSizes if requested the url of the original image" do
85
- @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
86
- @photo.image_url :original
87
- end
88
-
89
- it "should return nil if original image url not available" do
90
- @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
91
- @photo.image_url(:original).should == nil
92
- end
73
+ @photo.image_url(:small_320).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_n.jpg"
74
+ @photo.image_url(:medium).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027.jpg"
75
+ @photo.image_url(:medium_640).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_z.jpg"
76
+ @photo.image_url(:medium_800).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_c.jpg"
77
+ @photo.image_url(:large).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_b.jpg"
78
+ end
79
+
80
+ it "should return the same image even if you pass a string as an argument" do
81
+ @photo.image_url("square").should == @photo.image_url(:square)
82
+ @photo.image_url("large").should == @photo.image_url(:large)
83
+ end
84
+
85
+ it "should not call getSizes if not requested the url of the original image" do
86
+ @flickr.should_not_receive(:request_over_http)
87
+ @photo.image_url :square
88
+ @photo.image_url :large_square
89
+ @photo.image_url :thumbnail
90
+ @photo.image_url :small
91
+ @photo.image_url :small_320
92
+ @photo.image_url :medium
93
+ @photo.image_url :medium_640
94
+ @photo.image_url :medium_800
95
+ @photo.image_url :large
96
+ end
97
+
98
+ it "should call getSizes if requested the url of the original image" do
99
+ @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
100
+ @photo.image_url :original
101
+ end
102
+
103
+ it "should return nil if original image url not available" do
104
+ @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
105
+ @photo.image_url(:original).should == nil
106
+ end
93
107
  end
94
108
 
95
109
  describe ".video_url" do
@@ -120,12 +134,12 @@ describe Flickr::Photos::Photo do
120
134
  describe Flickr::Photos::Photo, "but it's really a video" do
121
135
 
122
136
  include PhotoSpecHelper
123
-
137
+
124
138
  before :all do
125
139
  @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_info-0.xml")
126
140
  @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_sizes-0.xml")
127
141
  end
128
-
142
+
129
143
  before :each do
130
144
  @flickr = SpecHelper.flickr
131
145
  #@flickr.stub!(:request_over_http).and_return(info_xml)
@@ -6,44 +6,67 @@ describe Flickr::Photosets do
6
6
  "/../fixtures/flickr/photosets/get_list-0.xml")
7
7
  @get_photos_xml = File.read(File.dirname(__FILE__) +
8
8
  "/../fixtures/flickr/photosets/get_photos-0.xml")
9
+ @create_xml = File.read(File.dirname(__FILE__) +
10
+ "/../fixtures/flickr/photosets/create-0.xml")
9
11
  end
10
-
12
+
11
13
  before :each do
12
14
  @flickr = SpecHelper.flickr
13
15
  end
14
16
 
15
-
17
+
16
18
  describe ".get_list" do
17
19
  it "should call flickr.photosets.getList" do
18
- @flickr.should_receive(:send_request).with("flickr.photosets.getList", {})
20
+ @flickr.should_receive(:send_request).with("flickr.photosets.getList", {})
19
21
  @flickr.photosets.get_list
20
22
  end
21
-
23
+
22
24
  it "should return an array of photoset objects" do
23
- @flickr.stub!(:request_over_http).and_return(@get_list_xml)
25
+ @flickr.stub!(:request_over_http).and_return(@get_list_xml)
24
26
  photosets = @flickr.photosets.get_list
25
-
26
- photosets[0].should be_an_instance_of(Flickr::Photosets::Photoset)
27
+
28
+ photosets[0].should be_an_instance_of(Flickr::Photosets::Photoset)
27
29
  photosets[0].title.should == 'Test'
28
30
  end
29
31
  end
30
-
32
+
33
+ describe ".create" do
34
+ subject { Flickr::Photosets.new(@flickr) }
35
+ it "should call flick.photosets.create" do
36
+ @flickr.should_receive(:send_request).with("flickr.photosets.create",
37
+ { :title => "new photoset", :primary_photo_id => 42 })
38
+ @flickr.stub!(:request_over_http).and_return(@create_xml)
39
+ subject.create("new photoset", 42)
40
+ end
41
+ end
42
+
31
43
  describe ".get_photos" do
32
44
  before :each do
33
45
  @photoset = Flickr::Photosets::Photoset.new(@flickr,{:id=>4})
34
46
  end
35
-
47
+
36
48
  it "should call flickr.photosets.getPhotos" do
37
- @flickr.should_receive(:send_request).with("flickr.photosets.getPhotos",{:photoset_id=>4})
49
+ @flickr.should_receive(:send_request).with("flickr.photosets.getPhotos",{:photoset_id=>4})
38
50
  @photoset.get_photos
39
51
  end
40
-
52
+
41
53
  it "should return an array of photo objects" do
42
- @flickr.stub!(:request_over_http).and_return(@get_photos_xml)
54
+ @flickr.stub!(:request_over_http).and_return(@get_photos_xml)
43
55
  photos = @photoset.get_photos
44
-
56
+
45
57
  photos.should_not be_nil
46
- photos[0].should be_an_instance_of(Flickr::Photos::Photo)
58
+ photos[0].should be_an_instance_of(Flickr::Photos::Photo)
47
59
  end
48
60
  end
49
- end
61
+
62
+ describe ".add_photo" do
63
+ subject { Flickr::Photosets::Photoset.new(@flickr, {:id=>4}) }
64
+
65
+ it "should call flickr.photosets.addPhoto" do
66
+ @flickr.should_receive(:send_request).with("flickr.photosets.addPhoto",
67
+ { :photo_id => 43, :photoset_id => 4 })
68
+ @flickr.stub!(:request_over_http).and_return("")
69
+ subject.add_photo(43)
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickr_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-17 00:00:00.000000000Z
13
+ date: 2012-08-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: flickr_fu
17
- requirement: &70279932931440 !ruby/object:Gem::Requirement
16
+ name: mime-types
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,54 +22,31 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70279932931440
26
- - !ruby/object:Gem::Dependency
27
- name: bundler
28
- requirement: &70279932930860 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
29
26
  none: false
30
27
  requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: *70279932930860
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- requirement: &70279932930220 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
28
+ - - ! '>='
43
29
  - !ruby/object:Gem::Version
44
- version: 1.6.4
45
- type: :development
46
- prerelease: false
47
- version_requirements: *70279932930220
30
+ version: '0'
48
31
  - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &70279932929620 !ruby/object:Gem::Requirement
32
+ name: xml-magic
33
+ requirement: !ruby/object:Gem::Requirement
51
34
  none: false
52
35
  requirements:
53
36
  - - ! '>='
54
37
  - !ruby/object:Gem::Version
55
38
  version: '0'
56
- type: :development
39
+ type: :runtime
57
40
  prerelease: false
58
- version_requirements: *70279932929620
59
- - !ruby/object:Gem::Dependency
60
- name: rdoc
61
- requirement: &70279932928900 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
62
42
  none: false
63
43
  requirements:
64
44
  - - ! '>='
65
45
  - !ruby/object:Gem::Version
66
46
  version: '0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: *70279932928900
70
47
  - !ruby/object:Gem::Dependency
71
48
  name: bundler
72
- requirement: &70279932928320 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
73
50
  none: false
74
51
  requirements:
75
52
  - - ~>
@@ -77,65 +54,31 @@ dependencies:
77
54
  version: '1'
78
55
  type: :development
79
56
  prerelease: false
80
- version_requirements: *70279932928320
81
- - !ruby/object:Gem::Dependency
82
- name: jeweler
83
- requirement: &70279932920780 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
84
58
  none: false
85
59
  requirements:
86
60
  - - ~>
87
61
  - !ruby/object:Gem::Version
88
- version: 1.6.4
89
- type: :development
90
- prerelease: false
91
- version_requirements: *70279932920780
92
- - !ruby/object:Gem::Dependency
93
- name: rspec
94
- requirement: &70279932920060 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
- type: :development
101
- prerelease: false
102
- version_requirements: *70279932920060
103
- - !ruby/object:Gem::Dependency
104
- name: rdoc
105
- requirement: &70279932919340 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- type: :development
112
- prerelease: false
113
- version_requirements: *70279932919340
62
+ version: '1'
114
63
  - !ruby/object:Gem::Dependency
115
- name: bundler
116
- requirement: &70279932918740 !ruby/object:Gem::Requirement
64
+ name: jeweler
65
+ requirement: !ruby/object:Gem::Requirement
117
66
  none: false
118
67
  requirements:
119
68
  - - ~>
120
69
  - !ruby/object:Gem::Version
121
- version: '1'
70
+ version: 1.6.4
122
71
  type: :development
123
72
  prerelease: false
124
- version_requirements: *70279932918740
125
- - !ruby/object:Gem::Dependency
126
- name: jeweler
127
- requirement: &70279932918040 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
128
74
  none: false
129
75
  requirements:
130
76
  - - ~>
131
77
  - !ruby/object:Gem::Version
132
78
  version: 1.6.4
133
- type: :development
134
- prerelease: false
135
- version_requirements: *70279932918040
136
79
  - !ruby/object:Gem::Dependency
137
80
  name: rspec
138
- requirement: &70279932917400 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
139
82
  none: false
140
83
  requirements:
141
84
  - - ! '>='
@@ -143,51 +86,38 @@ dependencies:
143
86
  version: '0'
144
87
  type: :development
145
88
  prerelease: false
146
- version_requirements: *70279932917400
147
- - !ruby/object:Gem::Dependency
148
- name: rdoc
149
- requirement: &70279932916880 !ruby/object:Gem::Requirement
89
+ version_requirements: !ruby/object:Gem::Requirement
150
90
  none: false
151
91
  requirements:
152
92
  - - ! '>='
153
93
  - !ruby/object:Gem::Version
154
94
  version: '0'
155
- type: :development
156
- prerelease: false
157
- version_requirements: *70279932916880
158
95
  - !ruby/object:Gem::Dependency
159
- name: mime-types
160
- requirement: &70279932916180 !ruby/object:Gem::Requirement
96
+ name: rdoc
97
+ requirement: !ruby/object:Gem::Requirement
161
98
  none: false
162
99
  requirements:
163
- - - ! '>'
100
+ - - ! '>='
164
101
  - !ruby/object:Gem::Version
165
- version: 0.0.0
166
- type: :runtime
102
+ version: '0'
103
+ type: :development
167
104
  prerelease: false
168
- version_requirements: *70279932916180
169
- - !ruby/object:Gem::Dependency
170
- name: xml-magic
171
- requirement: &70279932915480 !ruby/object:Gem::Requirement
105
+ version_requirements: !ruby/object:Gem::Requirement
172
106
  none: false
173
107
  requirements:
174
- - - ! '>'
108
+ - - ! '>='
175
109
  - !ruby/object:Gem::Version
176
- version: 0.0.0
177
- type: :runtime
178
- prerelease: false
179
- version_requirements: *70279932915480
110
+ version: '0'
180
111
  description: Provides a ruby interface to flickr via the REST api
181
112
  email: ben@commonthread.com
182
113
  executables: []
183
114
  extensions: []
184
- extra_rdoc_files:
185
- - README
115
+ extra_rdoc_files: []
186
116
  files:
187
117
  - Gemfile
188
118
  - Gemfile.lock
189
119
  - LICENSE
190
- - README
120
+ - README.md
191
121
  - Rakefile
192
122
  - VERSION.yml
193
123
  - flickr_fu.gemspec
@@ -224,6 +154,7 @@ files:
224
154
  - spec/fixtures/flickr/photos/get_sizes-0.xml
225
155
  - spec/fixtures/flickr/photos/get_sizes-1.xml
226
156
  - spec/fixtures/flickr/photos/licenses/get_info.xml
157
+ - spec/fixtures/flickr/photosets/create-0.xml
227
158
  - spec/fixtures/flickr/photosets/get_list-0.xml
228
159
  - spec/fixtures/flickr/photosets/get_photos-0.xml
229
160
  - spec/fixtures/flickr/test/echo-0.xml
@@ -268,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
268
199
  version: '0'
269
200
  segments:
270
201
  - 0
271
- hash: -3277112206446566161
202
+ hash: 2842306328355594278
272
203
  required_rubygems_version: !ruby/object:Gem::Requirement
273
204
  none: false
274
205
  requirements:
@@ -277,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
208
  version: '0'
278
209
  requirements: []
279
210
  rubyforge_project:
280
- rubygems_version: 1.8.10
211
+ rubygems_version: 1.8.24
281
212
  signing_key:
282
213
  specification_version: 3
283
214
  summary: Provides a ruby interface to flickr via the REST api
data/README DELETED
@@ -1,147 +0,0 @@
1
- = flickr-fu
2
-
3
- == Contact
4
-
5
- Author: Ben Wyrosdick
6
- Email: ben [at] commonthread.com
7
- Lighthouse: http://commonthread.lighthouseapp.com/projects/12069-flickr_fu/overview
8
- Main Repository: http://github.com/commonthread/flickr_fu/tree/master
9
-
10
- == Getting Started
11
-
12
- You need to first get an API key as detailed here:
13
-
14
- http://www.flickr.com/services/api/misc.api_keys.html
15
-
16
- == Installation
17
-
18
- sudo gem install flickr-fu
19
-
20
- == Documentation
21
-
22
- RDoc Documentation can be found here:
23
-
24
- http://www.commonthread.com/projects/flickr_fu/rdoc/
25
-
26
- == Example flickr.yml
27
- --- !map:HashWithIndifferentAccess
28
- key: "YOUR KEY"
29
- secret: "YOUR SECRET"
30
- token_cache: "token_cache.yml"
31
-
32
- == Authorization
33
-
34
- To authorise your application to access Flickr using your API key you will
35
- need to access a specific URL.
36
-
37
- To generate this URL run the following and when presented with the URL
38
- access it from your browser. Confirm the application has permission at
39
- the level you have specified.
40
-
41
- Note that flickr has different types of keys. If you use one for a webapplication,
42
- which is most likely, you need to define a callback and somehow make sure that
43
- you connect the parameter :frob that flickr send via the callback is assigned
44
- to the right user account. The best way to do this is to loop over all the current
45
- user's flickr accounts and try flickr.auth.token with the :frob.
46
-
47
- Finally, cache the token (this will create the token cache file)
48
-
49
- If you have an invalid API key you will see errors such as:
50
-
51
- "100: Invalid API Key"
52
-
53
- If you don't follow the process below to authorise your application
54
- you will see errors such as:
55
-
56
- "98: Login failed / Invalid auth token" or
57
- "99: User not logged in / Insufficient permissions"
58
-
59
- == Authorization Example for non-webapplication
60
-
61
- require 'flickr_fu'
62
-
63
- flickr = Flickr.new('flickr.yml')
64
-
65
- puts "visit the following url, then click <enter> once you have authorized:"
66
-
67
- # request write permissions
68
- puts flickr.auth.url(:write)
69
-
70
- gets
71
-
72
- flickr.auth.cache_token
73
-
74
- == Authorization Example for a webapplication
75
-
76
- flickr.auth.token also contains the nsid and username, this
77
- example only stores the token and no other userdata.
78
-
79
- require 'flickr_fu'
80
- class FlickrController < ActionController::Base
81
- def create
82
- flickr = Flickr.new('flickr.yml')
83
- redirect_to flickr.auth.url(:write)
84
- end
85
- def flickr_callback
86
- flickr = Flickr.new('flickr.yml')
87
- flickr.auth.frob = params[:frob]
88
- current_user.update_attribute :flickr_token, flickr.auth.token.token
89
- end
90
- def something_else_with_flickr
91
- flickr = Flickr.new(YAML.load_file('flickr.yml').merge(:token => current_user.flickr_token))
92
- # now you have full access on the user's data :)
93
- end
94
- end
95
-
96
- == Search Example
97
-
98
- require 'flickr_fu'
99
-
100
- flickr = Flickr.new('flickr.yml')
101
-
102
- photos = flickr.photos.search(:tags => 'ruby-flickr')
103
-
104
- puts "found #{photos.size} photo(s)"
105
-
106
- photos.each do |photo|
107
- puts photo.title
108
- puts photo.description unless [nil, ''].include?(photo.description)
109
- [:square, :thumbnail, :small, :medium, :large, :original].each do |size|
110
- puts "#{size}: #{photo.url(size)}"
111
- end
112
- puts "comments: #{photo.comments.size}"
113
- photo.comments.each do |comment|
114
- intro = "#{comment.author_name} says - "
115
- puts "#{intro}\"#{comment.comment.gsub("\n", "\n"+(" "*intro.length))}\""
116
- end
117
- puts "notes: #{photo.notes.size}"
118
- photo.notes.each do |note|
119
- puts "[#{note.x},#{note.y} ~ #{note.width}x#{note.height}] - \"#{note.note}\""
120
- end
121
- puts
122
- puts
123
- end
124
-
125
- == Another Search Example
126
-
127
- If searching for photos by user id then you need to specify the 'alias' - without
128
- intervention this is usually set by Flickr and is an alphanumeric string.
129
-
130
- To find out the user id for a given user, you can use the tool at:
131
-
132
- http://idgettr.com/
133
-
134
- And replace the line in the above sample to query on user id:
135
-
136
- photos = flickr.photos.search(:user_id => 'your_user_id_here')
137
-
138
- == Patch Contributers
139
-
140
- Chris Ledet
141
- Maciej Biłas
142
- Mike Perham
143
- Chris Anderton
144
- Luke Francl
145
- Thomas R. Koll
146
- P. Mark Anderson
147
- Josh Nichols