kueda-flickraw 0.5.1

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,147 @@
1
+ require "rdoc/parsers/parserfactory"
2
+ require "rdoc/parsers/parse_rb"
3
+
4
+ FLICKR_API_URL='http://www.flickr.com/services/api'
5
+
6
+ FakedToken = Struct.new :text
7
+
8
+ module RDoc
9
+ class FlickrawParser < RubyParser
10
+ extend ParserFactory
11
+ parse_files_matching(/flickraw\.rb$/)
12
+
13
+ def scan
14
+ super
15
+
16
+ fr = @top_level.find_module_named 'FlickRaw'
17
+ k = fr.add_class NormalClass, 'Flickr', 'FlickRaw::Request'
18
+ k.record_location @top_level
19
+ @stats.num_classes += 1
20
+
21
+ add_flickr_methods(FlickRaw::Flickr, k)
22
+ @top_level
23
+ end
24
+
25
+ private
26
+ def add_flickr_methods(obj, doc)
27
+ obj.constants.each { |const_name|
28
+ const = obj.const_get const_name
29
+ if const.is_a?(Class) && const < FlickRaw::Request
30
+ name = const.name.sub(/.*::/, '')
31
+ k = doc.add_class NormalClass, name, 'FlickRaw::Request'
32
+ k.record_location @top_level
33
+ @stats.num_classes += 1
34
+
35
+ m = AnyMethod.new nil, name.downcase
36
+ m.comment = "Returns a #{name} object."
37
+ m.params = ''
38
+ m.singleton = false
39
+ doc.add_method m
40
+
41
+ progress("c")
42
+ @stats.num_methods += 1
43
+
44
+ add_flickr_methods(const, k)
45
+ end
46
+ }
47
+
48
+ obj.flickr_methods.each {|name|
49
+ flickr_method = obj.request_name + '.' + name
50
+ info = flickr.reflection.getMethodInfo :method_name => flickr_method
51
+
52
+ m = AnyMethod.new nil, name
53
+ m.comment = flickr_method_comment(info)
54
+ m.params = flickr_method_args(info)
55
+ m.singleton = false
56
+
57
+ m.start_collecting_tokens
58
+ m.add_token FakedToken.new( %{
59
+ # Generated automatically from flickr api
60
+ def #{name}(*args)
61
+ @flickr.call '#{flickr_method}', *args
62
+ end
63
+ } )
64
+ doc.add_method m
65
+ progress(".")
66
+ @stats.num_methods += 1
67
+ }
68
+ end
69
+
70
+ def flickr_method_comment(info)
71
+ description = unescapeHTML(info.method.description.to_s)
72
+ # description.gsub!( /<\/?(\w+)>/ ) {|b|
73
+ # return b if ['em', 'b', 'tt'].include? $1
74
+ # return ''
75
+ # }
76
+
77
+ if info.respond_to? :arguments
78
+ args = info.arguments.select { |arg| arg.name != 'api_key' }
79
+
80
+ arguments = "<b>Arguments</b>\n"
81
+ if args.size > 0
82
+ args.each {|arg|
83
+ arguments << "[#{arg.name} "
84
+ arguments << "<em>(required)</em> " if arg.optional == '0'
85
+ arguments << "] "
86
+ arguments << "#{unescapeHTML(arg.to_s)}\n"
87
+ }
88
+ end
89
+ end
90
+
91
+ if info.respond_to? :errors
92
+ errors = "<b>Error codes</b>\n"
93
+ info.errors.each {|e|
94
+ errors << "* #{e.code}: <em>#{e.message}</em>\n\n"
95
+ errors << " #{unescapeHTML e.to_s}\n"
96
+ }
97
+ end
98
+
99
+ if info.method.respond_to? :response
100
+ response = "<b>Returns</b>\n"
101
+ raw = unescapeHTML(info.method.response.to_s)
102
+ response << raw.collect { |line| line.insert(0, ' ') }.join
103
+ else
104
+ response = ''
105
+ end
106
+
107
+ str = "{#{info.method.name}}[#{FLICKR_API_URL}/#{info.method.name}.html] request.\n\n"
108
+ str << description << "\n\n"
109
+ str << arguments << "\n\n"
110
+ str << errors << "\n\n"
111
+ str << response << "\n\n"
112
+ end
113
+
114
+ def flickr_method_args(info)
115
+ str = ''
116
+ if info.respond_to? :arguments
117
+ args = info.arguments.select { |arg| arg.name != 'api_key' }
118
+
119
+ if args.size > 0
120
+ str << '('
121
+ args.each {|arg|
122
+ str << ":#{arg.name} => '#{arg.name}'"
123
+ str << ','
124
+ }
125
+ str.chomp! ','
126
+ str << ')'
127
+ end
128
+ end
129
+ str
130
+ end
131
+
132
+ def unescapeHTML(string)
133
+ string.gsub!('\/', '/')
134
+ string.gsub(/&(.*?);/n) do
135
+ match = $1.dup
136
+ case match
137
+ when /\Aamp\z/ni then '&'
138
+ when /\Aquot\z/ni then '"'
139
+ when /\Agt\z/ni then '>'
140
+ when /\Alt\z/ni then '<'
141
+ when /\Anbsp\z/ni then ' '
142
+ else "&#{match};"
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
data/lib/flickraw.rb ADDED
@@ -0,0 +1,249 @@
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 'md5'
25
+ require 'cgi'
26
+
27
+ require 'rubygems'
28
+ require 'active_support'
29
+
30
+ module FlickRaw
31
+ VERSION='0.5.1'
32
+
33
+ FLICKR_HOST='api.flickr.com'.freeze
34
+
35
+ # Path of flickr REST API
36
+ REST_PATH='/services/rest/?'.freeze
37
+
38
+ # Path of flickr auth page
39
+ AUTH_PATH='/services/auth/?'.freeze
40
+
41
+ # Path of flickr upload
42
+ UPLOAD_PATH='/services/upload/'.freeze
43
+
44
+ @api_key = '7b124df89b638e545e3165293883ef62'
45
+
46
+ module SimpleOStruct # :nodoc:
47
+ def __attr_define(k,v)
48
+ instance_variable_set "@#{k}", v
49
+ meta = class << self; self; end
50
+ meta.class_eval { attr_reader k.to_s }
51
+ end
52
+ end
53
+
54
+ class Response # :nodoc:
55
+ include SimpleOStruct
56
+ def initialize(h)
57
+ h.each {|k, v| __attr_define k, Response.structify(v, k) }
58
+ end
59
+
60
+ def self.structify(obj, name = '')
61
+ if obj.is_a? Hash
62
+ if name =~ /s$/ and obj[$`].is_a? Array
63
+ list = structify obj.delete($`)
64
+ list.extend SimpleOStruct
65
+ list.instance_eval { obj.each {|kv, vv| __attr_define kv, vv } }
66
+ list
67
+ elsif obj.keys == ['_content']
68
+ obj['_content'].to_s
69
+ else
70
+ Response.new obj
71
+ end
72
+ elsif obj.is_a? Array
73
+ obj.collect {|e| structify e}
74
+ else
75
+ obj
76
+ end
77
+ end
78
+
79
+ def to_s; @_content || super end
80
+ end
81
+
82
+ class FailedResponse < StandardError
83
+ attr_reader :code
84
+ alias :msg :message
85
+ def initialize(msg, code, req)
86
+ @code = code
87
+ super("'#{req}' - #{msg}")
88
+ end
89
+ end
90
+
91
+ class Request
92
+ def initialize(flickr = nil) # :nodoc:
93
+ @flickr = flickr
94
+
95
+ self.class.flickr_objects.each {|name|
96
+ klass = self.class.const_get name.capitalize
97
+ instance_variable_set "@#{name}", klass.new(@flickr)
98
+ }
99
+ end
100
+
101
+ def self.build_request(req) # :nodoc:
102
+ method_nesting = req.split '.'
103
+ raise "'#{@name}' : Method name mismatch" if method_nesting.shift != request_name.split('.').last
104
+
105
+ if method_nesting.size > 1
106
+ name = method_nesting.first
107
+ class_name = name.capitalize
108
+ if const_defined? class_name
109
+ klass = const_get( class_name)
110
+ else
111
+ klass = Class.new Request
112
+ const_set(class_name, klass)
113
+ attr_reader name
114
+ flickr_objects << name
115
+ end
116
+
117
+ klass.build_request method_nesting.join('.')
118
+ else
119
+ req = method_nesting.first
120
+ define_method(req) { |*args|
121
+ class_req = self.class.request_name
122
+ @flickr.call class_req + '.' + req, *args
123
+ }
124
+ flickr_methods << req
125
+ end
126
+ end
127
+
128
+ # List of the flickr subobjects of this object
129
+ def self.flickr_objects; @flickr_objects ||= [] end
130
+
131
+ # List of the flickr methods of this object
132
+ def self.flickr_methods; @flickr_methods ||= [] end
133
+
134
+ # Returns the prefix of the request corresponding to this class.
135
+ def self.request_name; name.downcase.gsub(/::/, '.').sub(/[^\.]+\./, '') end
136
+ end
137
+
138
+ # Root class of the flickr api hierarchy.
139
+ class Flickr < Request
140
+ def initialize # :nodoc:
141
+ super self
142
+ @token = nil
143
+ end
144
+
145
+ # This is the central method. It does the actual request to the flickr server.
146
+ #
147
+ # Raises FailedResponse if the response status is _failed_.
148
+ def call(req, args={})
149
+ path = REST_PATH + build_args(args, req).collect { |a, v| "#{a}=#{v}" }.join('&')
150
+ http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.get(path, 'User-Agent' => "Flickraw/#{VERSION}") }
151
+ parse_response(http_response, req)
152
+ end
153
+
154
+ # Use this to upload the photo in _file_.
155
+ #
156
+ # flickr.upload_photo '/path/to/the/photo', :title => 'Title', :description => 'This is the description'
157
+ #
158
+ # See http://www.flickr.com/services/api/upload.api.html for more information on the arguments.
159
+ def upload_photo(file, args={})
160
+ photo = File.open(file, 'rb') { |f| f.read }
161
+ boundary = MD5.md5(photo).to_s
162
+
163
+ header = {'Content-type' => "multipart/form-data, boundary=#{boundary} ", 'User-Agent' => "Flickraw/#{VERSION}"}
164
+ query = ''
165
+ build_args(args).each { |a, v|
166
+ query <<
167
+ "--#{boundary}\r\n" <<
168
+ "Content-Disposition: form-data; name=\"#{a}\"\r\n\r\n" <<
169
+ "#{v}\r\n"
170
+ }
171
+ query <<
172
+ "--#{boundary}\r\n" <<
173
+ "Content-Disposition: form-data; name=\"photo\"; filename=\"#{file}\"\r\n" <<
174
+ "Content-Transfer-Encoding: binary\r\n" <<
175
+ "Content-Type: image/jpeg\r\n\r\n" <<
176
+ photo <<
177
+ "\r\n" <<
178
+ "--#{boundary}--"
179
+
180
+ http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.post(UPLOAD_PATH, query, header) }
181
+ xml = http_response.body
182
+ if xml[/stat="(\w+)"/, 1] == 'fail'
183
+ msg = xml[/msg="([^"]+)"/, 1]
184
+ code = xml[/code="([^"]+)"/, 1]
185
+ raise FailedResponse.new(msg, code, 'flickr.upload')
186
+ end
187
+ Response.structify( {:stat => 'ok', :photoid => xml[/<photoid>(\w+)<\/photoid>/, 1], :ticketid => xml[/<ticketid>([^<]+)<\/ticketid>/, 1]})
188
+ end
189
+
190
+ private
191
+ def parse_response(response, req = nil)
192
+ json = ActiveSupport::JSON.decode(response.body)
193
+ raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
194
+ name, json = json.to_a.first if json.size == 1
195
+
196
+ res = Response.structify json, name
197
+ lookup_token(req, res)
198
+ res
199
+ end
200
+
201
+ def build_args(args={}, req = nil)
202
+ full_args = {:api_key => FlickRaw.api_key, :format => 'json', :nojsoncallback => 1}
203
+ full_args[:method] = req if req
204
+ full_args[:auth_token] = @token if @token
205
+ args.each {|k, v| full_args[k.to_sym] = v.to_s }
206
+ full_args[:api_sig] = FlickRaw.api_sig(full_args) if FlickRaw.shared_secret
207
+ args.each {|k, v| full_args[k.to_sym] = CGI.escape(v.to_s) } if req
208
+ full_args
209
+ end
210
+
211
+ def lookup_token(req, res)
212
+ token_reqs = ['flickr.auth.getToken', 'flickr.auth.getFullToken', 'flickr.auth.checkToken']
213
+ @token = res.token if token_reqs.include?(req) and res.respond_to?(:token)
214
+ end
215
+ end
216
+
217
+ class << self
218
+ # Your flickr API key, see http://www.flickr.com/services/api/keys for more information
219
+ attr_accessor :api_key
220
+
221
+ # The shared secret of _api_key_, see http://www.flickr.com/services/api/keys for more information
222
+ attr_accessor :shared_secret
223
+
224
+ # Returns the flickr auth URL.
225
+ def auth_url(args={})
226
+ full_args = {:api_key => FlickRaw.api_key, :perms => 'read'}
227
+ args.each {|k, v| full_args[k.to_sym] = v }
228
+ full_args[:api_sig] = api_sig(full_args) if FlickRaw.shared_secret
229
+
230
+ 'http://' + FLICKR_HOST + AUTH_PATH + full_args.collect { |a, v| "#{a}=#{v}" }.join('&')
231
+ end
232
+
233
+ # Returns the signature of hsh. This is meant to be passed in the _api_sig_ parameter.
234
+ def api_sig(hsh)
235
+ MD5.md5(FlickRaw.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join).to_s
236
+ end
237
+ end
238
+
239
+ methods = Flickr.new.call 'flickr.reflection.getMethods'
240
+ methods.each { |method| Flickr.build_request method }
241
+ end
242
+
243
+ # Use this to access the flickr API easily. You can type directly the flickr requests as they are described on the flickr website.
244
+ # require 'flickraw'
245
+ #
246
+ # recent_photos = flickr.photos.getRecent
247
+ # puts recent_photos[0].title
248
+ def flickr; $flickraw ||= FlickRaw::Flickr.new end
249
+
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.add_dependency 'json'
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,67 @@
1
+ require 'test/unit'
2
+ require 'lib/flickraw'
3
+
4
+ # utf8 hack
5
+ def u(str)
6
+ str.gsub(/\\+u([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
7
+ end
8
+
9
+ class Basic < Test::Unit::TestCase
10
+ def test_known
11
+ 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"]
12
+ found_methods = flickr.reflection.getMethods
13
+ assert_instance_of Array, found_methods
14
+ known_methods.each { |m| assert found_methods.include?(m), m}
15
+ end
16
+
17
+ def test_found
18
+ found_methods = flickr.reflection.getMethods
19
+ found_methods.each { |m|
20
+ assert_nothing_raised {
21
+ begin
22
+ eval m
23
+ rescue FlickRaw::FailedResponse
24
+ end
25
+ }
26
+ }
27
+ end
28
+
29
+ def test_photos
30
+ list = flickr.photos.getRecent :per_page => '10'
31
+ assert_instance_of Array, list
32
+ assert_equal(list.size, 10)
33
+
34
+ id = secret = info = nil
35
+ assert_nothing_raised(NoMethodError) {
36
+ id = list[0].id
37
+ secret = list[0].secret
38
+ }
39
+ assert_nothing_raised(FlickRaw::FailedResponse) {
40
+ info = flickr.photos.getInfo :photo_id => id, :secret => secret
41
+ }
42
+ assert_respond_to info, :id
43
+ assert_respond_to info, :secret
44
+ assert_respond_to info, :title
45
+ assert_respond_to info, :description
46
+ assert_respond_to info, :owner
47
+ assert_respond_to info, :dates
48
+ assert_respond_to info, :comments
49
+ assert_respond_to info, :tags
50
+ end
51
+
52
+ def test_url_escape
53
+ result_set = nil
54
+ assert_nothing_raised {
55
+ result_set = flickr.photos.search :text => "family vacation"
56
+ }
57
+ assert_operator result_set.total.to_i, :>=, 0
58
+
59
+ # Unicode tests
60
+ echo = nil
61
+ utf8_text = "Hélène François, €uro"
62
+ assert_nothing_raised {
63
+ echo = flickr.test.echo :utf8_text => utf8_text
64
+ }
65
+ assert_equal u(echo.utf8_text), utf8_text
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kueda-flickraw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Mael Clerambault
8
+ - Ken-ichi Ueda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-04-05 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ description:
27
+ email: maelclerambault@yahoo.fr
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - lib/flickraw.rb
36
+ - flickraw_rdoc.rb
37
+ - LICENSE
38
+ - README.rdoc
39
+ - rakefile
40
+ - examples/flickr_KDE.rb
41
+ - examples/upload.rb
42
+ - examples/auth.rb
43
+ - examples/interestingness.rb
44
+ - test/test.rb
45
+ has_rdoc: false
46
+ homepage: http://hanklords.github.com/flickraw/
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: flickraw
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
71
+ test_files: []
72
+