flickraw 0.3.1 → 0.3.2

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.
Files changed (7) hide show
  1. data/README +43 -0
  2. data/TODO +6 -0
  3. data/copying.txt +20 -0
  4. data/flickraw_rdoc.rb +1 -0
  5. data/lib/flickraw.rb +27 -23
  6. data/rakefile +3 -2
  7. metadata +5 -2
data/README ADDED
@@ -0,0 +1,43 @@
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 try to present the data returned in a simple and intuitive way.
6
+
7
+ You can read the class documentation here : FlickRaw.
8
+
9
+ The rubyforge project : http://rubyforge.org/projects/flickraw
10
+
11
+ = Installation
12
+ Type this in a console (you might need to be superuser)
13
+ gem install flickraw
14
+
15
+ You can recreate this documentation by typing this in the source directory:
16
+ rake rdoc
17
+
18
+ = Usage
19
+
20
+ require 'flickraw'
21
+
22
+ list = flickr.photos.getRecent
23
+
24
+ id = list[0].id
25
+ secret = list[0].secret
26
+ info = flickr.photos.getInfo :photo_id => id, :secret => secret
27
+
28
+ info.title # => "PICT986"
29
+ info.dates.taken # => "2006-07-06 15:16:18"
30
+
31
+
32
+ sizes = flickr.photos.getSizes :photo_id => id
33
+
34
+ original = sizes.find {|s| s.label == 'Original' }
35
+ original.width # => "800"
36
+
37
+ See the _examples_ directory to find more examples.
38
+
39
+ = Notes
40
+ If you want to use the api authenticated with several user at the same time, you must pass the authentication token explicitely each time.
41
+ This is because it is keeping the authentication token internally.
42
+ As an alternative, you can create new Flickr objects besides Object.flickr which is created for you. Use Flickr.new to this effect.
43
+
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ == General
2
+ * Add helper classes for URL support
3
+
4
+ == Documentation
5
+ * Document the object returned by the flickr method calls ( FlickRaw::Xml )
6
+ * Add more examples.
data/copying.txt 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/flickraw_rdoc.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rdoc/parsers/parserfactory"
2
2
  require "rdoc/parsers/parse_rb"
3
+ require "cgi"
3
4
 
4
5
  FLICKR_API_URL='http://www.flickr.com/services/api'
5
6
 
data/lib/flickraw.rb CHANGED
@@ -21,11 +21,11 @@
21
21
 
22
22
 
23
23
  require 'rexml/document'
24
- require 'open-uri'
24
+ require 'net/http'
25
25
  require 'md5'
26
26
 
27
27
  module FlickRaw
28
- VERSION='0.3.1'
28
+ VERSION='0.3.2'
29
29
 
30
30
  FLICKR_HOST='api.flickr.com'.freeze
31
31
 
@@ -42,6 +42,7 @@ module FlickRaw
42
42
 
43
43
  # This is a wrapper around the xml response which provides an easy interface.
44
44
  class Xml
45
+ include Enumerable
45
46
  # Returns the text content of the response
46
47
  attr_reader :to_s
47
48
 
@@ -51,36 +52,36 @@ module FlickRaw
51
52
  def initialize(xml) # :nodoc:
52
53
  @to_s = xml.texts.join(' ')
53
54
  @to_xml = xml.to_s
54
- @list = nil
55
55
 
56
56
  xml.attributes.each {|a, v| attribute a, v }
57
57
 
58
58
  if xml.name =~ /s\z/
59
59
  elements = REXML::XPath.match( xml, xml.name.sub(/s\z/, ''))
60
- unless elements.empty?
61
- @list = elements.collect { |e| Xml.new e }
62
- end
60
+ @list = elements.collect { |e| Xml.new e }
63
61
  else
64
- xml.elements.each {|e| attribute e.name, Xml.new(e) }
62
+ @list = [self]
63
+ xml.elements.each {|e|
64
+ if instance_variable_get "@#{e.name}"
65
+ send(e.name) << Xml.new(e)
66
+ else
67
+ attribute e.name, Xml.new(e)
68
+ end
69
+ }
65
70
  end
66
71
  end
67
72
 
68
- def respond_to?(m) # :nodoc:
69
- super || @list.respond_to?(m)
70
- end
73
+ def [](index); @list[index]; end
74
+ def each; @list.each { |el| yield el }; end
75
+ def length; @list.length; end
71
76
 
72
- private
73
- def method_missing(sym, *args, &block)
74
- if @list.respond_to?( sym)
75
- @list.send sym, *args, &block
76
- else
77
- super
78
- end
79
- end
77
+ protected
78
+ def << el; @list << el; end
80
79
 
80
+ private
81
81
  def attribute(sym, value)
82
+ instance_variable_set "@#{sym}", value
82
83
  meta = class << self; self; end
83
- meta.class_eval { define_method(sym) { value } }
84
+ meta.class_eval { attr_reader sym.to_s }
84
85
  end
85
86
  end
86
87
 
@@ -126,7 +127,7 @@ module FlickRaw
126
127
  klass = Class.new Request
127
128
  const_set(class_name, klass)
128
129
  attr_reader name
129
- flickr_objects << name
130
+ flickr_objects << name
130
131
  end
131
132
 
132
133
  klass.build_request method_nesting.join('.')
@@ -168,10 +169,13 @@ module FlickRaw
168
169
  #
169
170
  # Raises FailedResponse if the response status is _failed_.
170
171
  def call(req, args={})
171
- url = 'http://' + FLICKR_HOST + REST_PATH + build_args(args, req).collect { |a, v| "#{a}=#{v}" }.join('&')
172
+ path = REST_PATH + build_args(args, req).collect { |a, v| "#{a}=#{v}" }.join('&')
172
173
 
173
- res = Response.new open(url, 'User-Agent' => "Flickraw/#{VERSION}")
174
- raise FailedResponse.new( res.msg, res.code) if res.stat == 'fail'
174
+ http_response = Net::HTTP.start(FLICKR_HOST) { |http|
175
+ http.get(path, 'User-Agent' => "Flickraw/#{VERSION}")
176
+ }
177
+ res = Response.new http_response.body
178
+ raise FailedResponse.new(res.msg, res.code) if res.stat == 'fail'
175
179
  lookup_token(req, res)
176
180
  res
177
181
  end
data/rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
5
5
  require 'lib/flickraw'
6
6
  require 'flickraw_rdoc'
7
7
 
8
- PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "rakefile", "examples/*.rb"].to_a
8
+ PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "copying.txt", "README", "TODO", "rakefile", "examples/*.rb"].to_a
9
9
 
10
10
  spec = Gem::Specification.new do |s|
11
11
  s.summary = "Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api"
@@ -27,4 +27,5 @@ end
27
27
 
28
28
  Rake::GemPackageTask.new spec do |p|
29
29
  p.need_tar_gz = true
30
- end
30
+ end
31
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: flickraw
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.1
7
- date: 2006-09-02 00:00:00 +02:00
6
+ version: 0.3.2
7
+ date: 2006-10-24 00:00:00 +02:00
8
8
  summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
9
9
  require_paths:
10
10
  - lib
@@ -31,6 +31,9 @@ authors:
31
31
  files:
32
32
  - lib/flickraw.rb
33
33
  - flickraw_rdoc.rb
34
+ - copying.txt
35
+ - README
36
+ - TODO
34
37
  - rakefile
35
38
  - examples/auth.rb
36
39
  - examples/interestingness.rb