fotonauts-flickr_fu 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,13 +1,19 @@
1
1
  rdoc
2
+ doc
2
3
  .DS_Store
3
4
  *.gem
4
5
  demo*
5
6
  *~
6
7
  *.sw*
7
8
  .specification
8
- nbproject/
9
+ .bundle
10
+
9
11
  doc/rspec_report.html
10
12
  doc/rspec_profile.txt
11
13
  spec/spec.local.opts
12
14
  coverage/
13
15
  pkg/
16
+
17
+ # IDEs
18
+ nbproject/
19
+ .idea
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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
- ---
1
+ ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 5
4
+ :patch: 6
data/flickr_fu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fotonauts-flickr_fu}
5
- s.version = "0.3.4"
5
+ s.version = "0.3.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Wyrosdick", "Maciej Bilas", "Fotonauts"]
@@ -10,12 +10,12 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{Provides a ruby interface to flickr via the REST api}
11
11
  s.email = %q{ben@commonthread.com}
12
12
  s.extra_rdoc_files = [
13
- "README"
13
+ "README.md"
14
14
  ]
15
15
  s.files = [
16
16
  ".gitignore",
17
17
  "LICENSE",
18
- "README",
18
+ "README.md",
19
19
  "Rakefile",
20
20
  "VERSION.yml",
21
21
  "flickr_fu.gemspec",
@@ -82,7 +82,7 @@ Gem::Specification.new do |s|
82
82
  "spec/spec_helper.rb"
83
83
  ]
