mwilliams-flickraw 0.6

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Hank Lords <hanklords@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = Flickraw
2
+
3
+ Flickraw is a library to access flickr[http://flickr.com] api in a simple way.
4
+ It maps exactly the methods described in {the official api documentation}[http://www.flickr.com/services/api].
5
+ It also tries to present the data returned in a simple and intuitive way.
6
+ The methods are fetched from flickr when loading the library by using introspection capabilities. So it is always up-to-date with regards to new methods added by flickr.
7
+
8
+ The rubyforge project : http://rubyforge.org/projects/flickraw
9
+
10
+ The github repository: http://github.com/hanklords/flickraw/tree/master
11
+
12
+ = Installation
13
+ Type this in a console (you might need to be superuser)
14
+ gem install flickraw
15
+
16
+ You can recreate this documentation by typing this in the source directory:
17
+ rake rdoc
18
+
19
+ = Usage
20
+
21
+ require 'flickraw'
22
+
23
+ list = flickr.photos.getRecent
24
+
25
+ id = list[0].id
26
+ secret = list[0].secret
27
+ info = flickr.photos.getInfo :photo_id => id, :secret => secret
28
+
29
+ info.title # => "PICT986"
30
+ info.dates.taken # => "2006-07-06 15:16:18"
31
+
32
+
33
+ sizes = flickr.photos.getSizes :photo_id => id
34
+
35
+ original = sizes.find {|s| s.label == 'Original' }
36
+ original.width # => "800"
37
+
38
+ See the _examples_ directory to find more examples.
39
+
40
+ = Notes
41
+ If you want to use the api authenticated with several user at the same time, you must pass the authentication token explicitely each time.
42
+ This is because it is keeping the authentication token internally.
43
+ As an alternative, you can create new Flickr objects besides Object.flickr which is created for you. Use Flickr.new to this effect.
44
+
data/examples/auth.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'flickraw'
2
+
3
+ # This is how to authenticate on flickr website.
4
+ # You need an API key for that, see http://www.flickr.com/services/api/keys/
5
+ API_KEY=''
6
+ SHARED_SECRET=''
7
+
8
+ FlickRaw.api_key=API_KEY
9
+ FlickRaw.shared_secret=SHARED_SECRET
10
+
11
+ frob = flickr.auth.getFrob
12
+ auth_url = FlickRaw.auth_url :frob => frob, :perms => 'read'
13
+
14
+ puts "Open this url in your process to complete the authication process : #{auth_url}"
15
+ puts "Press Enter when you are finished."
16
+ STDIN.getc
17
+
18
+ begin
19
+ flickr.auth.getToken :frob => frob
20
+ login = flickr.test.login
21
+ puts "You are now authenticated as #{login.username}"
22
+ rescue FlickRaw::FailedResponse => e
23
+ puts "Authentication failed : #{e.msg}"
24
+ end
25
+
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby
2
+ # Chooses a photo from the current interesting
3
+ # photo and set it as the background image on
4
+ # your first KDE desktop.
5
+
6
+ require 'flickraw'
7
+ require 'open-uri'
8
+ DESKTOP=1
9
+
10
+ list = flickr.interestingness.getList
11
+ photo = list[rand(100)]
12
+ sizes = flickr.photos.getSizes(:photo_id => photo.id)
13
+ original = sizes.find {|s| s.label == 'Original' }
14
+
15
+ url = original.source
16
+ file = File.basename url
17
+ full_path = File.join(Dir.pwd, file)
18
+
19
+ open url do |remote|
20
+ open(file, 'wb') { |local| local << remote.read }
21
+ end
22
+
23
+ `dcop kdesktop KBackgroundIface setWallpaper #{DESKTOP} #{full_path} 7`
@@ -0,0 +1,6 @@
1
+ require 'flickraw'
2
+
3
+ # Get the list of the 20 most recent 'interesting photos'
4
+
5
+ list = flickr.interestingness.getList :per_page => 20
6
+ list.each {|photo| puts "'#{photo.title}' id=#{photo.id} secret=#{photo.secret}" }
@@ -0,0 +1,22 @@
1
+ require 'flickraw'
2
+
3
+ # This is how to upload photos on flickr.
4
+ # You need to be authentified to do that.
5
+ API_KEY=''
6
+ SHARED_SECRET=''
7
+ PHOTO_PATH='photo.jpg'
8
+
9
+ FlickRaw.api_key=API_KEY
10
+ FlickRaw.shared_secret=SHARED_SECRET
11
+
12
+ frob = flickr.auth.getFrob
13
+ auth_url = FlickRaw.auth_url :frob => frob, :perms => 'write'
14
+
15
+ puts "Open this url in your process to complete the authication process : #{auth_url}"
16
+ puts "Press Enter when you are finished."
17
+ STDIN.getc
18
+
19
+ flickr.auth.getToken :frob => frob
20
+ login = flickr.test.login
21
+
22
+ flickr.upload_photo PHOTO_PATH, :title => 'Title', :description => 'This is the description'
data/flickraw_rdoc.rb ADDED
@@ -0,0 +1,129 @@
1
+ require "rdoc/parser/ruby"
2
+ require "cgi"
3
+
4
+ FLICKR_API_URL='http://www.flickr.com/services/api'
5
+
6
+ FakedToken = Struct.new :text
7
+
8
+ module RDoc
9
+ class FlickrawParser < Parser::Ruby
10
+ parse_files_matching(/flickraw\.rb$/)
11
+
12
+ def scan
13
+ super
14
+
15
+ fr = @top_level.find_module_named 'FlickRaw'
16
+ k = fr.add_class NormalClass, 'Flickr', 'FlickRaw::Request'
17
+ k.record_location @top_level
18
+ @stats.add_class 'Flickr'
19
+
20
+ add_flickr_methods(FlickRaw::Flickr, k)
21
+ @top_level
22
+ end
23
+
24
+ private
25
+ def add_flickr_methods(obj, doc)
26
+ obj.constants.each { |const_name|
27
+ const = obj.const_get const_name
28
+ if const.is_a?(Class) && const < FlickRaw::Request
29
+ name = const.name.sub(/.*::/, '')
30
+ k = doc.add_class NormalClass, name, 'FlickRaw::Request'
31
+ k.record_location @top_level
32
+ @stats.add_class name
33
+
34
+ m = AnyMethod.new nil, name.downcase
35
+ m.comment = "Returns a #{name} object."
36
+ m.params = ''
37
+ m.singleton = false
38
+ doc.add_method m
39
+ @stats.add_method m
40
+
41
+ add_flickr_methods(const, k)
42
+ end
43
+ }
44
+
45
+ obj.flickr_methods.each {|name|
46
+ flickr_method = obj.request_name + '.' + name
47
+ info = flickr.reflection.getMethodInfo :method_name => flickr_method
48
+
49
+ m = AnyMethod.new nil, name
50
+ m.comment = flickr_method_comment(info)
51
+ m.params = flickr_method_args(info)
52
+ m.singleton = false
53
+
54
+ m.start_collecting_tokens
55
+ m.add_token FakedToken.new( %{
56
+ # Generated automatically from flickr api
57
+ def #{name}(*args)
58
+ @flickr.call '#{flickr_method}', *args
59
+ end
60
+ } )
61
+ doc.add_method m
62
+ @stats.add_method m
63
+ }
64
+ end
65
+
66
+ def flickr_method_comment(info)
67
+ description = CGI.unescapeHTML(info.method.description.to_s)
68
+ # description.gsub!( /<\/?(\w+)>/ ) {|b|
69
+ # return b if ['em', 'b', 'tt'].include? $1
70
+ # return ''
71
+ # }
72
+
73
+ if info.respond_to? :arguments
74
+ args = info.arguments.select { |arg| arg.name != 'api_key' }
75
+
76
+ arguments = "<b>Arguments</b>\n"
77
+ if args.size > 0
78
+ args.each {|arg|
79
+ arguments << "[#{arg.name} "
80
+ arguments << "<em>(required)</em> " if arg.optional == '0'
81
+ arguments << "] "
82
+ arguments << "#{CGI.unescapeHTML(arg.to_s)}\n"
83
+ }
84
+ end
85
+ end
86
+
87
+ if info.respond_to? :errors
88
+ errors = "<b>Error codes</b>\n"
89
+ info.errors.each {|e|
90
+ errors << "* #{e.code}: <em>#{e.message}</em>\n\n"
91
+ errors << " #{CGI.unescapeHTML e.to_s}\n"
92
+ }
93
+ end
94
+
95
+ if info.method.respond_to? :response
96
+ response = "<b>Returns</b>\n"
97
+ raw = CGI.unescapeHTML(info.method.response.to_s)
98
+ response << raw.lines.collect { |line| line.insert(0, ' ') }.join
99
+ else
100
+ response = ''
101
+ end
102
+
103
+ str = "{#{info.method.name}}[#{FLICKR_API_URL}/#{info.method.name}.html] request.\n\n"
104
+ str << description << "\n\n"
105
+ str << arguments << "\n\n"
106
+ str << errors << "\n\n"
107
+ str << response << "\n\n"
108
+ end
109
+
110
+ def flickr_method_args(info)
111
+ str = ''
112
+ if info.respond_to? :arguments
113
+ args = info.arguments.select { |arg| arg.name != 'api_key' }
114
+
115
+ if args.size > 0
116
+ str << '('
117
+ args.each {|arg|
118
+ str << ":#{arg.name} => '#{arg.name}'"
119
+ str << ','
120
+ }
121
+ str.chomp! ','
122
+ str << ')'
123
+ end
124
+ end
125
+ str
126
+ end
127
+
128
+ end
129
+ end
data/lib/flickraw.rb ADDED
@@ -0,0 +1,247 @@
1
+ # Copyright (c) 2006 Mael Clerambault <maelclerambault@yahoo.fr>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ require 'net/http'
24
+ require 'digest/md5'
25
+ require 'json'
26
+ require 'cgi'
27
+
28
+ module FlickRaw
29
+ VERSION='0.6'
30
+
31
+ FLICKR_HOST='api.flickr.com'.freeze
32
+
33
+ # Path of flickr REST API
34
+ REST_PATH='/services/rest/?'.freeze
35
+
36
+ # Path of flickr auth page
37
+ AUTH_PATH='/services/auth/?'.freeze
38
+
39
+ # Path of flickr upload
40
+ UPLOAD_PATH='/services/upload/'.freeze
41
+
42
+ @api_key = '7b124df89b638e545e3165293883ef62'
43
+
44
+ module SimpleOStruct # :nodoc:
45
+ def __attr_define(k,v)
46
+ instance_variable_set "@#{k}", v
47
+ meta = class << self; self; end
48
+ meta.class_eval { attr_reader k.to_s }
49
+ end
50
+ end
51
+
52
+ class Response # :nodoc:
53
+ include SimpleOStruct
54
+ def initialize(h)
55
+ h.each {|k, v| __attr_define k, Response.structify(v, k) }
56
+ end
57
+
58
+ def self.structify(obj, name = '')
59
+ if obj.is_a? Hash
60
+ if name =~ /s$/ and obj[$`].is_a? Array
61
+ list = structify obj.delete($`)
62
+ list.extend SimpleOStruct
63
+ list.instance_eval { obj.each {|kv, vv| __attr_define kv, vv } }
64
+ list
65
+ elsif obj.keys == ['_content']
66
+ obj['_content'].to_s
67
+ else
68
+ Response.new obj
69
+ end
70
+ elsif obj.is_a? Array
71
+ obj.collect {|e| structify e}
72
+ else
73
+ obj
74
+ end
75
+ end
76
+
77
+ def to_s; @_content || super end
78
+ end
79
+
80
+ class FailedResponse < StandardError
81
+ attr_reader :code
82
+ alias :msg :message
83
+ def initialize(msg, code, req)
84
+ @code = code
85
+ super("'#{req}' - #{msg}")
86
+ end
87
+ end
88
+
89
+ class Request
90
+ def initialize(flickr = nil) # :nodoc:
91
+ @flickr = flickr
92
+
93
+ self.class.flickr_objects.each {|name|
94
+ klass = self.class.const_get name.capitalize
95
+ instance_variable_set "@#{name}", klass.new(@flickr)
96
+ }
97
+ end
98
+
99
+ def self.build_request(req) # :nodoc:
100
+ method_nesting = req.split '.'
101
+ raise "'#{@name}' : Method name mismatch" if method_nesting.shift != request_name.split('.').last
102
+
103
+ if method_nesting.size > 1
104
+ name = method_nesting.first
105
+ class_name = name.capitalize
106
+ if const_defined?(class_name, false)
107
+ klass = const_get(class_name)
108
+ else
109
+ klass = Class.new Request
110
+ const_set(class_name, klass)
111
+ attr_reader name
112
+ flickr_objects << name
113
+ end
114
+
115
+ klass.build_request method_nesting.join('.')
116
+ else
117
+ req = method_nesting.first
118
+ define_method(req) { |*args|
119
+ class_req = self.class.request_name
120
+ @flickr.call class_req + '.' + req, *args
121
+ }
122
+ flickr_methods << req
123
+ end
124
+ end
125
+
126
+ # List of the flickr subobjects of this object
127
+ def self.flickr_objects; @flickr_objects ||= [] end
128
+
129
+ # List of the flickr methods of this object
130
+ def self.flickr_methods; @flickr_methods ||= [] end
131
+
132
+ # Returns the prefix of the request corresponding to this class.
133
+ def self.request_name; name.downcase.gsub(/::/, '.').sub(/[^\.]+\./, '') end
134
+ end
135
+
136
+ # Root class of the flickr api hierarchy.
137
+ class Flickr < Request
138
+ def initialize # :nodoc:
139
+ super self
140
+ @token = nil
141
+ end
142
+
143
+ # This is the central method. It does the actual request to the flickr server.
144
+ #
145
+ # Raises FailedResponse if the response status is _failed_.
146
+ def call(req, args={})
147
+ path = REST_PATH + build_args(args, req).collect { |a, v| "#{a}=#{v}" }.join('&')
148
+ http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.get(path, 'User-Agent' => "Flickraw/#{VERSION}") }
149
+ parse_response(http_response, req)
150
+ end
151
+
152
+ # Use this to upload the photo in _file_.
153
+ #
154
+ # flickr.upload_photo '/path/to/the/photo', :title => 'Title', :description => 'This is the description'
155
+ #
156
+ # See http://www.flickr.com/services/api/upload.api.html for more information on the arguments.
157
+ def upload_photo(file, args={})
158
+ photo = File.open(file, 'rb') { |f| f.read }
159
+ boundary = MD5.md5(photo).to_s
160
+
161
+ header = {'Content-type' => "multipart/form-data, boundary=#{boundary} ", 'User-Agent' => "Flickraw/#{VERSION}"}
162
+ query = ''
163
+ build_args(args).each { |a, v|
164
+ query <<
165
+ "--#{boundary}\r\n" <<
166
+ "Content-Disposition: form-data; name=\"#{a}\"\r\n\r\n" <<
167
+ "#{v}\r\n"
168
+ }
169
+ query <<
170
+ "--#{boundary}\r\n" <<
171
+ "Content-Disposition: form-data; name=\"photo\"; filename=\"#{file}\"\r\n" <<
172
+ "Content-Transfer-Encoding: binary\r\n" <<
173
+ "Content-Type: image/jpeg\r\n\r\n" <<
174
+ photo <<
175
+ "\r\n" <<
176
+ "--#{boundary}--"
177
+
178
+ http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.post(UPLOAD_PATH, query, header) }
179
+ xml = http_response.body
180
+ if xml[/stat="(\w+)"/, 1] == 'fail'
181
+ msg = xml[/msg="([^"]+)"/, 1]
182
+ code = xml[/code="([^"]+)"/, 1]
183
+ raise FailedResponse.new(msg, code, 'flickr.upload')
184
+ end
185
+ Response.structify( {:stat => 'ok', :photoid => xml[/<photoid>(\w+)<\/photoid>/, 1], :ticketid => xml[/<ticketid>([^<]+)<\/ticketid>/, 1]})
186
+ end
187
+
188
+ private
189
+ def parse_response(response, req = nil)
190
+ json = JSON.load(response.body)
191
+ raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
192
+ name, json = json.to_a.first if json.size == 1
193
+
194
+ res = Response.structify json, name
195
+ lookup_token(req, res)
196
+ res
197
+ end
198
+
199
+ def build_args(args={}, req = nil)
200
+ full_args = {:api_key => FlickRaw.api_key, :format => 'json', :nojsoncallback => 1}
201
+ full_args[:method] = req if req
202
+ full_args[:auth_token] = @token if @token
203
+ args.each {|k, v| full_args[k.to_sym] = v.to_s }
204
+ full_args[:api_sig] = FlickRaw.api_sig(full_args) if FlickRaw.shared_secret
205
+ args.each {|k, v| full_args[k.to_sym] = CGI.escape(v.to_s) } if req
206
+ full_args
207
+ end
208
+
209
+ def lookup_token(req, res)
210
+ token_reqs = ['flickr.auth.getToken', 'flickr.auth.getFullToken', 'flickr.auth.checkToken']
211
+ @token = res.token if token_reqs.include?(req) and res.respond_to?(:token)
212
+ end
213
+ end
214
+
215
+ class << self
216
+ # Your flickr API key, see http://www.flickr.com/services/api/keys for more information
217
+ attr_accessor :api_key
218
+
219
+ # The shared secret of _api_key_, see http://www.flickr.com/services/api/keys for more information
220
+ attr_accessor :shared_secret
221
+
222
+ # Returns the flickr auth URL.
223
+ def auth_url(args={})
224
+ full_args = {:api_key => FlickRaw.api_key, :perms => 'read'}
225
+ args.each {|k, v| full_args[k.to_sym] = v }
226
+ full_args[:api_sig] = api_sig(full_args) if FlickRaw.shared_secret
227
+
228
+ 'http://' + FLICKR_HOST + AUTH_PATH + full_args.collect { |a, v| "#{a}=#{v}" }.join('&')
229
+ end
230
+
231
+ # Returns the signature of hsh. This is meant to be passed in the _api_sig_ parameter.
232
+ def api_sig(hsh)
233
+ MD5.md5(FlickRaw.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join).to_s
234
+ end
235
+ end
236
+
237
+ methods = Flickr.new.call 'flickr.reflection.getMethods'
238
+ methods.each { |method| Flickr.build_request method }
239
+ end
240
+
241
+ # Use this to access the flickr API easily. You can type directly the flickr requests as they are described on the flickr website.
242
+ # require 'flickraw'
243
+ #
244
+ # recent_photos = flickr.photos.getRecent
245
+ # puts recent_photos[0].title
246
+ def flickr; $flickraw ||= FlickRaw::Flickr.new end
247
+
data/rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rake/rdoctask'
2
+ require 'rake/packagetask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/testtask'
5
+
6
+ require 'lib/flickraw'
7
+ require 'flickraw_rdoc'
8
+
9
+ PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "LICENSE", "README.rdoc", "rakefile", "examples/*.rb", "test/*.rb"].to_a
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.summary = "Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api"
13
+ s.name = "flickraw"
14
+ s.author = "Mael Clerambault"
15
+ s.email = "maelclerambault@yahoo.fr"
16
+ s.homepage = "http://hanklords.github.com/flickraw/"
17
+ s.rubyforge_project = "flickraw"
18
+ s.version = FlickRaw::VERSION
19
+ s.files = PKG_FILES
20
+ s.test_files = FileList["test/*.rb"].to_a
21
+ s.required_ruby_version = '>= 1.9'
22
+ end
23
+
24
+ Rake::RDocTask.new do |rd|
25
+ rd.rdoc_files.include "README.rdoc", "lib/flickraw.rb"
26
+ rd.options << "--inline-source"
27
+ end
28
+
29
+ Rake::GemPackageTask.new spec do |p|
30
+ p.need_tar_gz = true
31
+ end
32
+
33
+ Rake::TestTask.new
34
+
35
+ task :spec do
36
+ spec_clone = spec.clone
37
+ spec_clone.test_files = nil
38
+ open("flickraw.gemspec", "w") {|g| g.puts spec_clone.to_ruby }
39
+ end
data/test/test.rb ADDED
@@ -0,0 +1,69 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test/unit'
4
+ require 'lib/flickraw'
5
+
6
+ # utf8 hack
7
+ def u(str)
8
+ str.gsub(/\\+u([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
9
+ end
10
+
11
+ class Basic < Test::Unit::TestCase
12
+ def test_known
13
+ known_methods = ["flickr.activity.userComments", "flickr.activity.userPhotos", "flickr.auth.checkToken", "flickr.auth.getFrob", "flickr.auth.getFullToken", "flickr.auth.getToken", "flickr.blogs.getList", "flickr.blogs.postPhoto", "flickr.contacts.getList", "flickr.contacts.getPublicList", "flickr.favorites.add", "flickr.favorites.getList", "flickr.favorites.getPublicList", "flickr.favorites.remove", "flickr.groups.browse", "flickr.groups.getInfo", "flickr.groups.pools.add", "flickr.groups.pools.getContext", "flickr.groups.pools.getGroups", "flickr.groups.pools.getPhotos", "flickr.groups.pools.remove", "flickr.groups.search", "flickr.interestingness.getList", "flickr.people.findByEmail", "flickr.people.findByUsername", "flickr.people.getInfo", "flickr.people.getPublicGroups", "flickr.people.getPublicPhotos", "flickr.people.getUploadStatus", "flickr.photos.addTags", "flickr.photos.comments.addComment", "flickr.photos.comments.deleteComment", "flickr.photos.comments.editComment", "flickr.photos.comments.getList", "flickr.photos.delete", "flickr.photos.geo.getLocation", "flickr.photos.geo.getPerms", "flickr.photos.geo.removeLocation", "flickr.photos.geo.setLocation", "flickr.photos.geo.setPerms", "flickr.photos.getAllContexts", "flickr.photos.getContactsPhotos", "flickr.photos.getContactsPublicPhotos", "flickr.photos.getContext", "flickr.photos.getCounts", "flickr.photos.getExif", "flickr.photos.getFavorites", "flickr.photos.getInfo", "flickr.photos.getNotInSet", "flickr.photos.getPerms", "flickr.photos.getRecent", "flickr.photos.getSizes", "flickr.photos.getUntagged", "flickr.photos.getWithGeoData", "flickr.photos.getWithoutGeoData", "flickr.photos.licenses.getInfo", "flickr.photos.licenses.setLicense", "flickr.photos.notes.add", "flickr.photos.notes.delete", "flickr.photos.notes.edit", "flickr.photos.recentlyUpdated", "flickr.photos.removeTag", "flickr.photos.search", "flickr.photos.setDates", "flickr.photos.setMeta", "flickr.photos.setPerms", "flickr.photos.setTags", "flickr.photos.transform.rotate", "flickr.photos.upload.checkTickets", "flickr.photosets.addPhoto", "flickr.photosets.comments.addComment", "flickr.photosets.comments.deleteComment", "flickr.photosets.comments.editComment", "flickr.photosets.comments.getList", "flickr.photosets.create", "flickr.photosets.delete", "flickr.photosets.editMeta", "flickr.photosets.editPhotos", "flickr.photosets.getContext", "flickr.photosets.getInfo", "flickr.photosets.getList", "flickr.photosets.getPhotos", "flickr.photosets.orderSets", "flickr.photosets.removePhoto", "flickr.reflection.getMethodInfo", "flickr.reflection.getMethods", "flickr.tags.getHotList", "flickr.tags.getListPhoto", "flickr.tags.getListUser", "flickr.tags.getListUserPopular", "flickr.tags.getListUserRaw", "flickr.tags.getRelated", "flickr.test.echo", "flickr.test.login", "flickr.test.null", "flickr.urls.getGroup", "flickr.urls.getUserPhotos", "flickr.urls.getUserProfile", "flickr.urls.lookupGroup", "flickr.urls.lookupUser"]
14
+ found_methods = flickr.reflection.getMethods
15
+ assert_instance_of Array, found_methods
16
+ known_methods.each { |m| assert found_methods.include?(m), m}
17
+ end
18
+
19
+ def test_found
20
+ found_methods = flickr.reflection.getMethods
21
+ found_methods.each { |m|
22
+ assert_nothing_raised {
23
+ begin
24
+ eval m
25
+ rescue FlickRaw::FailedResponse
26
+ end
27
+ }
28
+ }
29
+ end
30
+
31
+ def test_photos
32
+ list = flickr.photos.getRecent :per_page => '10'
33
+ assert_instance_of Array, list
34
+ assert_equal(list.size, 10)
35
+
36
+ id = secret = info = nil
37
+ assert_nothing_raised(NoMethodError) {
38
+ id = list[0].id
39
+ secret = list[0].secret
40
+ }
41
+ assert_nothing_raised(FlickRaw::FailedResponse) {
42
+ info = flickr.photos.getInfo :photo_id => id, :secret => secret
43
+ }
44
+ assert_respond_to info, :id
45
+ assert_respond_to info, :secret
46
+ assert_respond_to info, :title
47
+ assert_respond_to info, :description
48
+ assert_respond_to info, :owner
49
+ assert_respond_to info, :dates
50
+ assert_respond_to info, :comments
51
+ assert_respond_to info, :tags
52
+ end
53
+
54
+ def test_url_escape
55
+ result_set = nil
56
+ assert_nothing_raised {
57
+ result_set = flickr.photos.search :text => "family vacation"
58
+ }
59
+ assert_operator result_set.total.to_i, :>=, 0
60
+
61
+ # Unicode tests
62
+ echo = nil
63
+ utf8_text = "Hélène François, €uro"
64
+ assert_nothing_raised {
65
+ echo = flickr.test.echo :utf8_text => utf8_text
66
+ }
67
+ assert_equal u(echo.utf8_text), utf8_text
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mwilliams-flickraw
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.6"
5
+ platform: ruby
6
+ authors:
7
+ - Mael Clerambault
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: maelclerambault@yahoo.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/flickraw.rb
35
+ - flickraw_rdoc.rb
36
+ - LICENSE
37
+ - README.rdoc
38
+ - rakefile
39
+ - examples/flickr_KDE.rb
40
+ - examples/upload.rb
41
+ - examples/auth.rb
42
+ - examples/interestingness.rb
43
+ - test/test.rb
44
+ has_rdoc: false
45
+ homepage: http://hanklords.github.com/flickraw/
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.9"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: flickraw
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
70
+ test_files: []
71
+