fotonauts-flickr_fu 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +13 -0
  2. data/LICENSE +22 -0
  3. data/README +147 -0
  4. data/Rakefile +73 -0
  5. data/VERSION.yml +4 -0
  6. data/flickr_fu.gemspec +117 -0
  7. data/lib/flickr/auth.rb +76 -0
  8. data/lib/flickr/base.rb +151 -0
  9. data/lib/flickr/comment.rb +16 -0
  10. data/lib/flickr/contact.rb +16 -0
  11. data/lib/flickr/contacts.rb +55 -0
  12. data/lib/flickr/errors.rb +20 -0
  13. data/lib/flickr/geo.rb +42 -0
  14. data/lib/flickr/license.rb +24 -0
  15. data/lib/flickr/location.rb +15 -0
  16. data/lib/flickr/note.rb +16 -0
  17. data/lib/flickr/people.rb +54 -0
  18. data/lib/flickr/person.rb +82 -0
  19. data/lib/flickr/photo.rb +321 -0
  20. data/lib/flickr/photo_response.rb +37 -0
  21. data/lib/flickr/photos.rb +252 -0
  22. data/lib/flickr/photoset.rb +37 -0
  23. data/lib/flickr/photosets.rb +39 -0
  24. data/lib/flickr/size.rb +16 -0
  25. data/lib/flickr/status.rb +19 -0
  26. data/lib/flickr/test.rb +31 -0
  27. data/lib/flickr/token.rb +22 -0
  28. data/lib/flickr/uploader.rb +162 -0
  29. data/lib/flickr/urls.rb +44 -0
  30. data/lib/flickr_fu.rb +48 -0
  31. data/spec/fixtures/flickr/contacts/get_list-fail-99.xml +4 -0
  32. data/spec/fixtures/flickr/contacts/get_public_list-0.xml +7 -0
  33. data/spec/fixtures/flickr/photos/geo/get_location-0.xml +11 -0
  34. data/spec/fixtures/flickr/photos/geo/get_location-fail-2.xml +4 -0
  35. data/spec/fixtures/flickr/photos/get_info-0.xml +41 -0
  36. data/spec/fixtures/flickr/photos/get_info-1.xml +19 -0
  37. data/spec/fixtures/flickr/photos/get_sizes-0.xml +10 -0
  38. data/spec/fixtures/flickr/photos/get_sizes-1.xml +8 -0
  39. data/spec/fixtures/flickr/photos/licenses/get_info.xml +12 -0
  40. data/spec/fixtures/flickr/photosets/get_list-0.xml +13 -0
  41. data/spec/fixtures/flickr/photosets/get_photos-0.xml +7 -0
  42. data/spec/fixtures/flickr/test/echo-0.xml +5 -0
  43. data/spec/fixtures/flickr/test/null-fail-99.xml +4 -0
  44. data/spec/fixtures/flickr/urls/get_group-0.xml +4 -0
  45. data/spec/fixtures/flickr/urls/get_group-fail-1.xml +4 -0
  46. data/spec/fixtures/flickr/urls/get_user_photos-0.xml +4 -0
  47. data/spec/fixtures/flickr/urls/get_user_photos-fail-1.xml +4 -0
  48. data/spec/fixtures/flickr/urls/get_user_photos-fail-2.xml +4 -0
  49. data/spec/fixtures/flickr/urls/get_user_profile-0.xml +4 -0
  50. data/spec/fixtures/flickr/urls/get_user_profile-fail-1.xml +4 -0
  51. data/spec/fixtures/flickr/urls/get_user_profile-fail-2.xml +4 -0
  52. data/spec/fixtures/flickr/urls/lookup_group-0.xml +6 -0
  53. data/spec/fixtures/flickr/urls/lookup_group-fail-1.xml +4 -0
  54. data/spec/fixtures/flickr/urls/lookup_user-0.xml +6 -0
  55. data/spec/fixtures/flickr/videos/get_info-0.xml +31 -0
  56. data/spec/fixtures/flickr/videos/get_sizes-0.xml +13 -0
  57. data/spec/flickr/base_spec.rb +97 -0
  58. data/spec/flickr/contacts_spec.rb +47 -0
  59. data/spec/flickr/errors_spec.rb +21 -0
  60. data/spec/flickr/geo_spec.rb +20 -0
  61. data/spec/flickr/photo_spec.rb +140 -0
  62. data/spec/flickr/photos_spec.rb +50 -0
  63. data/spec/flickr/photosets_spec.rb +49 -0
  64. data/spec/flickr/test_spec.rb +34 -0
  65. data/spec/flickr/urls_spec.rb +99 -0
  66. data/spec/spec.opts +4 -0
  67. data/spec/spec_helper.rb +20 -0
  68. metadata +176 -0
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <contacts page="1" pages="1" per_page="1000" perpage="1000" total="2">
4
+ <contact nsid="40718771@N00" username="kooop" iconserver="2" iconfarm="1" ignored="0" />
5
+ <contact nsid="20039881@N00" username="wayoutwest" iconserver="1" iconfarm="1" ignored="0" />
6
+ </contacts>
7
+ </rsp>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="2984637736">
4
+ <location latitude="50.041376" longitude="21.999006" accuracy="16" context="0" place_id="X.5ul_ucAJtJcT0" woeid="517126">
5
+ <locality place_id="X.5ul_ucAJtJcT0" woeid="517126">Rzeszów</locality>
6
+ <county place_id="gUrbqNqYA5n4kv.erw" woeid="12591341">Rzeszów</county>
7
+ <region place_id="acDFruGYA5lyOpcIVg" woeid="12577943">Subcarpathia</region>
8
+ <country place_id="0kV97TybAphIxvm14g" woeid="23424923">Poland</country>
9
+ </location>
10
+ </photo>
11
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="Photo has no location information."/>
4
+ </rsp>
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="2984637736" secret="9e5762e027" server="3180" farm="4" dateuploaded="1225297614" isfavorite="0" license="0" rotation="0" media="photo">
4
+ <owner nsid="80755658@N00" username="Maciej Biłas" realname="Maciej Biłas" location="Rzeszów, Poland"/>
5
+ <title>Demolition of Hotel Rzeszów</title>
6
+ <description>
7
+ The last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów.
8
+ </description>
9
+ <visibility ispublic="1" isfriend="0" isfamily="0"/>
10
+ <dates posted="1225297614" taken="2007-04-20 17:56:06" takengranularity="0" lastupdate="1227358764"/>
11
+ <editability cancomment="0" canaddmeta="0"/>
12
+ <usage candownload="0" canblog="0" canprint="0"/>
13
+ <comments>0</comments>
14
+ <notes/>
15
+ <tags>
16
+ <tag id="4963651-2984637736-9769036" author="80755658@N00" raw="Hotel Rzeszów" machine_tag="0">hotelrzeszów
17
+ </tag>
18
+ <tag id="4963651-2984637736-9381" author="80755658@N00" raw="demolition" machine_tag="0">demolition
19
+ </tag>
20
+ <tag id="4963651-2984637736-1888184" author="80755658@N00" raw="Rzeszów" machine_tag="0">rzeszów
21
+ </tag>
22
+ <tag id="4963651-2984637736-8302" author="80755658@N00" raw="Poland" machine_tag="0">poland
23
+ </tag>
24
+ </tags>
25
+ <location latitude="50.041376" longitude="21.999006" accuracy="16" place_id="X.5ul_ucAJtJcT0" woeid="517126">
26
+ <locality place_id="X.5ul_ucAJtJcT0" woeid="517126">Rzeszów
27
+ </locality>
28
+ <county place_id="gUrbqNqYA5n4kv.erw" woeid="12591341">Rzeszów
29
+ </county>
30
+ <region place_id="acDFruGYA5lyOpcIVg" woeid="12577943">Subcarpathia
31
+ </region>
32
+ <country place_id="0kV97TybAphIxvm14g" woeid="23424923">Poland
33
+ </country>
34
+ </location>
35
+ <geoperms ispublic="1" iscontact="0" isfriend="0" isfamily="0"/>
36
+ <urls>
37
+ <url type="photopage">http://www.flickr.com/photos/lvizard/2984637736/
38
+ </url>
39
+ </urls>
40
+ </photo>
41
+ </rsp>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="3059178826" secret="951324cc9f" server="3008" farm="4" dateuploaded="1227628465" isfavorite="0" license="0" rotation="0" originalsecret="fdbf0e4ced" originalformat="jpg" views="0" media="photo">
4
+ <owner nsid="80755658@N00" username="Maciej Biłas" realname="Maciej Biłas" location="Rzeszów, Poland"/>
5
+ <title>test</title>
6
+ <description/>
7
+ <visibility ispublic="0" isfriend="0" isfamily="0"/>
8
+ <dates posted="1227628465" taken="2008-11-25 16:54:25" takengranularity="0" lastupdate="1227628476"/>
9
+ <permissions permcomment="3" permaddmeta="2"/>
10
+ <editability cancomment="1" canaddmeta="1"/>
11
+ <usage candownload="0" canblog="1" canprint="1"/>
12
+ <comments>0</comments>
13
+ <notes/>
14
+ <tags/>
15
+ <urls>
16
+ <url type="photopage">http://www.flickr.com/photos/lvizard/3059178826/</url>
17
+ </urls>
18
+ </photo>
19
+ </rsp>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <sizes canblog="0" canprint="0" candownload="0">
4
+ <size label="Square" width="75" height="75" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_s.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/sq/" media="photo"/>
5
+ <size label="Thumbnail" width="100" height="67" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_t.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/t/" media="photo"/>
6
+ <size label="Small" width="240" height="160" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_m.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/s/" media="photo"/>
7
+ <size label="Medium" width="500" height="333" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/m/" media="photo"/>
8
+ <size label="Large" width="1024" height="683" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_b.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/l/" media="photo"/>
9
+ </sizes>
10
+ </rsp>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <sizes canblog="1" canprint="1" candownload="0">
4
+ <size label="Square" width="75" height="75" source="http://farm4.static.flickr.com/3008/3059178826_951324cc9f_s.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/sq/" media="photo"/>
5
+ <size label="Thumbnail" width="70" height="72" source="http://farm4.static.flickr.com/3008/3059178826_951324cc9f_t.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/t/" media="photo"/>
6
+ <size label="Original" width="70" height="72" source="http://farm4.static.flickr.com/3008/3059178826_fdbf0e4ced_o.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/o/" media="photo"/>
7
+ </sizes>
8
+ </rsp>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <licenses>
4
+ <license id="0" name="All Rights Reserved" url=""/>
5
+ <license id="4" name="Attribution License" url="http://creativecommons.org/licenses/by/2.0/"/>
6
+ <license id="6" name="Attribution-NoDerivs License" url="http://creativecommons.org/licenses/by-nd/2.0/"/>
7
+ <license id="3" name="Attribution-NonCommercial-NoDerivs License" url="http://creativecommons.org/licenses/by-nc-nd/2.0/"/>
8
+ <license id="2" name="Attribution-NonCommercial License" url="http://creativecommons.org/licenses/by-nc/2.0/"/>
9
+ <license id="1" name="Attribution-NonCommercial-ShareAlike License" url="http://creativecommons.org/licenses/by-nc-sa/2.0/"/>
10
+ <license id="5" name="Attribution-ShareAlike License" url="http://creativecommons.org/licenses/by-sa/2.0/"/>
11
+ </licenses>
12
+ </rsp>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photosets cancreate="1">
4
+ <photoset id="5" primary="2483" secret="abcdef" server="8" photos="4" farm="1">
5
+ <title>Test</title>
6
+ <description>foo</description>
7
+ </photoset>
8
+ <photoset id="4" primary="1234" secret="832659" server="3" photos="12" farm="1">
9
+ <title>My Set</title>
10
+ <description>bar</description>
11
+ </photoset>
12
+ </photosets>
13
+ </rsp>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photoset id="4" primary="2483" page="1" perpage="500" pages="1" total="2">
4
+ <photo id="2484" secret="123456" server="1" title="my photo" isprimary="0" />
5
+ <photo id="2483" secret="123456" server="1" title="flickr rocks" isprimary="1" />
6
+ </photoset>
7
+ </rsp>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <method>flickr.test.echo</method>
4
+ <foo>bar</foo>
5
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="99" msg="Insufficient permissions. Method requires read privileges; none granted."/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <group nsid="34427469792@N01" url="http://www.flickr.com/groups/central/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="Group not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <user nsid="80755658@N00" url="http://www.flickr.com/photos/lvizard/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="User not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="No user specified"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <user nsid="80755658@N00" url="http://www.flickr.com/people/lvizard/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="User not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="No user specified"/>
4
+ </rsp>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <group id="34427469792@N01">
4
+ <groupname>FlickrCentral</groupname>
5
+ </group>
6
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="Group not found"/>
4
+ </rsp>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <user id="80755658@N00">
4
+ <username>Maciej Biłas</username>
5
+ </user>
6
+ </rsp>
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="2729556270" secret="eee23fb14a" server="3207" farm="4" dateuploaded="1217794663" isfavorite="0" license="4" rotation="0" originalsecret="e940a69ebf" originalformat="png" media="video">
4
+ <owner nsid="24461004@N00" username="girl_named_fred" realname="Cynthia Donovan" location="Pawtucket, USA" />
5
+ <title>bust a move?</title>
6
+ <description />
7
+ <visibility ispublic="1" isfriend="0" isfamily="0" />
8
+ <dates posted="1217794663" taken="2008-08-03 13:17:43" takengranularity="0" lastupdate="1217859448" />
9
+ <editability cancomment="0" canaddmeta="0" />
10
+ <usage candownload="1" canblog="0" canprint="0" />
11
+
12
+ <comments>0</comments>
13
+ <notes />
14
+ <tags>
15
+ <tag id="251642-2729556270-6613225" author="24461004@N00" raw="babysquash" machine_tag="0">babysquash</tag>
16
+ <tag id="251642-2729556270-8754" author="24461004@N00" raw="august" machine_tag="0">august</tag>
17
+ <tag id="251642-2729556270-30529" author="24461004@N00" raw="anita" machine_tag="0">anita</tag>
18
+ <tag id="251642-2729556270-65815" author="24461004@N00" raw="waltham" machine_tag="0">waltham</tag>
19
+
20
+ <tag id="251642-2729556270-1853" author="24461004@N00" raw="liberty" machine_tag="0">liberty</tag>
21
+ <tag id="251642-2729556270-20506" author="24461004@N00" raw="cousin" machine_tag="0">cousin</tag>
22
+ <tag id="251642-2729556270-2079514" author="24461004@N00" raw="brucespringstein" machine_tag="0">brucespringstein</tag>
23
+ </tags>
24
+ <urls>
25
+ <url type="photopage">http://www.flickr.com/photos/girl_named_fred/2729556270/</url>
26
+ </urls>
27
+
28
+ <video ready="1" failed="0" pending="0" duration="" width="320" height="240" />
29
+ </photo>
30
+ </rsp>
31
+
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <sizes canblog="0" canprint="0" candownload="1">
4
+ <size label="Square" width="75" height="75" source="http://farm4.static.flickr.com/3207/2729556270_eee23fb14a_s.jpg" url="http://www.flickr.com/photos/girl_named_fred/2729556270/sizes/sq/" media="photo" />
5
+ <size label="Thumbnail" width="100" height="75" source="http://farm4.static.flickr.com/3207/2729556270_eee23fb14a_t.jpg" url="http://www.flickr.com/photos/girl_named_fred/2729556270/sizes/t/" media="photo" />
6
+ <size label="Small" width="240" height="180" source="http://farm4.static.flickr.com/3207/2729556270_eee23fb14a_m.jpg" url="http://www.flickr.com/photos/girl_named_fred/2729556270/sizes/s/" media="photo" />
7
+ <size label="Medium" width="320" height="240" source="http://farm4.static.flickr.com/3207/2729556270_eee23fb14a.jpg" url="http://www.flickr.com/photos/girl_named_fred/2729556270/sizes/m/" media="photo" />
8
+ <size label="Original" width="320" height="240" source="http://farm4.static.flickr.com/3207/2729556270_e940a69ebf_o.png" url="http://www.flickr.com/photos/girl_named_fred/2729556270/sizes/o/" media="photo" />
9
+ <size label="Video Player" width="320" height="240" source="http://www.flickr.com/apps/video/stewart.swf?v=63881&amp;photo_id=2729556270&amp;photo_secret=eee23fb14a" url="http://www.flickr.com/photos/girl_named_fred/2729556270/" media="video" />
10
+ </sizes>
11
+ </rsp>
12
+
13
+
@@ -0,0 +1,97 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Flickr do
4
+
5
+ before :all do
6
+ @token = Flickr::Auth::Token.new(:permissions => "write", :token => "foo", :user_id => "80755658@N00",
7
+ :user_real_name => "Maciej Bilas", :username => "Maciej Bilas")
8
+ @api_key = "foo"
9
+ @api_secret = "bar"
10
+ @yaml_hash = {"key" => @api_key, "secret" => @api_secret}
11
+ end
12
+
13
+ describe ".new" do
14
+
15
+ describe "with no environment option specified" do
16
+ it "should inititialize Flickr from a Hash" do
17
+ # AFAIK there is no spec on how the key and secret look like
18
+ # so we can test with simple values
19
+ init_hash = {:key => @api_key, :secret => @api_secret}
20
+ flickr = Flickr.new(init_hash)
21
+ flickr.api_key.should == @api_key
22
+ flickr.api_secret.should == @api_secret
23
+
24
+ init_hash_with_token = init_hash.merge(:token => @token)
25
+ flickr = Flickr.new(init_hash_with_token)
26
+ flickr.token.should == @token
27
+ end
28
+
29
+ it "should initialize Flickr from a YAML file" do
30
+ YAML.should_receive(:load_file).once.and_return(@yaml_hash)
31
+ flickr = Flickr.new("flickr.yml")
32
+ flickr.api_key.should == @api_key
33
+ flickr.api_secret.should == @api_secret
34
+ end
35
+
36
+ it "should fail if API key or secret value is absent" do
37
+ invalid_hash = {:key => @api_key}
38
+ lambda { Flickr.new(invalid_hash) }.should raise_error
39
+ invalid_hash = {:secret => @api_secret}
40
+ lambda { Flickr.new(invalid_hash) }.should raise_error
41
+ end
42
+
43
+ end
44
+
45
+ describe "with an environment option specified" do
46
+ before :all do
47
+ @environment_specified = "development"
48
+ end
49
+
50
+ it "should initialize Flickr from a YAML file" do
51
+ yaml_hash = {@environment_specified => {"key" => @api_key, "secret" => @api_secret}}
52
+ YAML.should_receive(:load_file).once.and_return(yaml_hash)
53
+ flickr = Flickr.new("flickr.yml", :environment => @environment_specified)
54
+ flickr.api_key.should == @api_key
55
+ flickr.api_secret.should == @api_secret
56
+ end
57
+ end
58
+
59
+ describe "when token_cache is passed (only with a YAML file)" do
60
+
61
+ before :all do
62
+ @expected_token_cache = "token_cache.yml"
63
+ end
64
+
65
+ # For backward compatibility
66
+ it "should initialize Flickr with token_cache when passed as the second parameter" do
67
+ YAML.should_receive(:load_file).once.and_return(@yaml_hash)
68
+ flickr = Flickr.new("flickr.yml", @expected_token_cache)
69
+ flickr.token_cache.should == @expected_token_cache
70
+ end
71
+
72
+ it "should initialize Flickr with token_cache when passed as an option" do
73
+ YAML.should_receive(:load_file).once.and_return(@yaml_hash)
74
+ flickr = Flickr.new("flickr.yml", :token_cache => @expected_token_cache)
75
+ flickr.token_cache.should == @expected_token_cache
76
+ end
77
+ end
78
+
79
+ describe "when token is passed as an options (only with a YAML file)" do
80
+
81
+ it "should initialize Flickr with a token if passed" do
82
+ YAML.should_receive(:load_file).once.and_return(@yaml_hash)
83
+ flickr = Flickr.new("flickr.yml", :token => @token)
84
+ flickr.token.should == @token
85
+ end
86
+
87
+ end
88
+
89
+ describe "when both token and token_cache are passed" do
90
+ it "should raise an error" do
91
+ YAML.should_receive(:load_file).once.and_return(@yaml_hash)
92
+ lambda { Flickr.new("flickr.yml", {:token => @token, :token_cache => "token_cache.yml"})}.should raise_error
93
+ end
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Flickr::Contacts do
4
+
5
+ before :each do
6
+ @flickr = SpecHelper.flickr
7
+ end
8
+
9
+ describe ".get_public_list" do
10
+ before :all do
11
+ @public_list_xml = File.read(File.dirname(__FILE__) +
12
+ "/../fixtures/flickr/contacts/get_public_list-0.xml")
13
+ end
14
+
15
+ it "should call flickr.contacts.getPublicList" do
16
+ bogus_user_id = "12334@N00"
17
+ @flickr.should_receive(:send_request).with("flickr.contacts.getPublicList",
18
+ {:user_id=>bogus_user_id})
19
+ @flickr.contacts.get_public_list(bogus_user_id)
20
+ end
21
+
22
+ it "should return public contacts for the given user" do
23
+ bogus_user_id = "12334@N00"
24
+ @flickr.stub!(:request_over_http).and_return(@public_list_xml)
25
+ contacts = @flickr.contacts.get_public_list(bogus_user_id)
26
+ contacts.size.should == 2
27
+ contacts.first.username.should == "kooop"
28
+ contacts.first.nsid.should == "40718771@N00"
29
+ contacts.first.iconserver.should == "2"
30
+ contacts.first.iconfarm.should == "1"
31
+ end
32
+ end
33
+
34
+ describe ".get_list" do
35
+ it "should call flickr.contacts.getList" do
36
+ @flickr.should_receive(:send_request).with("flickr.contacts.getList", {})
37
+ @flickr.contacts.get_list
38
+ end
39
+
40
+ it "should raise flickr error 99: Insufficient permissions" do
41
+ xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/contacts/get_list-fail-99.xml")
42
+ @flickr.stub!(:request_over_http).and_return(xml)
43
+ lambda { @flickr.contacts.get_list }.should raise_error(Flickr::Error, /^99:/)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Flickr::Errors, ".error_for" do
4
+ it "should raise a RuntimeError with an \"Internal message\" message if either code or message is blank" do
5
+ lambda { Flickr::Errors.error_for(nil, nil) }.should raise_error(RuntimeError, /^Internal error/)
6
+ lambda { Flickr::Errors.error_for(20, nil) }.should raise_error(RuntimeError, /^Internal error/)
7
+ lambda { Flickr::Errors.error_for(nil, "foo") }.should raise_error(RuntimeError, /^Internal error/)
8
+ end
9
+
10
+ it "should raise a RuntimeError with an \"Internal error\" message if code is not an integer" do
11
+ lambda { Flickr::Errors.error_for("a", "foo")}.should raise_error(RuntimeError, /^Internal error/)
12
+ end
13
+
14
+ it "should raise a valid error if parameters are valid" do
15
+ lambda { Flickr::Errors.error_for(96, "Invalid signature")}.should raise_error(Flickr::Error)
16
+ end
17
+
18
+ it "should return an error with a message starting with the error code" do
19
+ lambda { Flickr::Errors.error_for(97, "Missing signature")}.should raise_error(Flickr::Error, /^97/)
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Flickr::Photos::Geo do
4
+
5
+ before :each do
6
+ @flickr = SpecHelper.flickr
7
+ end
8
+
9
+ describe ".get_location" do
10
+ it "should return the geo data (latitude and longitude and the accuracy level) for a photo" do
11
+ location_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/geo/get_location-0.xml")
12
+ @flickr.should_receive(:request_over_http).and_return(location_xml)
13
+ acctual_loc = @flickr.photos.geo.get_location(2984637736)
14
+ acctual_loc.latitude.should == 50.041376
15
+ acctual_loc.longitude.should == 21.999006
16
+ acctual_loc.accuracy.should == 16
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module PhotoSpecHelper
4
+ def valid_photo_attributes
5
+ {
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
15
+ }
16
+ end
17
+ end
18
+
19
+ describe Flickr::Photos::Photo do
20
+
21
+ include PhotoSpecHelper
22
+
23
+ before :all do
24
+ @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_info-0.xml")
25
+ @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/get_sizes-0.xml")
26
+ end
27
+
28
+ before :each do
29
+ @flickr = SpecHelper.flickr
30
+ #@flickr.stub!(:request_over_http).and_return(info_xml)
31
+ @photo = Flickr::Photos::Photo.new(@flickr, valid_photo_attributes)
32
+ end
33
+
34
+ describe ".description" do
35
+ it "should return the description" do
36
+ @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
+ end
40
+ end
41
+
42
+ describe ".photo_size" do
43
+ 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"
46
+ end
47
+
48
+ 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"
51
+ end
52
+
53
+ 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"
56
+ end
57
+ end
58
+
59
+ describe ".image_url" do
60
+ 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"
62
+ @photo.image_url(:thumbnail).should == "http://farm4.static.flickr.com/3180/2984637736_9e5762e027_t.jpg"
63
+ @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
91
+ end
92
+
93
+ describe ".video_url" do
94
+ it "should return nil, since it's not a video" do
95
+ @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
96
+ @photo.video_url.should == nil
97
+ end
98
+ end
99
+
100
+ describe ".location" do
101
+ it "should return the picture location as specified in flickr.photos.geo.getLocation" do
102
+ location_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/geo/get_location-0.xml")
103
+ @flickr.should_receive(:request_over_http).twice.and_return(location_xml)
104
+ expected_loc = @flickr.photos.geo.get_location(@photo.id)
105
+ acctual_loc = @photo.location
106
+ # Checking by latitude and longitude is enough for us
107
+ acctual_loc.latitude.should == expected_loc.latitude
108
+ acctual_loc.longitude.should == expected_loc.longitude
109
+ end
110
+
111
+ it "should return nil if picture is not geo-tagged" do
112
+ no_location_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/photos/geo/get_location-fail-2.xml")
113
+ @flickr.should_receive(:request_over_http).and_return(no_location_xml)
114
+ @photo.location.should be_nil
115
+ end
116
+ end
117
+
118
+ describe Flickr::Photos::Photo, "but it's really a video" do
119
+
120
+ include PhotoSpecHelper
121
+
122
+ before :all do
123
+ @info_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_info-0.xml")
124
+ @sizes_xml = File.read(File.dirname(__FILE__) + "/../fixtures/flickr/videos/get_sizes-0.xml")
125
+ end
126
+
127
+ before :each do
128
+ @flickr = SpecHelper.flickr
129
+ #@flickr.stub!(:request_over_http).and_return(info_xml)
130
+ @photo = Flickr::Photos::Photo.new(@flickr, valid_photo_attributes)
131
+ end
132
+
133
+ describe ".video_url" do
134
+ it "should return something sane" do
135
+ @flickr.should_receive(:request_over_http).and_return(@sizes_xml)
136
+ @photo.video_url.should == "http://www.flickr.com/apps/video/stewart.swf?v=63881&photo_id=2729556270&photo_secret=eee23fb14a"
137
+ end
138
+ end
139
+ end
140
+ end