fotonauts-flickr_fu 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  ## Installation
17
17
 
18
- <code>sudo gem install flickr-fu</code>
18
+ <code>sudo gem install flickr_fu</code>
19
19
 
20
20
  ## Documentation
21
21
 
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 8
4
+ :patch: 9
5
+
data/flickr_fu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fotonauts-flickr_fu}
5
- s.version = "0.3.8"
5
+ s.version = "0.3.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Wyrosdick", "Maciej Bilas", "Fotonauts"]
@@ -105,6 +105,7 @@ Gem::Specification.new do |s|
105
105
 
106
106
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
107
107
  s.add_runtime_dependency(%q<mime-types>, ["> 0.0.0"])
108
+ s.add_runtime_dependency(%q<nokogiri>, ["> 1.5.5"])
108
109
  else
109
110
  s.add_dependency(%q<mime-types>, ["> 0.0.0"])
110
111
  end
data/lib/flickr/base.rb CHANGED
@@ -81,19 +81,20 @@ module Flickr
81
81
  # * endpoint (Optional)
82
82
  # url of the api endpoint
83
83
  #
84
+ require 'nokogiri'
84
85
  def send_request(method, options = {}, http_method = :get, endpoint = REST_ENDPOINT)
85
86
  options.merge!(:api_key => @api_key, :method => method)
86
87
  sign_request(options)
87
88
 
88
89
  rsp = request_over_http(options, http_method, endpoint)
89
90
 
90
- rsp = '<rsp stat="ok"></rsp>' if rsp == ""
91
- xm = XmlMagic.new(rsp)
92
-
93
- if xm[:stat] == 'ok'
94
- xm
91
+ rsp = '<?xml version="1.0" encoding="utf-8" ?><rsp stat="ok"></rsp>' if rsp == ""
92
+ xm = Nokogiri.Slop(rsp, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS)
93
+
94
+ if xm.rsp['stat'] == 'ok'
95
+ xm.rsp
95
96
  else
96
- raise Flickr::Errors.error_for(xm.err[:code].to_i, xm.err[:msg])
97
+ Flickr::Errors.error_for(xm.rsp.err["code"].to_i, xm.rsp.err["msg"])
97
98
  end
98
99
  end
99
100
 
data/lib/flickr/errors.rb CHANGED
@@ -10,7 +10,7 @@ module Flickr
10
10
  # Currently raises only Flickr::Error
11
11
  def self.error_for(code, message)
12
12
  raise RuntimeError.new("Internal error. Flickr API error not identified or unknown error.") if (code.nil? || message.nil? || message.empty?)
13
- raise RuntimeError.new("Internal error. Unknown error.") if code.to_i == 0 # We assume that error code 0 is never returned
13
+ raise RuntimeError.new("Internal error. Unknown error: #{code.inspect}") if code.to_i == 0 # We assume that error code 0 is never returned
14
14
  e = Flickr::Error.new("#{code}: #{message}")
15
15
  e.code = code
16
16
  raise e
data/lib/flickr/person.rb CHANGED
@@ -52,29 +52,7 @@ class Flickr::People::Person
52
52
  :method => 'public_photos',
53
53
  :options => options) do |photos|
54
54
  rsp.photos.photo.each do |photo|
55
- attributes = {:id => photo[:id],
56
- :owner => photo[:owner],
57
- :secret => photo[:secret],
58
- :server => photo[:server],
59
- :farm => photo[:farm],
60
- :title => photo[:title],
61
- :is_public => photo[:ispublic],
62
- :is_friend => photo[:isfriend],
63
- :is_family => photo[:isfamily],
64
- :license_id => photo[:license].to_i,
65
- :uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
66
- :taken_at => (Time.parse(photo[:datetaken]) rescue nil),
67
- :owner_name => photo[:ownername],
68
- :icon_server => photo[:icon_server],
69
- :original_format => photo[:originalformat],
70
- :updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
71
- :geo => photo[:geo],
72
- :tags => photo[:tags],
73
- :machine_tags => photo[:machine_tags],
74
- :o_dims => photo[:o_dims],
75
- :views => photo[:views].to_i,
76
- :media => photo[:media]}
77
-
55
+ attributes = Flickr::Photos.create_attributes(photo)
78
56
  photos << Flickr::Photos::Photo.new(@flickr, attributes)
79
57
  end if rsp.photos.photo
80
58
  end
data/lib/flickr/photo.rb CHANGED
@@ -1,8 +1,37 @@
1
1
  # wrapping class to hold an flickr photo
2
2
  class Flickr::Photos::Photo
