objectiveflickr 0.9.0 → 0.9.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/History.txt +0 -3
- data/Rakefile +0 -1
- data/lib/objectiveflickr/flickr_invocation.rb +26 -11
- data/lib/objectiveflickr/version.rb +1 -1
- data/test/objectiveflickr_test.rb +22 -0
- metadata +2 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -16,7 +16,6 @@ EMAIL = "lukhnos@gmail.com"
|
|
16
16
|
DESCRIPTION = "objectiveflickr is a minimalistic Flickr API library that uses REST-style calls and receives JSON response blocks, resulting in very concise code. Named so in order to echo another Flickr library of mine, under the same name, developed for Objective-C."
|
17
17
|
GEM_NAME = "objectiveflickr" # what ppl will type to install your gem
|
18
18
|
RUBYFORGE_PROJECT = "objectiveflickr" # The unix name for your project
|
19
|
-
RUBYFORGE_GROUP_ID = "2698"
|
20
19
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
21
20
|
RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
|
22
21
|
|
@@ -18,7 +18,10 @@ $KCODE = 'UTF8'
|
|
18
18
|
|
19
19
|
# FlickrInvocation
|
20
20
|
class FlickrInvocation
|
21
|
-
|
21
|
+
@@default_api_key = ''
|
22
|
+
@@default_shared_secret = ''
|
23
|
+
@@default_options = {}
|
24
|
+
|
22
25
|
SHARED_SECRET = ''
|
23
26
|
AUTH_ENDPOINT = 'http://flickr.com/services/auth/'
|
24
27
|
REST_ENDPOINT = 'http://api.flickr.com/services/rest/'
|
@@ -27,16 +30,14 @@ class FlickrInvocation
|
|
27
30
|
# Initializes the instance with the api_key (required) and an
|
28
31
|
# optional shared_secret (required only if you need to make
|
29
32
|
# authenticated call). Current available option is:
|
30
|
-
# * :
|
33
|
+
# * :raise_exception_on_error: set this key to true if you want the
|
31
34
|
# call method to raise an error if Flickr returns one
|
32
|
-
def initialize(api_key = nil, shared_secret = nil, options =
|
33
|
-
@api_key = api_key ||
|
34
|
-
@shared_secret = shared_secret ||
|
35
|
-
|
36
|
-
# options
|
37
|
-
@option_exception_on_error = options[:exception_on_error] ? true : false
|
35
|
+
def initialize(api_key = nil, shared_secret = nil, options = nil)
|
36
|
+
@api_key = api_key || @@default_api_key
|
37
|
+
@shared_secret = shared_secret || @@default_shared_secret
|
38
|
+
@options = options || @@default_options
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
# Invoke a Flickr method, pass :auth=>true in the param hash
|
41
42
|
# if you want the method call to be signed (required when you
|
42
43
|
# make authenticaed calls, e.g. flickr.auth.getFrob or
|
@@ -45,8 +46,8 @@ class FlickrInvocation
|
|
45
46
|
url = method_url(method, params)
|
46
47
|
rsp = FlickrResponse.new Net::HTTP.get(URI.parse(url))
|
47
48
|
|
48
|
-
if @
|
49
|
-
raise rsp
|
49
|
+
if @options[:raise_exception_on_error] && rsp.error?
|
50
|
+
raise RuntimeError, rsp
|
50
51
|
end
|
51
52
|
|
52
53
|
rsp
|
@@ -87,6 +88,20 @@ class FlickrInvocation
|
|
87
88
|
p = params.split("-")
|
88
89
|
{ :server_id=>p[1], :id=>p[2], :secret=>p[3], :size=>p[4], :type=>p[5] }
|
89
90
|
end
|
91
|
+
|
92
|
+
# set the default API key
|
93
|
+
def self.default_api_key(k)
|
94
|
+
@@default_api_key=k
|
95
|
+
end
|
96
|
+
|
97
|
+
# set the default shared secret
|
98
|
+
def self.default_shared_secret(s)
|
99
|
+
@@default_shared_secret=s
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.default_options(o)
|
103
|
+
@@default_options = o
|
104
|
+
end
|
90
105
|
|
91
106
|
private
|
92
107
|
def method_url(method, params=nil)
|
@@ -16,4 +16,26 @@ class ObjectiveFlickrTest < Test::Unit::TestCase
|
|
16
16
|
assert(r.ok?, "response should be ok")
|
17
17
|
assert_equal(r["method"]["_content"], "flickr.test.echo", "method name should echo")
|
18
18
|
end
|
19
|
+
|
20
|
+
def test_default_settings
|
21
|
+
FlickrInvocation.default_api_key 'bf67a649fffb210651334a09b92df02e'
|
22
|
+
f = FlickrInvocation.new
|
23
|
+
|
24
|
+
r = f.call("flickr.test.echo")
|
25
|
+
assert(r.ok?, "response should be ok")
|
26
|
+
assert_equal(r["method"]["_content"], "flickr.test.echo", "method name should echo")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_corrupt_key
|
30
|
+
# try a corrupt key
|
31
|
+
FlickrInvocation.default_api_key 'bf67a649fffb210651334a09b92df02f'
|
32
|
+
FlickrInvocation.default_options :raise_exception_on_error => true
|
33
|
+
|
34
|
+
f = FlickrInvocation.new
|
35
|
+
r = f.call("flickr.test.echo")
|
36
|
+
|
37
|
+
rescue => e
|
38
|
+
assert(e.message.error?, "response should be an error")
|
39
|
+
assert_equal(e.message.error_message, "Invalid API Key (Key not found)", "error message should be 'invalid API key'")
|
40
|
+
end
|
19
41
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: objectiveflickr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date: 2006-12-
|
6
|
+
version: 0.9.1
|
7
|
+
date: 2006-12-12 00:00:00 -05:00
|
8
8
|
summary: objectiveflickr is a minimalistic Flickr API library that uses REST-style calls and receives JSON response blocks, resulting in very concise code. Named so in order to echo another Flickr library of mine, under the same name, developed for Objective-C.
|
9
9
|
require_paths:
|
10
10
|
- lib
|