myflickr 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,13 @@
1
+ == 0.1.6 2008-01-28
2
+
3
+ * Fixed up a goof in the last release
4
+
5
+ == 0.1.5 2008-01-19
6
+
7
+ * Removed parallel map usage for listing the photos within a set
8
+ * Machine tags are now available for a set of photos
9
+ * Machine and regular variety tags are now parsed from the raw entry. We love spaces, don't we?
10
+
1
11
  == 0.1.4 2008-01-18
2
12
 
3
13
  * Added a user class for retrieval of username, realname
@@ -12,6 +12,12 @@ module Myflickr
12
12
  parse(Query.api_call('flickr.photos.search', "text=#{search_string}"))
13
13
  end
14
14
 
15
+ # Find photos by tag
16
+ # Tags should be an Array
17
+ def self.search_tags(tags=[])
18
+ tags.empty? ? [] : parse(Query.api_call('flickr.photos.search', "tags=#{tags.join(',')}"))
19
+ end
20
+
15
21
  # Find will grab all sizes of images, process the tags and standard attributes of a photo
16
22
  def self.find(id)
17
23
  photo_call = Query.api_call('flickr.photos.getInfo', "photo_id=#{id}")
@@ -21,8 +27,8 @@ module Myflickr
21
27
  photo.taken = Time.parse(photo_call.at(:dates)['taken'])
22
28
 
23
29
  # Set tags for photo
24
- photo.tags = (photo_call/"tag[@machine_tag=0]").map{|tag| Tag.new tag.inner_text }
25
- photo.machine_tags = (photo_call/"tag[@machine_tag=1]").map{|tag| MachineTag.from_s tag.inner_text }
30
+ photo.tags = (photo_call/"tag[@machine_tag=0]").map{|tag| Tag.new tag['raw'] }
31
+ photo.machine_tags = (photo_call/"tag[@machine_tag=1]").map{|tag| MachineTag.from_s tag['raw'] }
26
32
 
27
33
  return photo
28
34
  end
@@ -30,7 +36,7 @@ module Myflickr
30
36
  # Get the photo sizes for the photo in an array
31
37
  def sizes
32
38
  hash = {}
33
- (Query.api_call('flickr.photos.getSizes', "photo_id=#{id}")/:size).parallel_each(MAX_THREADS) do |size|
39
+ (Query.api_call('flickr.photos.getSizes', "photo_id=#{id}")/:size).each do |size|
34
40
  hash[size['label'].downcase.to_sym] = Size.new(*%w(width height source url).map{|a| size[a]})
35
41
  end
36
42
  hash
@@ -40,7 +46,7 @@ module Myflickr
40
46
  # Parse applies Hpricot to the photos and maps them to a Photo class instance
41
47
  def self.parse collection
42
48
  photos = (collection/:photo)
43
- photos.empty? ? [] : photos.parallel_map(MAX_THREADS) do |photo|
49
+ photos.empty? ? [] : photos.map do |photo|
44
50
  self.find(photo[:id])
45
51
  end
46
52
  end
@@ -15,12 +15,15 @@ module Myflickr
15
15
  # > photosets.getPhotos (1 call)
16
16
  # > Photo.find ID (n calls)
17
17
  def photos
18
- (Query.api_call('flickr.photosets.getPhotos', "photoset_id=#{id}")/:photo).parallel_map(MAX_THREADS) do |photo|
18
+ (Query.api_call('flickr.photosets.getPhotos', "photoset_id=#{id}")/:photo).map do |photo|
19
19
  Photo.find photo[:id]
20
20
  end
21
21
  end
22
22
 
23
23
  # Return a list of tags for the set (This is rough as guts as far as queries go)
24
+ # Queries:
25
+ # > photosets.getPhotos (1 call)
26
+ # > Photo.find ID (n calls)
24
27
  def tags
25
28
  tags = []
26
29
  photos.each do |photo|
@@ -31,10 +34,34 @@ module Myflickr
31
34
  tags.uniq
32
35
  end
33
36
 
37
+ # Return a list of machine_tags for the set (This is rough as guts as far as queries go)
38
+ # Queries:
39
+ # > photosets.getPhotos (1 call)
40
+ # > Photo.find ID (n calls)
41
+ def machine_tags
42
+ tags = []
43
+ photos.each do |photo|
44
+ photo.machine_tags.each do |tag|
45
+ tags << tag
46
+ end
47
+ end
48
+ tags.uniq
49
+ end
50
+
51
+ # Search for photos that may tags that the current set collectivly owns from its photos' tags.
52
+ # Then search for those photos within sets, return an array of sets or an empty array
53
+ def similar
54
+ sets = []
55
+ Set.list.each do |set|
56
+ sets << set unless (self.tags & set.tags).empty? or set == self
57
+ end
58
+ sets.uniq
59
+ end
60
+
34
61
  private
35
62
  def self.parse(collection)
36
63
  photosets = (collection/:photoset)
37
- photosets.empty? ? [] : photosets.parallel_map(MAX_THREADS) do |set|
64
+ photosets.empty? ? [] : photosets.map do |set|
38
65
  Set.new(set[:id], set[:photos], (set/:title).inner_text, (set/:description).inner_text)
39
66
  end
40
67
  end
@@ -2,7 +2,7 @@ module Myflickr
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -63,4 +63,10 @@ describe "Searching" do
63
63
  photo = Photo.find "252091410"
64
64
  photo.should be_an_instance_of(Photo)
65
65
  end
66
+
67
+ it "should be able to find photos by tags only" do
68
+ search = Photo.search_tags(["street"])
69
+ search.should be_an_instance_of(Array)
70
+ search.first.should be_an_instance_of(Photo)
71
+ end
66
72
  end
@@ -45,9 +45,21 @@ describe Set, "class" do
45
45
  tags.first.should be_an_instance_of(String)
46
46
  end
47
47
 
48
+ it "should collect machine_tags for the photos in the set" do
49
+ myset = Set.find "72157603414539843"
50
+ tags = myset.machine_tags
51
+ tags.should be_an_instance_of(Array)
52
+ tags.first.should be_an_instance_of(MachineTag)
53
+ end
54
+
48
55
  it "should collect unique tags" do
49
56
  myset = Set.find "72157603414539843"
50
57
  tags = myset.tags
51
58
  tags.uniq.should eql tags
52
59
  end
60
+
61
+ it "should know of similar sets" do
62
+ myset = Set.find "72157603414539843"
63
+ myset.similar.should be_an_instance_of(Array)
64
+ end
53
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myflickr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-19 00:00:00 +11:00
12
+ date: 2008-01-28 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency