fleakr 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.rdoc +88 -57
  2. data/Rakefile +28 -9
  3. data/lib/fleakr.rb +25 -31
  4. data/lib/fleakr/api/option.rb +34 -34
  5. data/lib/fleakr/api/parameter_list.rb +23 -23
  6. data/lib/fleakr/objects.rb +4 -1
  7. data/lib/fleakr/objects/metadata.rb +35 -0
  8. data/lib/fleakr/objects/metadata_collection.rb +36 -0
  9. data/lib/fleakr/objects/photo.rb +15 -11
  10. data/lib/fleakr/objects/set.rb +17 -13
  11. data/lib/fleakr/objects/url.rb +83 -0
  12. data/lib/fleakr/objects/user.rb +8 -0
  13. data/lib/fleakr/support.rb +3 -1
  14. data/lib/fleakr/support/attribute.rb +2 -2
  15. data/lib/fleakr/support/object.rb +44 -29
  16. data/lib/fleakr/support/url_expander.rb +37 -0
  17. data/lib/fleakr/support/utility.rb +66 -0
  18. data/lib/fleakr/version.rb +5 -5
  19. data/test/fixtures/photos.getExif.xml +362 -0
  20. data/test/test_helper.rb +44 -47
  21. data/test/unit/fleakr/api/authentication_request_test.rb +12 -12
  22. data/test/unit/fleakr/api/file_parameter_test.rb +15 -15
  23. data/test/unit/fleakr/api/method_request_test.rb +1 -1
  24. data/test/unit/fleakr/api/option_test.rb +44 -44
  25. data/test/unit/fleakr/api/parameter_list_test.rb +40 -40
  26. data/test/unit/fleakr/api/response_test.rb +10 -10
  27. data/test/unit/fleakr/api/upload_request_test.rb +28 -28
  28. data/test/unit/fleakr/api/value_parameter_test.rb +10 -10
  29. data/test/unit/fleakr/core_ext/false_class_test.rb +5 -5
  30. data/test/unit/fleakr/core_ext/hash_test.rb +9 -9
  31. data/test/unit/fleakr/core_ext/true_class_test.rb +5 -5
  32. data/test/unit/fleakr/objects/authentication_token_test.rb +23 -23
  33. data/test/unit/fleakr/objects/collection_test.rb +23 -23
  34. data/test/unit/fleakr/objects/comment_test.rb +15 -15
  35. data/test/unit/fleakr/objects/contact_test.rb +11 -11
  36. data/test/unit/fleakr/objects/error_test.rb +8 -8
  37. data/test/unit/fleakr/objects/group_test.rb +13 -13
  38. data/test/unit/fleakr/objects/image_test.rb +4 -4
  39. data/test/unit/fleakr/objects/metadata_collection_test.rb +55 -0
  40. data/test/unit/fleakr/objects/metadata_test.rb +27 -0
  41. data/test/unit/fleakr/objects/photo_context_test.rb +23 -23
  42. data/test/unit/fleakr/objects/photo_test.rb +71 -64
  43. data/test/unit/fleakr/objects/search_test.rb +22 -22
  44. data/test/unit/fleakr/objects/set_test.rb +62 -40
  45. data/test/unit/fleakr/objects/tag_test.rb +32 -31
  46. data/test/unit/fleakr/objects/url_test.rb +185 -0
  47. data/test/unit/fleakr/objects/user_test.rb +43 -16
  48. data/test/unit/fleakr/support/attribute_test.rb +15 -15
  49. data/test/unit/fleakr/support/object_test.rb +77 -33
  50. data/test/unit/fleakr/support/request_test.rb +12 -12
  51. data/test/unit/fleakr/support/url_expander_test.rb +44 -0
  52. data/test/unit/fleakr/support/utility_test.rb +70 -0
  53. data/test/unit/fleakr_test.rb +48 -41
  54. metadata +43 -23
@@ -26,15 +26,15 @@ Now that you have your key, you can get things rolling with irb and the fleakr g
26
26
 
27
27
  $ irb -r rubygems
28
28
  >> require 'fleakr'
29
-
29
+
30
30
  Then, set your API key (only need to do this once per session):
31
31
 