84
84
  s.homepage = %q{http://github.com/commonthread/flickr_fu}
85
- s.rdoc_options = ["--main", "README"]
85
+ s.rdoc_options = ["--main", "README.md"]
86
86
  s.require_paths = ["lib"]
87
87
  s.rubygems_version = %q{1.3.3}
88
88
  s.summary = %q{Provides a ruby interface to flickr via the REST api}
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 ''
@@ -1,19 +1,23 @@
1
1
  class Flickr::Photosets::Photoset
2
- attr_accessor :id,:num_photos,:title,:description
3
-
2
+ attr_accessor :id,:num_photos,:title,:description,:primary_photo_id
3
+
4
4
  def initialize(flickr, attributes)
5
5
  @flickr = flickr
6
6
  attributes.each do |k,v|
7
7
  send("#{k}=", v)
8
8
  end
9
9
  end
10
-
10
+
11
11
  def get_photos(options={})
12
12
  options = options.merge(:photoset_id=>id)
13
13
  rsp = @flickr.send_request('flickr.photosets.getPhotos', options)
14
14
  collect_photos(rsp)
15
15
  end
16
-
16
+
17
+ def add_photo(photo_id)
18
+ rsp = @flickr.send_request('flickr.photosets.addPhoto', {:photo_id=>photo_id, :photoset_id => id})
19
+ end
20
+
17
21
  protected
18
22
  def collect_photos(rsp)
19
23
  photos = []
@@ -26,11 +30,11 @@ class Flickr::Photosets::Photoset
26
30
  end
27
31
  return photos
28
32
  end
29
-
33
+
30
34
  def create_attributes(photo)
31
35
  {:id => photo[:id],
32
- :secret => photo[:secret],
33
- :server => photo[:server],
36
+ :secret => photo[:secret],
37
+ :server => photo[:server],
34
38
  :farm => photo[:farm],
35
39
  :title => photo[:title]}
36
40
  end
@@ -2,15 +2,24 @@ class Flickr::Photosets < Flickr::Base
2
2
  def initialize(flickr)
3
3
  @flickr = flickr
4
4
  end
5
-
5
+
6
6
  # Get the authorized user's contact list.
7
- #
7
+ #
8
8
  def get_list(options={})
9
9
  rsp = @flickr.send_request('flickr.photosets.getList', options)
10
10
  collect_photosets(rsp)
11
11
  end
12
-
13
- protected
12
+
13
+ #required:
14
+ # title
15
+ # primary_photo_id
16
+ #
17
+ def create(title, primary_photo_id, options={})
18
+ options.merge!({:title => title, :primary_photo_id => primary_photo_id})
19
+ @flickr.send_request('flickr.photosets.create', options)
20
+ end
21
+
22
+ protected
14
23
  def collect_photosets(rsp)
15
24
  photosets = []
16
25
  return photosets unless rsp
@@ -22,18 +31,18 @@ class Flickr::Photosets < Flickr::Base
22
31
  end
23
32
  return photosets
24
33
  end
25
-
34
+
26
35
  def create_attributes(photoset)
27
36
  # comment by : smeevil
28
37
  #
29
38
  # for some reason it was needed to call to_s on photoset.title and photoset.description
30
39
  # without this it will not set the value correctly
31
40
  {
32
- :id => photoset[:id],
41
+ :id => photoset[:id],
33
42
  :num_photos => photoset[:photos],
34
43
  :title => photoset.title.to_s,
35
44
  :description => photoset.description.to_s
36
45
  }
37
46
  end
38
-
39
- end
47
+
48
+ end
@@ -1,93 +1,109 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  module PhotoSpecHelper
4
6
  def valid_photo_attributes
5
7
  {
6
- :id => 2984637736,
7
- :owner => "80755658@N00",
8
- :secret => "9e5762e027",
9
- :server => 3180,
10
- :farm => 4,
11
- :title => "Demolition of Hotel Rzeszów",
12
- :is_public => 1,
13
- :is_friend => 0,
14
- :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
15
17
  }
16
18
  end
17
19
  end
18
20
 
19
21
  describe Flickr::Photos::Photo do
20
-
22
+
21
23
  include PhotoSpecHelper
22
-
24
+
23
25
  before :all do
24
26
  @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_info-0.xml")
25
27
  @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_sizes-0.xml")
26
28
  end
27
-
29
+
28
30
  before :each do
29
31
  @flickr = SpecHelper.flickr
30
32
  #@flickr.stub!(:request_over_http).and_return(info_xml)
31
33
  @photo = Flickr::Photos::Photo.new(@flickr, valid_photo_attributes)
32
34
  end
33
-
35
+
34
36
  describe ".description" do
35
37
  it "should return the description" do
36
38
  @flickr.should_receive(:request_over_http).and_return(@info_xml)
37
- @photo.description.should ==
38
- "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."
39
41
  end
40
42
  end
41
43
 
42
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
+
43
51
  it "should return the appropriate Flickr::Photos::Size instance when requested by symbol" do
44
- @photo.photo_size(:square).class.should == Flickr::Photos::Size
45
- @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"
46
54
  end
47
55
 
48
56
  it "should return the appropriate Flickr::Photos::Size instance when requested by string" do
49
- @photo.photo_size('square').class.should == Flickr::Photos::Size
50
- @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"
51
59
  end
52
60
 
53
61
  it "should return the :medium Flickr::Photos::Size instance invalidly requested" do
54
- @photo.photo_size(:doubleplusbig).class.should == Flickr::Photos::Size
55
- @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"
56
64
  end
57
65
  end
58
66
 
59
67
  describe ".image_url" do
60
68
  it "should return all standard sizes (thumbnail, square, small, medium and large) when requested" do
61
- @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"
62
71
  @photo.image_url(:thumbnail).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_t.jpg"
63
72
  @photo.image_url(:small).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_m.jpg"
64
- @photo.image_url(:medium).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027.jpg"
65
- @photo.image_url(:large).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_b.jpg"
66
- end
67
-
68
- it "should return the same image even if you pass a string as an argument" do
69
- @photo.image_url("square").should == @photo.image_url(:square)
70
- @photo.image_url("large").should == @photo.image_url(:large)
71
- end
72
-
73
- it "should not call getSizes if not requested the url of the original image" do
74
- @flickr.should_not_receive(:request_over_http)
75
- @photo.image_url :square
76
- @photo.image_url :thumbnail
77
- @photo.image_url :small
78
- @photo.image_url :medium
79
- @photo.image_url :large
80
- end
81
-
82
- it "should call getSizes if requested the url of the original image" do
83
- @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
84
- @photo.image_url :original
85
- end
86
-
87
- it "should return nil if original image url not available" do
88
- @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
89
- @photo.image_url(:original).should == nil
90
- 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
91
107
  end
92
108
 
93
109
  describe ".video_url" do
@@ -118,12 +134,12 @@ describe Flickr::Photos::Photo do
118
134
  describe Flickr::Photos::Photo, "but it's really a video" do
119
135
 
120
136
  include PhotoSpecHelper
121
-
137
+
122
138
  before :all do
123
139
  @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_info-0.xml")
124
140
  @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_sizes-0.xml")
125
141
  end
126
-
142
+
127
143
  before :each do
128
144
  @flickr = SpecHelper.flickr
129
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
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe Flickr::Urls do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- gem 'rspec'
3
- require 'spec'
1
+ require 'rspec'
4
2
 
5
3
  $:.unshift(File.dirname(__FILE__) + '/../lib')
6
4
  require 'flickr_fu'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fotonauts-flickr_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -34,11 +34,11 @@ email: ben@commonthread.com
34
34
  executables: []
35
35
  extensions: []
36
36
  extra_rdoc_files:
37
- - README
37
+ - README.md
38
38
  files:
39
39
  - .gitignore
40
40
  - LICENSE
41
- - README
41
+ - README.md
42
42
  - Rakefile
43
43
  - VERSION.yml
44
44
  - flickr_fu.gemspec
@@ -108,7 +108,7 @@ licenses: []
108
108
  post_install_message:
109
109
  rdoc_options:
110
110
  - --main
111
- - README
111
+ - README.md
112
112
  require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
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