3
- attr_accessor :id, :owner, :secret, :server, :farm, :title, :is_public, :is_friend, :is_family # standard attributes
4
- attr_accessor :license_id, :uploaded_at, :taken_at, :owner_name, :icon_server, :original_format, :updated_at, :geo, :tags, :machine_tags, :o_height, :o_width, :o_dims, :views, :media, :rotation # extra attributes
5
- attr_accessor :info_added, :description, :original_secret, :owner_username, :owner_realname, :url_photopage, :notes # info attributes
3
+ attr_accessor :id,
4
+ :owner,
5
+ :secret,
6
+ :server,
7
+ :farm,
8
+ :title,
9
+ :is_public,
10
+ :is_friend,
11
+ :is_family # standard attributes
12
+ attr_accessor :license_id,
13
+ :uploaded_at,
14
+ :taken_at,
15
+ :owner_name,
16
+ :owner_realname,
17
+ :icon_server,
18
+ :original_format,
19
+ :updated_at,
20
+ :geo,
21
+ :tags,
22
+ :machine_tags,
23
+ :o_height,
24
+ :o_width,
25
+ :o_dims,
26
+ :views,
27
+ :media,
28
+ :rotation # extra attributes
29
+ attr_accessor :info_added,
30
+ :description,
31
+ :original_secret,
32
+ :owner_username,
33
+ :url_photopage,
34
+ :notes # info attributes
6
35
  attr_accessor :comments # comment attributes
7
36
 
8
37
  # create a new instance of a flickr photo.
@@ -18,7 +47,36 @@ class Flickr::Photos::Photo
18
47
  send("#{k}=", v)
19
48
  end
20
49
  end
50
+ def self.create_attributes(photo)
51
+ {:id => photo['id'].to_i,
52
+ :secret => photo['secret'],
53
+ :server => photo['server'],
54
+ :farm => photo['farm'],
55
+ :license_id => photo['license'].to_i,
56
+ :rotation => photo['rotation'].to_i,
57
+ :uploaded_at => (Time.at(photo['dateuploaded'].to_i) rescue nil),
58
+ :owner => photo.owner['nsid'],
59
+ :owner_username => photo.owner['username'],
60
+ :owner_realname => photo.owner['realname'],
61
+ :icon_server => photo.owner['iconserver'],
62
+ :title => (photo.title.text rescue ''),
63
+ :description => photo.at_xpath("description").text, # description is a method of XML::Node, so we use at_xpath instead
64
+ :original_secret => photo['originalsecret'],
21
65
 
66
+ :is_public => photo.visibility['ispublic'].to_i,
67
+ :is_friend => photo.visibility['isfriend'].to_i,
68
+ :is_family => photo.visibility['isfamily'].to_i,
69
+
70
+ :taken_at => (Time.parse(photo.dates['taken']) rescue nil),
71
+ :updated_at => (Time.at(photo.dates['lastupdate'].to_i) rescue nil),
72
+ :tags => photo.tags.tag.map { |t|
73
+ { :id => t['id'], :author => t['author'],
74
+ :raw => t['raw'], :machine_tag => t['machine_tag'],
75
+ :text => t.text }},
76
+
77
+ :url_photopage => photo.urls.url.text
78
+ }
79
+ end
22
80
  # Alias to image_url method
23
81
  def url(size = :medium)
24
82
  image_url(size)
@@ -271,8 +329,8 @@ class Flickr::Photos::Photo
271
329
 
272
330
  _sizes = []
273
331
  rsp.sizes.size.each do |size|
274
- _sizes << Flickr::Photos::Size.new(:label => size[:label], :width => size[:width],
275
- :height => size[:height], :source => size[:source], :url => size[:url])
332
+ _sizes << Flickr::Photos::Size.new(:label => size[:label], :width => size[:width].to_i,
333
+ :height => size[:height].to_i, :source => size[:source], :url => size[:url])
276
334
  end
277
335
  _sizes
278
336
  end
@@ -319,25 +377,23 @@ class Flickr::Photos::Photo
319
377
  rsp = @flickr.send_request('flickr.photos.getInfo', :photo_id => self.id, :secret => self.secret)
320
378
 
321
379
  self.info_added = true
322
- self.description = rsp.photo.description.to_s.strip
323
- self.original_secret = rsp.photo[:originalsecret]
324
- self.owner_username = rsp.photo.owner[:username]
325
- self.owner_realname = rsp.photo.owner[:realname]
326
- self.url_photopage = rsp.photo.urls.url.to_s
327
- self.comment_count = rsp.photo.comments.to_s.to_i
380
+
381
+ ::Flickr::Photos::Photo.create_attributes(rsp.photo).each do |k,v|
382
+ send("#{k}=", v)
383
+ end
328
384
 
