benschwarz-flickr-rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +21 -0
  2. data/flickr-rest.gemspec +15 -0
  3. data/lib/flickr-rest.rb +44 -0
  4. metadata +63 -0
data/README ADDED
@@ -0,0 +1,21 @@
1
+ # Introduction
2
+
3
+ flickr-rest is a stab at removing all the stuff that you don't really
4
+ want to do. There are no specific photo methods, community. Nothing.
5
+
6
+ Simply use it to query the bits you want.
7
+ If you want a flickr api wrapper, use the flickr gem.
8
+
9
+ # Usage
10
+
11
+ require 'flickr-rest'
12
+
13
+ # My API key has been set as the default. Flickr probably won't like that.
14
+
15
+ Flickr::Query::API_KEY = 'your-api-key-here'
16
+ flickr = Flickr::Query.new 'your-user-id-here'
17
+
18
+ flickr.execute('flickr.test.echo') => #<Hpricot::Doc{} *snip*
19
+
20
+ Then use simple Hpricot selectors to traverse through the tree.
21
+
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "flickr-rest"
3
+ s.version = "0.0.1"
4
+ s.date = "2008-06-01"
5
+ s.summary = "A light interface to call flickr 'restful' api methods"
6
+ s.email = "ben@germanforblack.com"
7
+ s.homepage = "http://github.com/benschwarz/flickr-rest"
8
+ s.description = "A light interface to call flickr 'restful' api methods"
9
+ s.authors = ["Ben Schwarz"]
10
+ s.files = ["README", "flickr-rest.gemspec", "lib/flickr-rest.rb"]
11
+ s.require_path = "lib"
12
+
13
+ # Deps
14
+ s.add_dependency("hpricot", ">= 0.6")
15
+ end
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+ require 'open-uri'
4
+
5
+ module Flickr
6
+ class Query
7
+ VERSION = '0.0.1'
8
+ API_BASE = "http://api.flickr.com/services/rest/"
9
+ API_KEY = "2b60171843b346aa104e3a38d0129e5e"
10
+ class Failure < StandardError; end
11
+
12
+ # @param user_id - Your flickr user id
13
+ def initialize(user_id)
14
+ @user_id = user_id
15
+ end
16
+
17
+ # @param api_method - flickr.test.echo
18
+ # @param params={} - :photo_id => 2929112139
19
+ def execute(api_method, params={})
20
+ dispatch(build_query(api_method, params))
21
+ end
22
+
23
+ private
24
+ def dispatch(query)
25
+ puts query
26
+ response = Hpricot.XML(open(query).read)
27
+ raise Failure, response.at(:err)['msg'] unless response.search(:err).empty?
28
+ return response
29
+ end
30
+
31
+ def build_query(method, params={})
32
+ url = []
33
+ opts = {
34
+ :method => method,
35
+ :api_key => API_KEY,
36
+ :user_id => @user_id,
37
+ }.merge(params).each do |key, value|
38
+ url << "#{key}=#{value}"
39
+ end
40
+
41
+ return API_BASE + "?" + url.join("&")
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benschwarz-flickr-rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Schwarz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0.6"
23
+ version:
24
+ description: A light interface to call flickr 'restful' api methods
25
+ email: ben@germanforblack.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - README
34
+ - flickr-rest.gemspec
35
+ - lib/flickr-rest.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/benschwarz/flickr-rest
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.0.1
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A light interface to call flickr 'restful' api methods
62
+ test_files: []
63
+