32
32
  >> Fleakr.api_key = '<your api key here>'
33
33
 
34
34
  === A Brief Tour
35
35
 
36
- With just an API key, you have the ability to retrieve a substantial amount of data
37
- about users, their photosets, photos, contacts, and groups. Let's start by finding a
36
+ With just an API key, you have the ability to retrieve a substantial amount of data
37
+ about users, their photosets, photos, contacts, and groups. Let's start by finding a
38
38
  user by his username:
39
39
 
40
40
  >> user = Fleakr.user('the decapitator')
@@ -44,7 +44,7 @@ By email:
44
44
 
45
45
  >> user = Fleakr.user('user@host.com')
46
46
  => #<Fleakr::Objects::User:0x11f484c @username="bckspcr", @id="84481630@N00">
47
-
47
+
48
48
  Or even by URL:
49
49
 
50
50
  >> user = Fleakr.user('http://www.flickr.com/photos/the_decapitator/')
@@ -53,7 +53,7 @@ Or even by URL:
53
53
  Once you have a user, you can find his associated sets:
54
54
 
55
55
  >> user.sets
56
- => [#<Fleakr::Objects::Set:0x671358 @title="The Decapitator", @description="">,
56
+ => [#<Fleakr::Objects::Set:0x671358 @title="The Decapitator", @description="">,
57
57
  #<Fleakr::Objects::Set:0x66d898 @title="londonpaper hijack", ...
58
58
 
59
59
  His individual photos:
@@ -68,9 +68,9 @@ Or contacts:
68
68
  @id="12289718@N00", @icon_farm="1", @icon_server="4">
69
69
 
70
70
  Or his groups if you would like:
71
-
71
+
72
72
  >> user.groups
73
- => [#<Fleakr::Objects::Group:0x11f2330 ...,
73
+ => [#<Fleakr::Objects::Group:0x11f2330 ...,
74
74
  #<Fleakr::Objects::Group:0x11f2308 ...
75
75
  >> user.groups.first.name
76
76
  => "Rural Decay"
@@ -93,20 +93,20 @@ When accessing a set, you can also grab all the photos that are in that set:
93
93
 
94
94
  === Contacts
95
95
 
96
- Besides pulling back a given user's public contacts list, you can also retrieve the list of
96
+ Besides pulling back a given user's public contacts list, you can also retrieve the list of
97
97
  contacts for the currently authenticated user (see below about authentication). For example,
98
98
  you can retrieve all contacts:
99
99
 
100
100
  >> Fleakr.contacts
101
101
  => [#<Fleakr::Objects::Contact:0x111ff84 @username="bryan.ray" ...>]
102
-
102
+
103
103
  Or just the contacts marked as 'family':
104
-
104
+
105
105
  >> Fleakr.contacts(:family)
106
106
  => [#<Fleakr::Objects::Contact:0x12db42c @username="Grandbob" ...>]
107
-
107
+
108
108
  Or a specific page of contacts marked as 'friends':
109
-
109
+
110
110
  >> Fleakr.contacts(:friends, :page => 3, :per_page => 5)
111
111
  => [#<Fleakr::Objects::Contact:0x12a6c54 @username="Louise and BCG" ...>]
112
112
 
@@ -116,40 +116,40 @@ See the documentation for Fleakr.contacts for what options are available.
116
116
 
117
117
  Each photo object contains metadata about a collection of images, each representing different
118
118
  sizes. Once we have a single photo:
119
-
119
+
120
120
  >> photo = user.photos.first
121
121
  => #<Fleakr::Objects::Photo:0x161b024 @title="\"Be Fabulous\"" ... >
122
-
122
+
123
123
  We can get information about one of the sizes:
124
124
 
125
125
  >> photo.small
126
126
  => #<Fleakr::Objects::Image:0x1768f1c @height="172", @size="Small", @width="240",
127
- @url="http://farm4.static.flickr.com/3250/2924549350_cbc1804258_m.jpg",
127
+ @url="http://farm4.static.flickr.com/3250/2924549350_cbc1804258_m.jpg",
128
128
  @page="http://www.flickr.com/photos/the_decapitator/2924549350/sizes/s/">
129
129
 
130
130
  Grab the URL for the image itself:
131
131
 
132
132
  >> photo.small.url
133
133
  => "http://farm4.static.flickr.com/3250/2924549350_cbc1804258_m.jpg"
134
-
134
+
135
135
  Or grab the URL for its page on the Flickr site:
136
-
136
+
137
137
  >> photo.small.page
138
138
  => "http://www.flickr.com/photos/the_decapitator/2924549350/sizes/s/"
139
-
139
+
140
140
  Other sizes are available (:square, :thumbnail, :small, :medium, :large, :original) and
141
141
  are accessed in the same way:
142
-
142
+
143
143
  >> photo.original.url
144
144
  => "http://farm4.static.flickr.com/3250/2924549350_1cf67c2d47_o.jpg"
145
-
145
+
146
146
  === Tags
147
147
 
148
148
  Tags are available for users and photos. Retrieving them is easy:
149
149
 
150
150
  >> user = Fleakr.user('the decapitator')
151
151
  >> user.tags
152
- => [#<Fleakr::Objects::Tag:0x190d5fc @value="ad">,
152
+ => [#<Fleakr::Objects::Tag:0x190d5fc @value="ad">,
153
153
  #<Fleakr::Objects::Tag:0x1908a20 @value="ads">, ...
154
154
  >> user.photos.first.tags
155
155
  => [#<Fleakr::Objects::Tag:0x17b1b18 @machine_flag="0", @author_id="21775151@N06", ...
@@ -169,12 +169,12 @@ All tags have values, but for tags associated with photos there is some addition
169
169
  => false
170
170
  >> tag.author
171
171
  => #<Fleakr::Objects::User:0x1a149f0 @username="the decapitator", ... >
172
-
172
+
173
173
  Each tag can also have related tags:
174
174
 
175
175
  >> user.photos.first.tags[1].related.first.related.first.to_s
176
176
  => "face"
177
-
177
+
178
178
  You get the idea - see Fleakr::Objects::Tag for more information.
179
179
 
180
180
  === Comments
@@ -219,28 +219,41 @@ in turn, can have either collections or sets associated with them. For example:
219
219
  >> user.collections.first.collections.first.sets.first.title
220
220
  => "A Trip to Yosemite"
221
221
 
222
- Note that collections are limited to Flickr pro members. See Fleakr::Objects::Collection for more
222
+ Note that collections are limited to Flickr pro members. See Fleakr::Objects::Collection for more
223
223
  information.
224
224
 
225
+ === Accessing Resources by URL
226
+
227
+ Sometimes you want to retrieve a person, set, or photo but you only have the public Flickr URL for
228
+ that entity. Retrieval is easy:
229
+
230
+ >> Fleakr.resource_from_url('http://www.flickr.com/people/reagent/')
231
+ => #<Fleakr::Objects::User @id="25073988@N05", @username="reagent", @authentication_options={}>
232
+
233
+ This method also supports the retrieval of photos from a shortened Flickr URL:
234
+
235
+ >> Fleakr.resource_from_url('http://flic.kr/p/95Nr83')
236
+ => #<Fleakr::Objects::Photo @id="5305179788", @title="Comic Sans Sign", ... >
237
+
225
238
  === Saving Images
226
239
 
227
240
  If a photo interests you, save it down to a directory of your choosing:
228
241
 
229
242
  >> photo.original.save_to('/tmp')
230
243
  => #<File:/tmp/2924549350_1cf67c2d47_o.jpg (closed)>
231
-
232
- Similarly, you can save down entire sets. Just specify the target directory and the size
244
+
245
+ Similarly, you can save down entire sets. Just specify the target directory and the size
233
246
  of the images you're interested in:
234
247
 
235
248
  >> user.sets.first.save_to('/tmp', :square)
236
249
  => [#<Fleakr::Objects::Photo:0x1187a1c @secret="715587b2cb" ...
237
-
250
+
238
251
  This creates a subdirectory within the target directory based on the set's name and preserves
239
252
  the original order of the photos:
240
-
253
+
241
254
  >> Dir["/tmp/#{user.sets.first.title}/*.jpg"].map
242
- => ["/tmp/The Decapitator/01_2117922283_715587b2cb_s.jpg",
243
- "/tmp/The Decapitator/02_2125604584_9c09348fd6_s.jpg",
255
+ => ["/tmp/The Decapitator/01_2117922283_715587b2cb_s.jpg",
256
+ "/tmp/The Decapitator/02_2125604584_9c09348fd6_s.jpg",
244
257
  "/tmp/The Decapitator/03_2118696542_8af5763bde_s.jpg", ... ]
245
258
 
246
259
  === Searching
@@ -248,7 +261,7 @@ the original order of the photos:
248
261
  If you would prefer to just search photos, you can do that with search text:
249
262
 
250
263
  >> photos = Fleakr.search('ponies!!')
251
- => [#<Fleakr::Objects::Photo:0x11f4e64 @title="hiroshima atomic garden", @id="3078234390">,
264
+ => [#<Fleakr::Objects::Photo:0x11f4e64 @title="hiroshima atomic garden", @id="3078234390">,
252
265
  #<Fleakr::Objects::Photo:0x11f4928 @title="PONYLOV", @id="3077360853">, ...
253
266
  >> photos.first.title
254
267
  => "hiroshima atomic garden"
@@ -265,21 +278,38 @@ Searches can also be scoped to other entities in the system (namely Users and Gr
265
278
 
266
279
  >> user.groups.first.search('awesome')
267
280
  => [#<Fleakr::Objects::Photo:0x18cb4cc @server_id="2012", @id="2181921273",
268
- @farm_id="3", @title="", @secret="634eda7521">, ...
281
+ @farm_id="3", @title="", @secret="634eda7521">, ...
269
282
  >> user.search('serpent')
270
283
  => [#<Fleakr::Objects::Photo:0x18a6960 @server_id="41", @id="81370156",
271
284
  @farm_id="1", @title="Clear and Serpent Danger", @secret="013091582a">]
272
285
 
286
+ === Exif Data
287
+
288
+ Exif metadata can be retrieved for a photo:
289
+
290
+ >> photo = Fleakr::Objects::Photo.find_by_id('4507120023')
291
+ >> photo.metadata.keys
292
+ => ["ImageSize", "Optical Zoom Mode", "RedBalance", "Y-Resolution", ... ]
293
+ >> photo.metadata['ImageSize']
294
+ => "3264x2448"
295
+
296
+ You can iterate over the available elements and grab additional information:
297
+
298
+ >> photo.metadata.map {|k, e| "#{k} => '#{e.clean}'" }
299
+ => ["Exposure => '0.003 sec (1/400)'", "Y-Resolution => '180 dpi'", ... ]
300
+
301
+ See the documentation for Fleakr::Objects::Metadata for information on what's available.
302
+
273
303
  === Uploading Files
274
304
 
275
- Before you can upload files, you need to be able to make authenticated calls to the Flickr
305
+ Before you can upload files, you need to be able to make authenticated calls to the Flickr
276
306
  API. Skip to the next section (Authenticated Calls) for details on how to make this work.
277
307
 
278
308
  Uploading single files is simple:
279
309
 
280
310
  >> Fleakr.upload('/path/to/image.jpg')
281
311
  => [#<Fleakr::Objects::Photo:0x217fb54 @updated="1236133594", @server_id="3266", ...>]
282
-
312
+
283
313
  Notice that the newly-uploaded image is returned. You can further inspect / modify this as
284
314
  necessary. The real magic is in uploading multiple files - the upload method takes a file
285
315
  glob:
@@ -291,7 +321,7 @@ glob:
291
321
 
292
322
  You can also set options on the file(s) that you're uploading:
293
323
 
294
- >> Fleakr.upload('/path/to/party/images/*.jpg', :viewable_by => :everyone,
324
+ >> Fleakr.upload('/path/to/party/images/*.jpg', :viewable_by => :everyone,
295
325
  :title => 'Party Pics')
296
326
 
297
327
  The full list of options can be found in the Fleakr::Objects::Photo documentation.
@@ -299,8 +329,8 @@ The full list of options can be found in the Fleakr::Objects::Photo documentatio
299
329
  === Authenticated Calls
300
330
 
301
331
  While read-only access to the API gets you quite a bit of data, you'll need to generate an
302
- authentication token if you want access to the more powerful features (like uploading your
303
- own photos).
332
+ authentication token if you want access to the more powerful features (like uploading your
333
+ own photos).
304
334
 
305
335
  Depending on how you intend to use the Flickr API, there are 2 methods for performing
306
336
  authenticated calls.
@@ -315,22 +345,22 @@ list of keys on the Flickr site, click on the 'Edit key details' link and ensure
315
345
  1. The value for 'Mobile Permissions' is set to either 'write' or 'delete'
316
346
 
317
347
  Once this is set, you'll see your Authentication URL on the key details page (it will look
318
- something like http://www.flickr.com/auth-534525246245). Paste this URL into your browser and
348
+ something like http://www.flickr.com/auth-534525246245). Paste this URL into your browser and
319
349
  confirm access to get your mini-token. Now you're ready to configure your authentication token:
320
350
 
321
351
  Fleakr.api_key = 'ABC123'
322
352
  Fleakr.shared_secret = 'sekrit' # Available with your key details on the Flickr site
323
-
353
+
324
354
  token = Fleakr.token_from_mini_token('294-585-410')
325
355
  Fleakr.auth_token = token.value
326
-
356
+
327
357
  Fleakr.upload('/path/to/my/photo.jpg')
328
358
 
329
359
  Once you use the mini-token once it is no longer available. To use the generated auth_token
330
360
  for future requests, you'll need to make sure that you set the value permanently:
331
361
 
332
362
  Fleakr.auth_token = '72157622657341094-41241e527f325abb'
333
-
363
+
334
364
  === Multiple Users
335
365
 
336
366
  If you need to have your application access other users photos on their behalf, you'll want to
@@ -340,31 +370,31 @@ use the Web authentication method. Edit your key details and make sure that:
340
370
  1. The value for 'Authentication Type' is set to 'Web Application'
341
371
  1. You configure your callback URL to point to something valid and accessible
342
372
 
343
- Make sure that your key and secret are set as above. You can then begin the process by requesting
344
- that the user authorize access to his Flickr account by redirecting to an authorization URL. I'm
373
+ Make sure that your key and secret are set as above. You can then begin the process by requesting
374
+ that the user authorize access to his Flickr account by redirecting to an authorization URL. I'm
345
375
  assuming Rails conventions here, but this should work with any Ruby web framework:
346
376
 
347
377
  redirect_to Fleakr.authorization_url
348
-
378
+
349
379
  By default, we request read permission for access. This doesn't really do much more than what the
350
380
  public API allows, so you can request different permissions when asking for authorization:
351
381
 
352
382
  # The values :read, :write, and :delete are supported
353
383
  redirect_to Fleakr.authorization_url(:delete)
354
384
 
355
- One the user authorizes your application, he will be redirected back to your callback URL with a
385
+ One the user authorizes your application, he will be redirected back to your callback URL with a
356
386
  <tt>frob</tt> parameter as part of the query string. You'll need to exchange this for a token:
357
387
 
358
388
  token = Fleakr.token_from_frob(params[:frob])
359
-
360
- The actual authentication token is available by calling <tt>token.value</tt> in the above
389
+
390
+ The actual authentication token is available by calling <tt>token.value</tt> in the above
361
391
  example. You'll want to store this value somewhere to make future API calls on behalf of this
362
- user. To make that process easier, there is a method that you can use that will allow you to
392
+ user. To make that process easier, there is a method that you can use that will allow you to
363
393
  automatically scope your requests to the authenticated user:
364
394
 
365
395
  user = Fleakr.user_for_token('72157622657341094-41241e527f325abb')
366
-
367
- From there, you can make any of the usual calls available with the API. See
396
+
397
+ From there, you can make any of the usual calls available with the API. See
368
398
  Fleakr::Objects::User for more information.
369
399
 
370
400
  === What Went Wrong?
@@ -374,27 +404,27 @@ what's really going on when you run into unexpected behavior. To make things ea
374
404
  have Fleakr log all of the API traffic. Here's how:
375
405
 
376
406
  Fleakr.logger = Logger.new('/tmp/fleakr.log')
377
-
378
- Now any calls to the API will log both their request and response data to that file. But be
407
+
408
+ Now any calls to the API will log both their request and response data to that file. But be
379
409
  warned, this can be pretty verbose by default (especially if you're doing file uploads). To see
380
410
  just the requests you need to tune the log level:
381
411
 
382
412
  logger = Logger.new('/tmp/fleakr.log')
383
413
  logger.level = Logger::INFO
384
-
414
+
385
415
  Fleakr.logger = logger
386
-
416
+
387
417
  Even if something doesn't go wrong, this is a good way to get a sense for when you're making
388
418
  API requests.
389
419
 
390
420
  == Contributing
391
421
 
392
- If there is a feature that you would like to contribute, I gladly accept pull requests. There
422
+ If there is a feature that you would like to contribute, I gladly accept pull requests. There
393
423
  are a few things that make my life easier when integrating your changes:
394
424
 
395
425
  * Verify that all tests are passing (run `rake` from the project root)
396
426
  * Keep your commits small, focused, and tested - this allows me to apply changes cleanly
397
- * Leave the Rakefile and version information intact - if you really want to make changes,
427
+ * Leave the Rakefile and version information intact - if you really want to make changes,
398
428
  please do so in a separate commit.
399
429
 
400
430
  Once your changes are applied, I will add you to the list of contributors.
@@ -404,6 +434,7 @@ Once your changes are applied, I will add you to the list of contributors.
404
434
  While Fleakr started as a labor of love for me, I'm glad that others have been interested
405
435
  in this project enough to contribute their ideas and code:
406
436
 
437
+ * {Gordon Anderson}[http://github.com/gordonbanderson]
407
438
  * {Mark Dickson}[http://github.com/ideaoforder]
408
439
  * {John Guenin}[http://github.com/johng]
409
440
  * {Thomas Olausson}[http://github.com/latompa]
@@ -426,7 +457,7 @@ Thanks!
426
457
  * Implement save-able search results (e.g. Fleakr.search('ponies').save_to('/path', :medium))
427
458
  * Implement deeper associations for core elements (e.g. tags / etc..)
428
459
  * Implement write methods for photos & photosets
429
- * Implement flickr.places.* portion of API
460
+ * Implement flickr.places.* portion of API
430
461
 
431
462
  == License
432
463
 
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  require 'rake/testtask'
4
+ require 'hanna/rdoctask'
4
5
 
5
- require 'lib/fleakr/version'
6
+ require File.expand_path('../lib/fleakr/version', __FILE__)
6
7
 
7
8
  spec = Gem::Specification.new do |s|
8
9
  s.name = 'fleakr'
@@ -13,11 +14,10 @@ spec = Gem::Specification.new do |s|
13
14
  s.summary = "A small, yet powerful, gem to interface with Flickr photostreams"
14
15
  s.author = 'Patrick Reagan'
15
16
  s.email = 'reaganpr@gmail.com'
16
- s.homepage = 'http://sneaq.net'
17
+ s.homepage = 'http://fleakr.org'
17
18
  s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
18
-
19
+
19
20
  s.add_dependency('hpricot', '>= 0.6.164')
20
- s.add_dependency('activesupport', '>= 2.0')
21
21
  s.add_dependency('loggable', '>= 0.2.0')
22
22
  end
23
23
 
@@ -25,6 +25,23 @@ Rake::GemPackageTask.new(spec) do |pkg|
25
25
  pkg.gem_spec = spec
26
26
  end
27
27
 
28
+ Rake::RDocTask.new(:doc) do |doc|
29
+ doc.rdoc_files.include('README.rdoc').
30
+ include('lib/**/*.rb').
31
+ exclude('lib/fleakr/version.rb')
32
+
33
+ doc.main = "README.rdoc" # page to start on
34
+ doc.title = "Fleakr #{Fleakr::Version} Documentation"
35
+
36
+ doc.rdoc_dir = "doc/#{Fleakr::Version}"
37
+ doc.options << '--quiet'
38
+ end
39
+
40
+ desc 'Install this Gem'
41
+ task :install => :gem do
42
+ sh "gem install pkg/#{spec.full_name}.gem"
43
+ end
44
+
28
45
  Rake::TestTask.new do |t|
29
46
  t.libs << 'test'
30
47
  t.test_files = FileList["test/**/*_test.rb"]
@@ -34,21 +51,23 @@ end
34
51
  begin
35
52
  require 'rcov/rcovtask'
36
53
 
54
+ desc 'Run tests with code coverage statistics'
37
55
  Rcov::RcovTask.new(:coverage) do |t|
38
56
  t.libs = ['test']
39
57
  t.test_files = FileList["test/**/*_test.rb"]
40
58
  t.verbose = true
41
- t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
59
+ t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby', "-x #{ENV['HOME']}/.rvm"]
42
60
  end
43
-
61
+
44
62
  task :default => :coverage
45
-
63
+
46
64
  rescue LoadError
47
- warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
65
+ desc 'Run tests with code coverage statistics'
66
+ task(:coverage) { $stderr.puts 'Run `gem install rcov` to get coverage stats' }
48
67
  task :default => :test
49
68
  end
50
69
 
51
- desc 'Generate the gemspec to serve this Gem from Github'
70
+ desc 'Generate the gemspec for this Gem'
52
71
  task :gemspec do
53
72
  file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
54
73
  File.open(file, 'w') {|f| f << spec.to_ruby }
@@ -3,25 +3,10 @@ $:.unshift(File.dirname(__FILE__))
3
3
  require 'uri'
4
4
  require 'cgi'
5
5
  require 'net/http'
6
+ require 'time'
6
7
  require 'hpricot'
7
8
  require 'forwardable'
8
9
 
9
- # Require only what we need from ActiveSupport
10
- require 'active_support/core_ext/array'
11
- require 'active_support/core_ext/module'
12
-
13
- begin
14
- # ActiveSupport < 2.3.5
15
- require 'active_support/core_ext/blank'
16
- rescue NameError
17
- # ActiveSupport >= 2.3.5 will raise a NameError exception
18
- require 'active_support/core_ext/object/blank'
19
- end
20
-
21
- require 'active_support/core_ext/time'
22
- require 'active_support/inflector'
23
- require 'active_support/core_ext/string'
24
-
25
10
  require 'digest/md5'
26
11
  require 'fileutils'
27
12
  require 'loggable'
@@ -36,7 +21,7 @@ require 'fleakr/objects'
36
21
  # == Quick Start
37
22
  #
38
23
  # Getting started is easy, just make sure you have a valid API key from Flickr and you can
39
- # then start making any non-authenticated request to pull back data for yours and others'
24
+ # then start making any non-authenticated request to pull back data for yours and others'
40
25
  # photostreams, sets, contacts, groups, etc...
41
26
  #
42
27
  # For now, all activity originates from a single user which you can find by username or
@@ -57,10 +42,10 @@ require 'fleakr/objects'
57
42
  # user.groups
58
43
  #
59
44
  # To see what other associations and attributes are available, see the Fleakr::Objects::User class
60
- #
45
+ #
61
46
  # == Authentication
62
47
  #
63
- # If you want to do something more than just retrieve public photos (like upload your own),
48
+ # If you want to do something more than just retrieve public photos (like upload your own),
64
49
  # you'll need to generate an authentication token to use across requests and sessions.
65
50
  #
66
51
  # Assuming you've already applied for a key, go back and make sure you have the right settings
@@ -71,7 +56,7 @@ require 'fleakr/objects'
71
56
  # 1. The value for 'Mobile Permissions' is set to either 'write' or 'delete'
72
57
  #
73
58
  # Once this is set, you'll see your Authentication URL on the key details page (it will look
74
- # something like http://www.flickr.com/auth-534525246245). Paste this URL into your browser and
59
+ # something like http://www.flickr.com/auth-534525246245). Paste this URL into your browser and
75
60
  # confirm access to get your mini-token. Now you're ready to make authenticated requests:
76
61
  #
77
62
  # require 'rubygems'
@@ -83,7 +68,7 @@ require 'fleakr/objects'
83
68
  #
84
69
  # Fleakr.upload('/path/to/my/photo.jpg')
85
70
  # Fleakr.token.value # => "34132412341235-12341234ef34"
86
- #
71
+ #
87
72
  # Once you use the mini-token once, it is no longer available. To use the generated auth_token
88
73
  # for future requests, just set Fleakr.auth_token to the generated value.
89
74
  #
@@ -92,7 +77,9 @@ module Fleakr
92
77
  # Generic catch-all exception for any API errors
93
78
  class ApiError < StandardError; end
94
79
 
95
- mattr_accessor :api_key, :shared_secret, :auth_token
80
+ class << self
81
+ attr_accessor :api_key, :shared_secret, :auth_token
82
+ end
96
83
 
97
84
  # Find a user based on some unique user data. This method will try to find
98
85
  # the user based on several methods, starting with username and falling back to email and URL
@@ -103,6 +90,8 @@ module Fleakr
103
90
  # Fleakr.user('user@host.com')
104
91
  # Fleakr.user('http://www.flickr.com/photos/the_decapitator/')
105
92
  #
93
+
94
+ # TODO: Use User.find_by_identifier for some of this
106
95
  def self.user(user_data, options = {})
107
96
  user = nil
108
97
  [:username, :email, :url].each do |attribute|
@@ -112,7 +101,7 @@ module Fleakr
112
101
  end
113
102
  user
114
103
  end
115
-
104
+
116
105
  # Search all photos on the Flickr site. By default, this searches based on text, but you can pass
117
106
  # different search parameters (passed as hash keys):
118
107
  #
@@ -127,7 +116,7 @@ module Fleakr
127
116
  params = {:text => params} unless params.is_a?(Hash)
128
117
  Objects::Search.new(params).results
129
118
  end
130
-
119
+
131
120
  # Upload one or more files to your Flickr account (requires authentication). Simply provide
132
121
  # a filename or a pattern to upload one or more files:
133
122
  #
@@ -135,13 +124,13 @@ module Fleakr
135
124
  # Fleakr.upload('/User/Pictures/Party/*.jpg')
136
125
  #
137
126
  # Additionally, options can be supplied as part of the upload that will apply to all files
138
- # that are matched by the pattern passed to <tt>glob</tt>. For a full list, see
127
+ # that are matched by the pattern passed to <tt>glob</tt>. For a full list, see
139
128
  # Fleakr::Objects::Photo.
140
129
  #
141
130
  def self.upload(glob, options = {})
142
131
  Dir[glob].map {|file| Fleakr::Objects::Photo.upload(file, options) }
143
132
  end
144
-
133
+
145
134
  # Get all contacts for the currently authenticated user. The provided contact type can be
146
135
  # one of the following:
147
136
  #
@@ -159,11 +148,11 @@ module Fleakr
159
148
  options = {}
160
149
  options.merge!(:filter => contact_type) unless contact_type.nil?
161
150
  options.merge!(additional_options)
162
-
151
+
163
152
  Fleakr::Objects::Contact.find_all(options)
164
153
  end
165
154
 
166
- # Generate an authorization URL to redirect users to. This defaults to
155
+ # Generate an authorization URL to redirect users to. This defaults to
167
156
  # 'read' permission, but others are available when passed to this method:
168
157
  #
169
158
  # * :read - permission to read private information (default)
@@ -181,7 +170,7 @@ module Fleakr
181
170
  def self.token_from_frob(frob)
182
171
  Fleakr::Objects::AuthenticationToken.from_frob(frob)
183
172
  end
184
-
173
+
185
174
  # Exchange a mini token for an authentication token.
186
175
  #
187
176
  def self.token_from_mini_token(mini_token)
@@ -196,10 +185,15 @@ module Fleakr
196
185
  token.user
197
186
  end
198
187
 
188
+ # Retrieve a photo, person, or set from a flickr.com URL:
189
+ #
190
+ def self.resource_from_url(url)
191
+ Fleakr::Objects::Url.new(url).resource
192
+ end
193
+
199
194
  end
200
195
 
201
196
  # Alias Fleakr methods as Flickr if possible
202
197
  if defined?(Flickr).nil?
203
198
  Flickr = Fleakr
204
- end
205
-
199
+ end