329
385
  self.notes = []
330
386
 
331
- rsp.photo.notes.note.each do |note|
387
+ rsp.photo.notes.each do |note|
332
388
  self.notes << Flickr::Photos::Note.new(:id => note[:id],
333
- :note => note.to_s,
334
- :author => note[:author],
335
- :author_name => note[:authorname],
336
- :x => note[:x],
337
- :y => note[:y],
338
- :width => note[:w],
339
- :height => note[:h])
340
- end if rsp.photo.notes.note
389
+ :note => note.to_s,
390
+ :author => note[:author],
391
+ :author_name => note[:authorname],
392
+ :x => note[:x],
393
+ :y => note[:y],
394
+ :width => note[:w],
395
+ :height => note[:h])
396
+ end
341
397
  end
342
398
  end
343
399
  end
data/lib/flickr/photos.rb CHANGED
@@ -215,39 +215,41 @@ class Flickr::Photos < Flickr::Base
215
215
  # Raises an error if photo not found
216
216
  def find_by_id(photo_id)
217
217
  rsp = @flickr.send_request('flickr.photos.getInfo', :photo_id => photo_id)
218
- Photo.new(@flickr, :id => rsp.photo[:id].to_i, :owner => rsp.photo.owner,
219
- :secret => rsp.photo[:secret], :server => rsp.photo[:server].to_i, :farm => rsp.photo[:farm],
220
- :title => rsp.photo.title,
221
- :is_public => rsp.photo.visibility[:public], :is_friend => rsp.photo.visibility[:is_friend], :is_family => rsp.photo.visibility[:is_family])
218
+
219
+ attributes = Photo.create_attributes(rsp.photo)
220
+
221
+ Photo.new(@flickr, attributes)
222
222
  end
223
223
 
224
224
  protected
225
+
226
+
225
227
  def create_attributes(photo)
226
- {:id => photo[:id],
227
- :owner => photo[:owner],
228
- :secret => photo[:secret],
229
- :server => photo[:server],
230
- :farm => photo[:farm],
231
- :title => photo[:title],
232
- :is_public => photo[:ispublic],
233
- :is_friend => photo[:isfriend],
234
- :is_family => photo[:isfamily],
235
- :license_id => photo[:license].to_i,
236
- :uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
237
- :taken_at => (Time.parse(photo[:datetaken]) rescue nil),
238
- :owner_name => photo[:ownername],
239
- :icon_server => photo[:icon_server],
240
- :original_format => photo[:originalformat],
241
- :updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
242
- :rotation => photo[:rotation],
243
- :geo => photo[:geo],
244
- :tags => photo[:tags],
245
- :machine_tags => photo[:machine_tags],
246
- :o_dims => photo[:o_dims],
247
- :o_height => photo[:o_height],
248
- :o_width => photo[:o_width],
249
- :views => photo[:views].to_i,
250
- :media => photo[:media]}
228
+ {:id => photo['id'].to_i,
229
+ :owner => photo['owner'],
230
+ :secret => photo['secret'],
231
+ :server => photo['server'],
232
+ :farm => photo['farm'],
233
+ :title => photo['title'],
234
+ :is_public => photo['ispublic'],
235
+ :is_friend => photo['isfriend'],
236
+ :is_family => photo['isfamily'],
237
+ :license_id => photo['license'].to_i,
238
+ :uploaded_at => (Time.at(photo['dateupload'].to_i) rescue nil),
239
+ :taken_at => (Time.parse(photo['datetaken']) rescue nil),
240
+ :owner_name => photo['ownername'],
241
+ :icon_server => photo['icon_server'],
242
+ :original_format => photo['originalformat'],
243
+ :updated_at => (Time.at(photo['lastupdate'].to_i) rescue nil),
244
+ :rotation => photo['rotation'],
245
+ :geo => photo['geo'],
246
+ :tags => photo['tags'],
247
+ :machine_tags => photo['machine_tags'],
248
+ :o_dims => photo['o_dims'],
249
+ :o_height => photo['o_height'],
250
+ :o_width => photo['o_width'],
251
+ :views => photo['views'].to_i,
252
+ :media => photo['media']}
251
253
  end
252
254
 
253
255
  end
