fotonauts-flickr_fu 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,7 +19,6 @@ begin
19
19
  s.rdoc_options = ["--main", "README"]
20
20
  s.extra_rdoc_files = ["README"]
21
21
  s.add_dependency("mime-types", ["> 0.0.0"])
22
- s.add_dependency("xml-magic", ["> 0.0.0"])
23
22
  s.files.exclude("spec/spec.local.opts")
24
23
  end
25
24
  rescue LoadError
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 2
4
+ :patch: 3
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.2"
5
+ s.version = "0.3.3"
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,13 +105,10 @@ 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<xml-magic>, ["> 0.0.0"])
109
108
  else
110
109
  s.add_dependency(%q<mime-types>, ["> 0.0.0"])
111
- s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
112
110
  end
113
111
  else
114
112
  s.add_dependency(%q<mime-types>, ["> 0.0.0"])
115
- s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
116
113
  end
117
114
  end
data/lib/flickr_fu.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'xml_magic'
3
2
  require 'net/http'
4
3
  require 'cgi'
5
4
  require 'uri'
@@ -37,7 +36,102 @@ require 'date'
37
36
  require File.join(File.dirname(__FILE__), 'flickr', file)
38
37
  end
39
38
 
40
- include CommonThread::XML
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 CommonThread::XML::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
+ CommonThread::XML::XmlMagic.new(@element[index, count], @namespace)
94
+ else
95
+ CommonThread::XML::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
+ CommonThread::XML::XmlMagic.new(elements, @namespace)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end # module Flickr
134
+
41
135
 
42
136
  class Object
43
137
  # returning allows you to pass an object to a block that you can manipulate returning the manipulated object
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fotonauts-flickr_fu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 3
9
- - 2
10
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ben Wyrosdick
@@ -17,18 +16,16 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2009-05-19 00:00:00 +00:00
19
+ date: 2009-05-19 00:00:00 +02:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
23
  name: mime-types
25
24
  prerelease: false
26
25
  requirement: &id001 !ruby/object:Gem::Requirement
27
- none: false
28
26
  requirements:
29
27
  - - ">"
30
28
  - !ruby/object:Gem::Version
31
- hash: 31
32
29
  segments:
33
30
  - 0
34
31
  - 0
@@ -36,22 +33,6 @@ dependencies:
36
33
  version: 0.0.0
37
34
  type: :runtime
38
35
  version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
40
- name: xml-magic
41
- prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ">"
46
- - !ruby/object:Gem::Version
47
- hash: 31
48
- segments:
49
- - 0
50
- - 0
51
- - 0
52
- version: 0.0.0
53
- type: :runtime
54
- version_requirements: *id002
55
36
  description: Provides a ruby interface to flickr via the REST api
56
37
  email: ben@commonthread.com
57
38
  executables: []
@@ -139,27 +120,23 @@ rdoc_options:
139
120
  require_paths:
140
121
  - lib
141
122
  required_ruby_version: !ruby/object:Gem::Requirement
142
- none: false
143
123
  requirements:
144
124
  - - ">="
145
125
  - !ruby/object:Gem::Version
146
- hash: 3
147
126
  segments:
148
127
  - 0
149
128
  version: "0"
150
129
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
130
  requirements:
153
131
  - - ">="
154
132
  - !ruby/object:Gem::Version
155
- hash: 3
156
133
  segments:
157
134
  - 0
158
135
  version: "0"
159
136
  requirements: []
160
137
 
161
138
  rubyforge_project:
162
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.3.6
163
140
  signing_key:
164
141
  specification_version: 3
165
142
  summary: Provides a ruby interface to flickr via the REST api