benschwarz-flickr-rest 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- require 'flickr-rest'
11
+ require 'flickr-rest'
12
+ Flickr::Query::CONFIG_PATH = '/path/to/flickr.yml'
13
+ flickr = Flickr::Query.new
12
14
 
13
- # My API key has been set as the default. Flickr probably won't like that.
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "flickr-rest"
3
- s.version = "0.1.1"
3
+ s.version = "0.2"
4
4
  s.date = "2008-11-17"
5
5
  s.summary = "A light interface to call flickr 'restful' api methods"
6
6
  s.email = "ben@germanforblack.com"
data/lib/flickr-rest.rb CHANGED
@@ -1,37 +1,24 @@
1
- begin
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 = '0.1.1'
13
- API_BASE = "http://api.flickr.com/services/rest/"
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
- class ApiKeyRequired < StandardError; end
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 execute(api_method, params={})
26
- raise ApiKeyRequired, "set your flickr API key using Flickr::Query.API_KEY = ''" if API_KEY.nil?
27
-
28
- dispatch(build_query(api_method, params))
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
- private
32
- def dispatch(query)
33
- response = Hpricot.XML(open(query).read)
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
- :api_key => API_KEY,
43
- :user_id => @user_id
44
- }.merge(params).each do |key, value|
45
- url << "#{key}=#{value}" unless value.empty?
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("&")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benschwarz-flickr-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz