benschwarz-flickr-rest 0.1.1 → 0.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.
- data/README.markdown +4 -9
- data/flickr-rest.gemspec +1 -1
- data/lib/flickr-rest.rb +16 -29
- metadata +1 -1
data/README.markdown
CHANGED
@@ -8,16 +8,11 @@ If you want a flickr api wrapper, use the flickr gem.
|
|
8
8
|
|
9
9
|
# Usage
|
10
10
|
|
11
|
-
|
11
|
+
require 'flickr-rest'
|
12
|
+
Flickr::Query::CONFIG_PATH = '/path/to/flickr.yml'
|
13
|
+
flickr = Flickr::Query.new
|
12
14
|
|
13
|
-
|
15
|
+
flickr.request('flickr.test.echo')
|
14
16
|
|
15
|
-
Flickr::Query::API_KEY = 'your-api-key-here'
|
16
|
-
flickr = Flickr::Query.new 'your-user-id-here'
|
17
17
|
|
18
|
-
flickr.execute('flickr.test.echo')
|
19
|
-
|
20
|
-
=> #<Hpricot::Doc{} *snip*
|
21
|
-
|
22
|
-
Then use simple Hpricot selectors to traverse through the tree.
|
23
18
|
|
data/flickr-rest.gemspec
CHANGED
data/lib/flickr-rest.rb
CHANGED
@@ -1,37 +1,24 @@
|
|
1
|
-
|
2
|
-
require 'minigems'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'hpricot'
|
1
|
+
require 'json'
|
8
2
|
require 'open-uri'
|
9
3
|
|
10
4
|
module Flickr
|
11
5
|
class Query
|
12
|
-
VERSION
|
13
|
-
API_BASE
|
6
|
+
VERSION = "0.2.0".freeze
|
7
|
+
API_BASE = "http://api.flickr.com/services/rest/".freeze
|
14
8
|
|
15
9
|
class Failure < StandardError; end
|
16
|
-
|
17
|
-
|
18
|
-
# @param user_id - Your flickr user id
|
19
|
-
def initialize(user_id)
|
20
|
-
@user_id = user_id
|
21
|
-
end
|
22
|
-
|
10
|
+
|
23
11
|
# @param api_method eg: flickr.test.echo
|
24
12
|
# @param params={} eg: :photo_id => 2929112139
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
def initialize
|
14
|
+
@@config ||= YAML::load(File.open(CONFIG_PATH))
|
15
|
+
rescue NameError
|
16
|
+
raise Failure, "set your flickr API key and shared secret with a YAML file and point it to Flickr::Query.CONFIG_PATH = 'my-config.yml'"
|
29
17
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
response
|
34
|
-
raise Failure, response.at(:err)['msg'] unless response.search(:err).empty?
|
18
|
+
|
19
|
+
def request(api_method, params = {})
|
20
|
+
response = JSON.parse(open(build_query(api_method, params)).read)
|
21
|
+
raise Failure, response["message"] if response["stat"] == "fail"
|
35
22
|
return response
|
36
23
|
end
|
37
24
|
|
@@ -39,10 +26,10 @@ module Flickr
|
|
39
26
|
url = []
|
40
27
|
opts = {
|
41
28
|
:method => method,
|
42
|
-
:
|
43
|
-
:
|
44
|
-
}.merge(params).each do |key, value|
|
45
|
-
url << "#{key}=#{value}" unless value.
|
29
|
+
:nojsoncallback => 1,
|
30
|
+
:format => "json"
|
31
|
+
}.merge(params).merge(@@config).each do |key, value|
|
32
|
+
url << "#{key}=#{value}" unless value.nil?
|
46
33
|
end
|
47
34
|
|
48
35
|
return API_BASE + "?" + url.join("&")
|