flickraw 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/flickraw_rdoc.rb +1 -0
- data/lib/flickraw.rb +24 -15
- data/rakefile +2 -71
- data/test/test.rb +3 -3
- data/test/test_upload.rb +1 -1
- metadata +27 -11
data/README.rdoc
CHANGED
@@ -33,6 +33,9 @@ This will recreate the documentation by fetching the methods descriptions from f
|
|
33
33
|
|
34
34
|
require 'flickraw'
|
35
35
|
|
36
|
+
FlickRaw.api_key="... Your API key ..."
|
37
|
+
FlickRaw.shared_secret="... Your shared secret ..."
|
38
|
+
|
36
39
|
list = flickr.photos.getRecent
|
37
40
|
|
38
41
|
id = list[0].id
|
data/flickraw_rdoc.rb
CHANGED
data/lib/flickraw.rb
CHANGED
@@ -32,7 +32,7 @@ if ENV['http_proxy'] and not FlickRawOptions['proxy_host']
|
|
32
32
|
end
|
33
33
|
|
34
34
|
module FlickRaw
|
35
|
-
VERSION='0.8.
|
35
|
+
VERSION='0.8.4'
|
36
36
|
|
37
37
|
FLICKR_HOST='api.flickr.com'.freeze
|
38
38
|
REST_PATH='/services/rest/?'.freeze
|
@@ -47,7 +47,9 @@ module FlickRaw
|
|
47
47
|
|
48
48
|
class Response
|
49
49
|
def self.build(h, type) # :nodoc:
|
50
|
-
if
|
50
|
+
if h.is_a? Response
|
51
|
+
h
|
52
|
+
elsif type =~ /s$/ and (a = h[$`]).is_a? Array
|
51
53
|
ResponseList.new(h, type, a.collect {|e| Response.build(e, $`)})
|
52
54
|
elsif h.keys == ["_content"]
|
53
55
|
h["_content"]
|
@@ -74,6 +76,8 @@ module FlickRaw
|
|
74
76
|
def to_s; @h["_content"] || super end
|
75
77
|
def inspect; @h.inspect end
|
76
78
|
def to_hash; @h end
|
79
|
+
def marshal_dump; [@h, @flickr_type] end
|
80
|
+
def marshal_load(data); initialize(*data) end
|
77
81
|
end
|
78
82
|
|
79
83
|
class ResponseList < Response
|
@@ -84,6 +88,7 @@ module FlickRaw
|
|
84
88
|
def to_a; @a end
|
85
89
|
def inspect; @a.inspect end
|
86
90
|
def size; @a.size end
|
91
|
+
def marshal_dump; [@h, @flickr_type, @a] end
|
87
92
|
end
|
88
93
|
|
89
94
|
class FailedResponse < StandardError
|
@@ -124,9 +129,10 @@ module FlickRaw
|
|
124
129
|
klass.build_request method_nesting.join('.')
|
125
130
|
else
|
126
131
|
req = method_nesting.first
|
127
|
-
|
128
|
-
|
129
|
-
|
132
|
+
module_eval %{
|
133
|
+
def #{req}(*args, &block)
|
134
|
+
@flickr.call("#{request_name}.#{req}", *args, &block)
|
135
|
+
end
|
130
136
|
}
|
131
137
|
flickr_methods << req
|
132
138
|
end
|
@@ -155,21 +161,14 @@ module FlickRaw
|
|
155
161
|
# This is the central method. It does the actual request to the flickr server.
|
156
162
|
#
|
157
163
|
# Raises FailedResponse if the response status is _failed_.
|
158
|
-
def call(req, args={})
|
164
|
+
def call(req, args={}, &block)
|
159
165
|
@token = nil if req == "flickr.auth.getFrob"
|
160
166
|
http_response = open_flickr do |http|
|
161
167
|
request = Net::HTTP::Post.new(REST_PATH, 'User-Agent' => "Flickraw/#{VERSION}")
|
162
168
|
request.set_form_data(build_args(args, req))
|
163
169
|
http.request(request)
|
164
170
|
end
|
165
|
-
|
166
|
-
json = JSON.load(http_response.body.empty? ? "{}" : http_response.body)
|
167
|
-
raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
|
168
|
-
type, json = json.to_a.first if json.size == 1 and json.all? {|k,v| v.is_a? Hash}
|
169
|
-
|
170
|
-
res = Response.build json, type
|
171
|
-
@token = res.token if res.respond_to? :flickr_type and res.flickr_type == "auth"
|
172
|
-
res
|
171
|
+
process_response(req, http_response)
|
173
172
|
end
|
174
173
|
|
175
174
|
# Use this to upload the photo in _file_.
|
@@ -199,9 +198,19 @@ module FlickRaw
|
|
199
198
|
full_args
|
200
199
|
end
|
201
200
|
|
201
|
+
def process_response(req, http_response)
|
202
|
+
json = JSON.load(http_response.body.empty? ? "{}" : http_response.body)
|
203
|
+
raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
|
204
|
+
type, json = json.to_a.first if json.size == 1 and json.all? {|k,v| v.is_a? Hash}
|
205
|
+
|
206
|
+
res = Response.build json, type
|
207
|
+
@token = res.token if res.respond_to? :flickr_type and res.flickr_type == "auth"
|
208
|
+
res
|
209
|
+
end
|
210
|
+
|
202
211
|
def open_flickr
|
203
212
|
Net::HTTP::Proxy(FlickRawOptions['proxy_host'], FlickRawOptions['proxy_port'], FlickRawOptions['proxy_user'], FlickRawOptions['proxy_password']).start(FLICKR_HOST) {|http|
|
204
|
-
http.read_timeout = FlickRawOptions['timeout'] if FlickRawOptions
|
213
|
+
http.read_timeout = FlickRawOptions['timeout'] if FlickRawOptions.key?('timeout')
|
205
214
|
yield http
|
206
215
|
}
|
207
216
|
end
|
data/rakefile
CHANGED
@@ -5,8 +5,8 @@ require 'rake/gempackagetask'
|
|
5
5
|
require 'rake/testtask'
|
6
6
|
|
7
7
|
FlickRawOptions = {'lazyload' => true}
|
8
|
-
require 'lib/flickraw'
|
9
|
-
require 'flickraw_rdoc' if RUBY_VERSION >= "1.9"
|
8
|
+
require './lib/flickraw'
|
9
|
+
require './flickraw_rdoc' if RUBY_VERSION >= "1.9"
|
10
10
|
|
11
11
|
PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "LICENSE", "README.rdoc", "rakefile", "examples/*.rb", "test/*.rb"].to_a
|
12
12
|
|
@@ -32,75 +32,6 @@ CLOBBER.add "flickraw.gemspec"
|
|
32
32
|
|
33
33
|
Rake::RDocTask.new do |rd|
|
34
34
|
rd.rdoc_files.include "README.rdoc", "lib/flickraw.rb"
|
35
|
-
rd.options << "--inline-source"
|
36
35
|
end
|
37
36
|
|
38
37
|
Rake::TestTask.new
|
39
|
-
|
40
|
-
|
41
|
-
# Freezed version tasks
|
42
|
-
file "flickraw-cached.rb" do |t|
|
43
|
-
open(t.name, "w") {|f|
|
44
|
-
f.puts %{FlickRawOptions = {'lazyload' => true}}
|
45
|
-
f.puts %{require 'flickraw'}
|
46
|
-
f.puts %{FlickRaw::VERSION << '.#{Time.now.strftime("%Y%m%d")}-cached'}
|
47
|
-
f.puts 'ms = %w{' + flickr.reflection.getMethods.to_a.join(' ') + '}'
|
48
|
-
f.puts %{FlickRaw::Flickr.build(ms)}
|
49
|
-
}
|
50
|
-
end
|
51
|
-
CLOBBER.add "flickraw-cached.rb"
|
52
|
-
|
53
|
-
spec_cached = Gem::Specification.new do |s|
|
54
|
-
s.name = 'flickraw-cached'
|
55
|
-
s.summary = "Cached version of Flickraw"
|
56
|
-
s.author = "Mael Clerambault"
|
57
|
-
s.email = "maelclerambault@yahoo.fr"
|
58
|
-
s.homepage = "http://hanklords.github.com/flickraw/"
|
59
|
-
s.version = Time.now.strftime("%Y%m%d")
|
60
|
-
s.files = ["flickraw-cached.rb"]
|
61
|
-
s.require_path = '.'
|
62
|
-
s.add_dependency 'flickraw'
|
63
|
-
end
|
64
|
-
Rake::GemPackageTask.new(spec_cached).define
|
65
|
-
task :gem => ["flickraw-cached.rb"]
|
66
|
-
|
67
|
-
desc "Create cached gemspec file"
|
68
|
-
file "flickraw-cached.gemspec" do
|
69
|
-
open("flickraw-cached.gemspec", "w") {|g| g.puts spec_cached.to_ruby }
|
70
|
-
end
|
71
|
-
task :gem => ["flickraw-cached.gemspec"]
|
72
|
-
CLOBBER.add "flickraw-cached.gemspec"
|
73
|
-
|
74
|
-
FREEZED_CACHE_FILE = ENV['HOME'] + '/.flickraw_cached'
|
75
|
-
task :sync_cached do
|
76
|
-
require 'mail'
|
77
|
-
Mail.defaults {delivery_method :sendmail}
|
78
|
-
|
79
|
-
local_list = File.read(FREEZED_CACHE_FILE).split.sort
|
80
|
-
remote_list = flickr.reflection.getMethods.to_a.sort
|
81
|
-
|
82
|
-
if remote_list != local_list
|
83
|
-
# Flickr API has been updated
|
84
|
-
Mail.deliver do
|
85
|
-
from 'flickraw-cached-updater'
|
86
|
-
to ENV['MAILTO'] || ENV['LOGNAME']
|
87
|
-
subject "[flickraw-cached-updater'] flickraw-cached.gem updated"
|
88
|
-
body %|
|
89
|
-
flickraw-cached.gem has been updated.
|
90
|
-
|
91
|
-
New Flickr API methods :
|
92
|
-
- #{(remote_list-local_list).join("\n- ")}
|
93
|
-
|
|
94
|
-
end
|
95
|
-
|
96
|
-
# Build gem
|
97
|
-
Rake.application[:gem].invoke
|
98
|
-
|
99
|
-
# Upload gem
|
100
|
-
sh "gem push pkg/flickraw-cached-*.gem"
|
101
|
-
|
102
|
-
# Update cache and clean gem files
|
103
|
-
open(FREEZED_CACHE_FILE, 'w') {|f| remote_list.each {|m| f.puts m} }
|
104
|
-
Rake.application[:clobber].invoke
|
105
|
-
end
|
106
|
-
end
|
data/test/test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
|
-
require '
|
4
|
+
require 'flickraw'
|
5
5
|
|
6
6
|
class Basic < Test::Unit::TestCase
|
7
7
|
def test_request
|
@@ -316,8 +316,8 @@ class Basic < Test::Unit::TestCase
|
|
316
316
|
assert_equal "Canon DIGITAL IXUS 55", info.exif.find {|f| f.tag == "Model"}.raw
|
317
317
|
assert_equal "1/60", info.exif.find {|f| f.tag == "ExposureTime"}.raw
|
318
318
|
assert_equal "4.9", info.exif.find {|f| f.tag == "FNumber"}.raw
|
319
|
-
assert_equal "1600", info.exif.find {|f| f.tag == "
|
320
|
-
assert_equal "1200", info.exif.find {|f| f.tag == "
|
319
|
+
assert_equal "1600", info.exif.find {|f| f.tag == "RelatedImageWidth"}.raw
|
320
|
+
assert_equal "1200", info.exif.find {|f| f.tag == "RelatedImageHeight"}.raw
|
321
321
|
end
|
322
322
|
|
323
323
|
def test_photos_getSizes
|
data/test/test_upload.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 8
|
8
|
+
- 4
|
9
|
+
version: 0.8.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Mael Clerambault
|
@@ -9,19 +14,24 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-02-09 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: json
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 1
|
31
|
+
- 1
|
23
32
|
version: 1.1.1
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
description:
|
26
36
|
email: maelclerambault@yahoo.fr
|
27
37
|
executables: []
|
@@ -42,31 +52,37 @@ files:
|
|
42
52
|
- examples/upload.rb
|
43
53
|
- test/test_upload.rb
|
44
54
|
- test/test.rb
|
45
|
-
has_rdoc:
|
55
|
+
has_rdoc: true
|
46
56
|
homepage: http://hanklords.github.com/flickraw/
|
57
|
+
licenses: []
|
58
|
+
|
47
59
|
post_install_message:
|
48
60
|
rdoc_options: []
|
49
61
|
|
50
62
|
require_paths:
|
51
63
|
- lib
|
52
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
53
66
|
requirements:
|
54
67
|
- - ">="
|
55
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
56
71
|
version: "0"
|
57
|
-
version:
|
58
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
59
74
|
requirements:
|
60
75
|
- - ">="
|
61
76
|
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
62
79
|
version: "0"
|
63
|
-
version:
|
64
80
|
requirements: []
|
65
81
|
|
66
82
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.7
|
68
84
|
signing_key:
|
69
|
-
specification_version:
|
85
|
+
specification_version: 3
|
70
86
|
summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
|
71
87
|
test_files: []
|
72
88
|
|