flickr-rest 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +23 -0
- data/flickr-rest.gemspec +15 -0
- data/lib/flickr-rest.rb +51 -0
- metadata +64 -0
data/README.markdown
ADDED
@@ -0,0 +1,23 @@
|
|
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')
|
19
|
+
|
20
|
+
=> #<Hpricot::Doc{} *snip*
|
21
|
+
|
22
|
+
Then use simple Hpricot selectors to traverse through the tree.
|
23
|
+
|
data/flickr-rest.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "flickr-rest"
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.date = "2008-11-17"
|
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.markdown", "flickr-rest.gemspec", "lib/flickr-rest.rb"]
|
11
|
+
s.require_path = "lib"
|
12
|
+
|
13
|
+
# Deps
|
14
|
+
s.add_dependency("hpricot", ">= 0.6")
|
15
|
+
end
|
data/lib/flickr-rest.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
begin
|
2
|
+
require 'minigems'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'hpricot'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
module Flickr
|
11
|
+
class Query
|
12
|
+
VERSION = '0.1.1'
|
13
|
+
API_BASE = "http://api.flickr.com/services/rest/"
|
14
|
+
|
15
|
+
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
|
+
|
23
|
+
# @param api_method eg: flickr.test.echo
|
24
|
+
# @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))
|
29
|
+
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?
|
35
|
+
return response
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_query(method, params={})
|
39
|
+
url = []
|
40
|
+
opts = {
|
41
|
+
: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.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
return API_BASE + "?" + url.join("&")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flickr-rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Schwarz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-17 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.6"
|
24
|
+
version:
|
25
|
+
description: A light interface to call flickr 'restful' api methods
|
26
|
+
email: ben@germanforblack.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- README.markdown
|
35
|
+
- flickr-rest.gemspec
|
36
|
+
- lib/flickr-rest.rb
|
37
|
+
has_rdoc: false
|
38
|
+
homepage: http://github.com/benschwarz/flickr-rest
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: A light interface to call flickr 'restful' api methods
|
63
|
+
test_files: []
|
64
|
+
|