@@ -40,8 +40,8 @@ class Flickr::Photosets < Flickr::Base
40
40
  {
41
41
  :id => photoset[:id],
42
42
  :num_photos => photoset[:photos],
43
- :title => photoset.title.to_s,
44
- :description => photoset.description.to_s
43
+ :title => photoset.title.text.to_s,
44
+ :description => photoset.at_xpath("description").text
45
45
  }
46
46
  end
47
47
 
data/lib/flickr/urls.rb CHANGED
@@ -32,8 +32,8 @@ class Flickr::Urls < Flickr::Base
32
32
 
33
33
  def lookup_user url
34
34
  rsp = @flickr.send_request('flickr.urls.lookupUser', {:url => url})
35
- user_id = UserLookupResult.new(rsp.user[:id])
36
- user_id.username = rsp.user.username
35
+ user_id = UserLookupResult.new(rsp.user['id'])
36
+ user_id.username = rsp.user.username.text
37
37
  user_id
38
38
  end
39
39
 
data/lib/flickr_fu.rb CHANGED
@@ -36,101 +36,6 @@ require 'date'
36
36
  require File.join(File.dirname(__FILE__), 'flickr', file)
37
37
  end
38
38
 
39
- module Flickr
40
-
41
- if RUBY_VERSION =~ /1.8/
42
- # Credit to Jim Weirich at http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc
43
- class BlankSlate
44
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
45
- end
46
- else
47
- BlankSlate = BasicObject
48
- end
49
-
50
- # Class that makes accessing xml objects more like any other ruby object
51
- # thanks to the magic of method missing
52
- class XmlMagic < BlankSlate
53
- require 'rexml/document'
54
-
55
- def initialize(xml, namespace="")
56
- if xml.class == ::REXML::Element or xml.class == ::Array
57
- @element = xml
58
- else
59
- @xml = ::REXML::Document.new(xml)
60
- @element = @xml.root
61
- end
62
- @namespace = namespace
63
- end
64
-
65
- def each
66
- @element.each {|e| yield ::Flickr::XmlMagic.new(e, @namespace)}
67
- end
68
-
69
- def method_missing(method, selection=nil)
70
- evaluate(method.to_s, selection)
71
- end
72
-
73
- def namespace=(namespace)
74
- if namespace and namespace.length > 0 # caca
75
- @namespace = namespace + ":"
76
- else
77
- @namespace = ""
78
- end
79
- end
80
-
81
- def to_s
82
- if @element.class == ::Array
83
- @element.collect{|e| e.text}.join
84
- else
85
- @element.text
86
- end
87
- end
88
-
89
- def [](index, count = nil)
90
- if index.is_a?(::Fixnum) or index.is_a?(::Bignum) or index.is_a?(::Integer) or index.is_a?(::Range)
91
- if @element.is_a?(::Array)
92
- if count
93
- ::Flickr::XmlMagic.new(@element[index, count], @namespace)
94
- else
95
- ::Flickr::XmlMagic.new(@element[index], @namespace)
96
- end
97
- else
98
- nil
99
- end
100
- elsif index.is_a?(::Symbol)
101
- if @element.is_a?(::Array)
102
- if @element.empty?
103
- nil
104
- else
105
- @element[0].attributes[index.to_s]
106
- end
107
- else
108
- @element.attributes[index.to_s]
109
- end
110
- end
111
- end
112
-
113
- private
114
- def evaluate(name, selection)
115
-
116
- if @element.is_a?(::Array)
117
- elements = @element[0].get_elements(@namespace + name)
118
- else
119
- elements = @element.get_elements(@namespace + name)
120
- end
121
-
122
- if elements.empty?
123
- nil
124
- else
125
- if selection == :count
126
- elements.length
127
- else
128
- ::Flickr::XmlMagic.new(elements, @namespace)
129
- end
130
- end
131
- end
132
- end
133
- end # module Flickr
134
39
 
135
40
 
136
41
  class Object
@@ -37,7 +37,7 @@ describe Flickr::Photos::Photo do
37
37
  it "should return the description" do
38
38
  @flickr.should_receive(:request_over_http).and_return(@info_xml)
39
39
  @photo.description.should ==
40
- "The last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów."
40
+ "\nThe last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów.\n\t\t"
41
41
  end
42
42
  end
43
43
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fotonauts-flickr_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,6 +29,22 @@ dependencies:
29
29
  - - ! '>'
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.0.0
32
+ - !ruby/object:Gem::Dependency
33
+ name: nokogiri
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>'
38
+ - !ruby/object:Gem::Version
39
+ version: 1.5.5
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>'
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.5
32
48
  description: Provides a ruby interface to flickr via the REST api
33
49
  email: ben@commonthread.com
34
50
  executables: []