benschwarz-flickr-wrapper 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/flickr-wrapper.gemspec +3 -2
- data/lib/flickr-wrapper.rb +6 -1
- data/lib/flickr-wrapper/photoset.rb +1 -1
- data/lib/flickr-wrapper/user.rb +10 -0
- data/lib/vendor/parallel/parallel.rb +121 -0
- metadata +13 -1
data/flickr-wrapper.gemspec
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "flickr-wrapper"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.2"
|
4
4
|
s.date = "2008-05-10"
|
5
5
|
s.summary = "A grassroots wrapper for flickr"
|
6
6
|
s.email = "ben@germanforblack.com"
|
7
7
|
s.homepage = "http://github.com/benschwarz/flickr-wrapper"
|
8
8
|
s.description = "A grassroots wrapper around flickr - Strictly for convenience"
|
9
9
|
s.authors = ["Ben Schwarz"]
|
10
|
-
s.files = ["README", "flickr-wrapper.gemspec", "lib/flickr-wrapper.rb", "lib/flickr-wrapper/base.rb", "lib/flickr-wrapper/machine_tag.rb", "lib/flickr-wrapper/photo.rb", "lib/flickr-wrapper/photoset.rb", "lib/flickr-wrapper/tag.rb", "lib/flickr-wrapper/user.rb"]
|
10
|
+
s.files = ["README", "flickr-wrapper.gemspec", "lib/flickr-wrapper.rb", "lib/flickr-wrapper/base.rb", "lib/flickr-wrapper/machine_tag.rb", "lib/flickr-wrapper/photo.rb", "lib/flickr-wrapper/photoset.rb", "lib/flickr-wrapper/tag.rb", "lib/flickr-wrapper/user.rb", "lib/vendor", "lib/vendor/parallel", "lib/vendor/parallel/parallel.rb"]
|
11
11
|
s.require_path = "lib"
|
12
12
|
|
13
13
|
# Deps
|
14
14
|
s.add_dependency("flickr-rest", ">= 0.0.1")
|
15
|
+
s.add_dependency("validatable", ">= 1.6.7")
|
15
16
|
end
|
data/lib/flickr-wrapper.rb
CHANGED
@@ -4,8 +4,13 @@ require 'flickr-rest'
|
|
4
4
|
require 'time'
|
5
5
|
require 'validatable'
|
6
6
|
|
7
|
+
# Concurrency
|
8
|
+
require File.join(File.dirname(__FILE__), 'vendor', 'parallel', 'parallel.rb')
|
9
|
+
|
7
10
|
# Namespace junkie
|
8
|
-
module Flickr
|
11
|
+
module Flickr
|
12
|
+
MAX_THREADS = 5
|
13
|
+
end
|
9
14
|
|
10
15
|
# Classes
|
11
16
|
%w(base photoset photo tag machine_tag user).each {|r| require File.join(File.dirname(__FILE__), 'flickr-wrapper', r)}
|
@@ -26,7 +26,7 @@ class Flickr::PhotoSet < Flickr::Base
|
|
26
26
|
# > photosets.getPhotos (1 call)
|
27
27
|
# > Photo.find ID (n calls)
|
28
28
|
def photos
|
29
|
-
(Flickr::Query.new(user_id).execute('flickr.photosets.getPhotos', :photoset_id => id)/:photo).
|
29
|
+
(Flickr::Query.new(user_id).execute('flickr.photosets.getPhotos', :photoset_id => id)/:photo).parallel_map(Flickr::MAX_THREADS) do |photo|
|
30
30
|
Flickr::Photo.find user_id, photo[:id]
|
31
31
|
end
|
32
32
|
end
|
data/lib/flickr-wrapper/user.rb
CHANGED
@@ -14,6 +14,11 @@ class Flickr::User < Flickr::Base
|
|
14
14
|
return Flickr::User.new(result.at(:username).inner_text, result.at(:user)['nsid'])
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.find_by_username username
|
18
|
+
result = Flickr::Query.new('').execute('flickr.people.findByUsername', :username => username)
|
19
|
+
return Flickr::User.new(result.at(:username).inner_text, result.at(:user)['nsid'])
|
20
|
+
end
|
21
|
+
|
17
22
|
#
|
18
23
|
# ==== Instance methods
|
19
24
|
#
|
@@ -27,6 +32,11 @@ class Flickr::User < Flickr::Base
|
|
27
32
|
get_info.at(:location).inner_text || "Unknown"
|
28
33
|
end
|
29
34
|
|
35
|
+
# has the user shelled out for flickr-pro account?
|
36
|
+
def pro?
|
37
|
+
(get_info.at(:person)["ispro"] == "1") ? true : false
|
38
|
+
end
|
39
|
+
|
30
40
|
#
|
31
41
|
# ==== Private methods
|
32
42
|
#
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Stolen from http://rubyforge.org/projects/concurrent
|
2
|
+
|
3
|
+
#
|
4
|
+
# concurrent/parallel - data-parallel programming for Ruby
|
5
|
+
#
|
6
|
+
# Copyright (C) 2007 MenTaLguY <mental@rydia.net>
|
7
|
+
#
|
8
|
+
# This file is made available under the same terms as Ruby.
|
9
|
+
#
|
10
|
+
|
11
|
+
module Concurrent #:nodoc:
|
12
|
+
module Parallel #:nodoc:
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Enumerable #:nodoc:
|
17
|
+
def parallel_each( n, &block )
|
18
|
+
parallel_subsets( n ).map do |slice|
|
19
|
+
Thread.new { slice.each &block }
|
20
|
+
end.each do |thread|
|
21
|
+
thread.join
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def parallel_map( n, &block )
|
27
|
+
parallel_subsets( n ).map do |slice|
|
28
|
+
Thread.new { slice.map &block }
|
29
|
+
end.inject( [] ) do |a, thread|
|
30
|
+
a.push *thread.value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parallel_select( n, &block )
|
35
|
+
parallel_subsets( n ).map do |slice|
|
36
|
+
Thread.new { slice.select &block }
|
37
|
+
end.inject( [] ) do |a, results|
|
38
|
+
a.push *thread.value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def parallel_reject( n, &block )
|
43
|
+
parallel_subsets( n ).map do |slice|
|
44
|
+
Thread.new { slice.reject &block }
|
45
|
+
end.inject( [] ) do |a, thread|
|
46
|
+
a.push *thread.value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parallel_max( n )
|
51
|
+
parallel_subsets( n ).map do |slice|
|
52
|
+
Thread.new { slice.max }
|
53
|
+
end.map { |t| t.value }.max
|
54
|
+
end
|
55
|
+
|
56
|
+
def parallel_min( n )
|
57
|
+
parallel_subsets( n ).map do |slice|
|
58
|
+
Thread.new { slice.min }
|
59
|
+
end.map { |t| t.value }.min
|
60
|
+
end
|
61
|
+
|
62
|
+
def parallel_partition( n, &block )
|
63
|
+
parallel_subsets( n ).map do |slice|
|
64
|
+
Thread.new { slice.partition &block }
|
65
|
+
end.inject( [ [], [] ] ) do |acc, thread|
|
66
|
+
pair = thread.value
|
67
|
+
acc[0].push *pair[0]
|
68
|
+
acc[1].push *pair[1]
|
69
|
+
acc
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def parallel_grep( re, n, &block )
|
74
|
+
parallel_subsets( n ).map do |slice|
|
75
|
+
Thread.new { slice.grep( re, &block ) }
|
76
|
+
end.inject( [] ) do |acc, thread|
|
77
|
+
acc.push *thread.value
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def parallel_all?( n, &block )
|
82
|
+
parallel_subsets( n ).map do |slice|
|
83
|
+
Thread.new { slice.all? &block }
|
84
|
+
end.inject( true ) do |acc, thread|
|
85
|
+
acc && thread.value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parallel_any?( n, &block )
|
90
|
+
parallel_subsets( n ).map do |slice|
|
91
|
+
Thread.new { slice.any? &block }
|
92
|
+
end.inject( false ) do |acc, thread|
|
93
|
+
acc || thread.value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def parallel_include?( n, obj )
|
98
|
+
parallel_subsets( n ).map do |slice|
|
99
|
+
Thread.new { slice.include? obj }
|
100
|
+
end.inject( false ) do |acc, thread|
|
101
|
+
acc || thread.value
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def parallel_subsets( n )
|
106
|
+
to_a.parallel_subsets( n )
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class Array #:nodoc:
|
111
|
+
def parallel_subsets( n )
|
112
|
+
if n > 1
|
113
|
+
slice_size = (size.to_f / n.to_f).ceil
|
114
|
+
(0...(size.to_f / slice_size)).map do |i|
|
115
|
+
self[i*slice_size, slice_size.ceil]
|
116
|
+
end
|
117
|
+
else
|
118
|
+
[ self ]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benschwarz-flickr-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Schwarz
|
@@ -21,6 +21,15 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.0.1
|
23
23
|
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: validatable
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.6.7
|
32
|
+
version:
|
24
33
|
description: A grassroots wrapper around flickr - Strictly for convenience
|
25
34
|
email: ben@germanforblack.com
|
26
35
|
executables: []
|
@@ -39,6 +48,9 @@ files:
|
|
39
48
|
- lib/flickr-wrapper/photoset.rb
|
40
49
|
- lib/flickr-wrapper/tag.rb
|
41
50
|
- lib/flickr-wrapper/user.rb
|
51
|
+
- lib/vendor
|
52
|
+
- lib/vendor/parallel
|
53
|
+
- lib/vendor/parallel/parallel.rb
|
42
54
|
has_rdoc: false
|
43
55
|
homepage: http://github.com/benschwarz/flickr-wrapper
|
44
56
|
post_install_message:
|