resterl 0.0.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/.document +5 -0
- data/.gitignore +23 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +64 -0
- data/TODO +5 -0
- data/VERSION +1 -0
- data/lib/resterl/base_object.rb +39 -0
- data/lib/resterl/cache_interface.rb +11 -0
- data/lib/resterl/client.rb +94 -0
- data/lib/resterl/redis_cache.rb +22 -0
- data/lib/resterl/request.rb +72 -0
- data/lib/resterl/response.rb +25 -0
- data/lib/resterl/simple_cache.rb +109 -0
- data/lib/resterl.rb +106 -0
- data/resterl.gemspec +66 -0
- data/test/helper.rb +10 -0
- data/test/test_resterl.rb +7 -0
- metadata +113 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 fduetsch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= resterl
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 fduetsch. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "resterl"
|
9
|
+
gem.summary = %Q{Rudimentary HTTP client with focus on caching}
|
10
|
+
gem.description = %Q{Rudimentary HTTP client with focus on caching}
|
11
|
+
gem.email = "florian.duetsch@nix-wie-weg.de"
|
12
|
+
gem.homepage = "http://nix-wie-weg.de/"
|
13
|
+
gem.authors = ["Florian Dütsch"]
|
14
|
+
|
15
|
+
# TODO
|
16
|
+
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
17
|
+
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20
|
19
|
+
# for additional settings
|
20
|
+
|
21
|
+
# TODO: Können wir auf einen neuere Version gehen?
|
22
|
+
gem.add_dependency 'hashie', '~> 0.4.0'
|
23
|
+
gem.add_dependency 'yajl-ruby', '~> 0.7.7'
|
24
|
+
end
|
25
|
+
Jeweler::GemcutterTasks.new
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler (or a dependency) not available. " \
|
28
|
+
"Install it with: gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'rcov/rcovtask'
|
40
|
+
Rcov::RcovTask.new do |test|
|
41
|
+
test.libs << 'test'
|
42
|
+
test.pattern = 'test/**/test_*.rb'
|
43
|
+
test.verbose = true
|
44
|
+
end
|
45
|
+
rescue LoadError
|
46
|
+
task :rcov do
|
47
|
+
abort "RCov is not available. In order to run rcov, you must: " \
|
48
|
+
"sudo gem install spicycode-rcov"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
task :test => :check_dependencies
|
53
|
+
|
54
|
+
task :default => :test
|
55
|
+
|
56
|
+
require 'rake/rdoctask'
|
57
|
+
Rake::RDocTask.new do |rdoc|
|
58
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
59
|
+
|
60
|
+
rdoc.rdoc_dir = 'rdoc'
|
61
|
+
rdoc.title = "resterl #{version}"
|
62
|
+
rdoc.rdoc_files.include('README*')
|
63
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
64
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
class Resterl::BaseObject #< Hashie::Mash
|
4
|
+
|
5
|
+
class_inheritable_accessor :resterl_client, :parser, :complete_mime_type,
|
6
|
+
:mapper
|
7
|
+
#self.resterl_client = nil
|
8
|
+
#self.complete_mime_type = 'text/plain'
|
9
|
+
|
10
|
+
def initialize data = {}
|
11
|
+
@data = Hashie::Mash.new data
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing sym, *args, &block
|
15
|
+
# Vielleicht lassen sich auch feste Attribute delegieren, das wäre als
|
16
|
+
# method_missing.
|
17
|
+
@data.send sym, *args, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def self.get_object url, params = {}
|
23
|
+
headers = { 'Accept' => complete_mime_type }
|
24
|
+
doc = resterl_client.get(url, params, headers).body
|
25
|
+
doc = parser.call(doc)
|
26
|
+
doc = mapper.map(doc) if @mapper
|
27
|
+
new(doc)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.mime_type= t
|
31
|
+
self.parser, self.complete_mime_type = case t
|
32
|
+
when :json
|
33
|
+
[proc {|str| JSON.parse(str)}, 'application/json']
|
34
|
+
when :xml
|
35
|
+
[proc {|str| Hash.from_xml(str)}, 'application/xml']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class Resterl::Client
|
2
|
+
attr_reader :options
|
3
|
+
DEFAULTS = {
|
4
|
+
:max_redirect_depth => 10,
|
5
|
+
:cache => Resterl::SimpleCache.new,
|
6
|
+
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
7
|
+
:expiry_multiplier => 10,
|
8
|
+
:minimum_cache_lifetime => 5 * 60 # 5 Minuten
|
9
|
+
}
|
10
|
+
|
11
|
+
class TooManyRedirects < StandardError; end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@options = DEFAULTS.merge(options).freeze
|
15
|
+
@cache = @options[:cache]
|
16
|
+
end
|
17
|
+
|
18
|
+
def get url, params, headers
|
19
|
+
url = setup_url(url)
|
20
|
+
|
21
|
+
# Cache-Schlüssel aus Pfad hashen
|
22
|
+
cache_key = data_to_cache_key url, params, headers
|
23
|
+
|
24
|
+
# Response aus Cache holen
|
25
|
+
old_response = @cache.read(cache_key)
|
26
|
+
|
27
|
+
if old_response and not old_response.expired?
|
28
|
+
# Anfrage noch nicht abgelaufen, Ergebnis aus dem Cache verwenden
|
29
|
+
old_response
|
30
|
+
else
|
31
|
+
# Neue Anfrage
|
32
|
+
new_get_request url, cache_key, params, headers, old_response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def new_get_request url, cache_key, params, headers, old_response
|
39
|
+
|
40
|
+
# Ggf. ETag und Last-Modified auslesen
|
41
|
+
if old_response
|
42
|
+
etag = old_response.net_http_response['ETag']
|
43
|
+
headers['If-None-Match'] = etag if etag
|
44
|
+
|
45
|
+
last_modified = old_response.net_http_response['Last-Modified']
|
46
|
+
headers['If-Modified-Since'] = last_modified if last_modified
|
47
|
+
end
|
48
|
+
|
49
|
+
# Anfrage stellen, ggf. ETag mit übergeben
|
50
|
+
request = Resterl::Request.new(self, url, params, headers)
|
51
|
+
new_response = request.perform.response
|
52
|
+
|
53
|
+
response, max_age_seconds = case new_response
|
54
|
+
|
55
|
+
when Net::HTTPClientError, Net::HTTPServerError
|
56
|
+
# Aus dem Cache muss nichts entfernt werden, weil ja auch kein Eintrag
|
57
|
+
# (mehr) drin ist.
|
58
|
+
new_response.error!
|
59
|
+
|
60
|
+
when Net::HTTPNotModified
|
61
|
+
# Wenn "304 Not Modified", dann altes Ergebnis als neues Ergebnis
|
62
|
+
# verwenden
|
63
|
+
r_temp = Resterl::Response.new(new_response)
|
64
|
+
old_response.update_expires_at(r_temp.expires_at)
|
65
|
+
[old_response, r_temp.expires_at - Time.now]
|
66
|
+
|
67
|
+
when Net::HTTPSuccess
|
68
|
+
r = Resterl::Response.new(new_response)
|
69
|
+
[r, r.expires_at - Time.now]
|
70
|
+
else
|
71
|
+
raise 'unknown response'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Cachezeit berechnen
|
75
|
+
expiry = [
|
76
|
+
max_age_seconds * options[:expiry_multiplier],
|
77
|
+
options[:minimum_cache_lifetime]
|
78
|
+
].max
|
79
|
+
|
80
|
+
# Ergebnis im Cache speichern
|
81
|
+
@cache.write cache_key, response, expiry
|
82
|
+
|
83
|
+
response
|
84
|
+
end
|
85
|
+
|
86
|
+
def setup_url url
|
87
|
+
bu = options[:base_uri]
|
88
|
+
bu ? "#{bu}#{url}" : url
|
89
|
+
end
|
90
|
+
|
91
|
+
def data_to_cache_key *args
|
92
|
+
args.hash
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Resterl::RedisCache < Resterl::CacheInterface
|
2
|
+
|
3
|
+
def initialize client
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
def read key
|
8
|
+
dump = @client.get key
|
9
|
+
Marshal.load(dump) if dump
|
10
|
+
end
|
11
|
+
def write key, value, expires_in
|
12
|
+
@client.pipelined do
|
13
|
+
#@client.multi do
|
14
|
+
@client.set key, Marshal.dump(value)
|
15
|
+
@client.expire key, expires_in
|
16
|
+
#end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def delete key
|
20
|
+
@client.del key
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Redirect code from:
|
2
|
+
# http://railstips.org/blog/archives/2009/03/04/following-redirects-with-nethttp/
|
3
|
+
class Resterl::Request
|
4
|
+
attr_accessor :rest_client, :url, :body, :redirect_limit, :response
|
5
|
+
DEFAULT_HEADERS = {}
|
6
|
+
|
7
|
+
def initialize client, url, query_params, headers
|
8
|
+
@rest_client = client
|
9
|
+
@url = url
|
10
|
+
@query_params = query_params
|
11
|
+
@redirect_limit = @rest_client.options[:max_redirect_depth]
|
12
|
+
@headers = DEFAULT_HEADERS.merge headers
|
13
|
+
end
|
14
|
+
def perform
|
15
|
+
raise TooManyRedirects if redirect_limit < 0
|
16
|
+
|
17
|
+
# build URL
|
18
|
+
#complete_url = url.dup
|
19
|
+
#complete_url << "?#{query_param_string}" unless query_param_string.blank?
|
20
|
+
#puts complete_url
|
21
|
+
uri = URI.parse(url)#complete_url)
|
22
|
+
#puts uri.path
|
23
|
+
|
24
|
+
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
apply_ssl http, uri
|
27
|
+
|
28
|
+
path_with_query = uri.path
|
29
|
+
path_with_query << "?#{query_param_string}" unless query_param_string.blank?
|
30
|
+
request = Net::HTTP::Get.new path_with_query, @headers
|
31
|
+
apply_basic_auth request
|
32
|
+
self.response = http.request(request)
|
33
|
+
|
34
|
+
# Follow redirects
|
35
|
+
if response.is_a?(Net::HTTPRedirection) &&
|
36
|
+
!response.is_a?(Net::HTTPNotModified)
|
37
|
+
self.url = redirect_url
|
38
|
+
self.redirect_limit -= 1
|
39
|
+
perform
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def query_param_string
|
47
|
+
@query_param_string ||= begin
|
48
|
+
@query_params.collect do |key, value|
|
49
|
+
"#{URI.escape(key.to_s)}=#{URI.escape(value.to_s)}"
|
50
|
+
end.join('&')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def redirect_url
|
55
|
+
if response['location'].nil?
|
56
|
+
response.body.match(/<a href=\"([^>]+)\">/i)[1]
|
57
|
+
else
|
58
|
+
response['location']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def apply_ssl http, uri
|
63
|
+
if uri.is_a? URI::HTTPS
|
64
|
+
http.use_ssl = true
|
65
|
+
http.verify_mode = rest_client.options[:ssl_verify_mode]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
def apply_basic_auth request
|
69
|
+
ba = rest_client.options[:basic_auth]
|
70
|
+
request.basic_auth(ba[:username], ba[:password]) if ba
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Resterl::Response
|
2
|
+
attr_reader :body, :expires_at, :net_http_response
|
3
|
+
|
4
|
+
def initialize(r)
|
5
|
+
@net_http_response = r
|
6
|
+
@body = r.body
|
7
|
+
#@expires_in = extract_max_age
|
8
|
+
@expires_at = Time.now + extract_max_age
|
9
|
+
end
|
10
|
+
|
11
|
+
def expired?
|
12
|
+
@expires_at < Time.now
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_expires_at t
|
16
|
+
@expires_at = t
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_max_age
|
22
|
+
cc = @net_http_response['Cache-Control']
|
23
|
+
cc.is_a?(String) ? cc[/max-age=(\d+)/, 1].to_i : 0
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# From:
|
2
|
+
# http://github.com/der-flo/localmemcache_store/blob/master/lib/expiry_cache.rb
|
3
|
+
|
4
|
+
class Resterl::SimpleCache < Resterl::CacheInterface
|
5
|
+
|
6
|
+
class Entry < Struct.new(:data, :expires_at)
|
7
|
+
def expired?
|
8
|
+
expires_at && expires_at <= Time.now
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize options = {}
|
13
|
+
@options = {
|
14
|
+
:expiration_check_interval => 1_000,
|
15
|
+
:cache_key_prefix => 'RESTERL_'
|
16
|
+
}.merge options
|
17
|
+
@expiration_check_counter = 0
|
18
|
+
@data = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def read key
|
22
|
+
key = internal_key key
|
23
|
+
#ap "in read #{key}"
|
24
|
+
|
25
|
+
do_expiration_check
|
26
|
+
entry = @data[key]
|
27
|
+
|
28
|
+
# return if nothing in cache
|
29
|
+
return nil unless entry
|
30
|
+
|
31
|
+
# entry expired?
|
32
|
+
if verify_entry_not_expired(key, entry)
|
33
|
+
entry.data
|
34
|
+
else
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def write key, value, expires_in = nil
|
40
|
+
key = internal_key key
|
41
|
+
|
42
|
+
do_expiration_check
|
43
|
+
#value.freeze
|
44
|
+
|
45
|
+
# calculate expiration
|
46
|
+
expires_at = if expires_in.to_i > 0
|
47
|
+
Time.now + expires_in.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
# store data
|
51
|
+
if expires_at.nil? || expires_at > Time.now
|
52
|
+
entry = Entry.new(value, expires_at)
|
53
|
+
@data[key] = entry
|
54
|
+
end
|
55
|
+
|
56
|
+
value
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete key
|
60
|
+
key = internal_key key
|
61
|
+
|
62
|
+
@data.delete key
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def verify_key_not_expired key
|
68
|
+
entry = @cache[key]
|
69
|
+
verify_entry_not_expired(key, entry) if entry
|
70
|
+
end
|
71
|
+
|
72
|
+
def verify_entry_not_expired key, entry
|
73
|
+
if entry.expired?
|
74
|
+
@data.delete(key)
|
75
|
+
false
|
76
|
+
else
|
77
|
+
true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def do_expiration_check
|
82
|
+
@expiration_check_counter += 1
|
83
|
+
unless @expiration_check_counter >= @options[:expiration_check_interval]
|
84
|
+
return
|
85
|
+
end
|
86
|
+
@expiration_check_counter = 0
|
87
|
+
expire_random_entries
|
88
|
+
end
|
89
|
+
|
90
|
+
def expire_random_entries count = 1_000
|
91
|
+
[count, @data.length].min.times do
|
92
|
+
key, entry = @data.random_pair
|
93
|
+
break if key.nil?
|
94
|
+
verify_entry_not_expired key, entry
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def expire_some_entries count = 100
|
99
|
+
count = [count, @data.length].min
|
100
|
+
@data.each_pair do |key, value|
|
101
|
+
break if count <= 0
|
102
|
+
count -= 1 unless verify_entry_not_expired(key, entry)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def internal_key key
|
107
|
+
"#{@options[:cache_key_prefix]}#{key}"
|
108
|
+
end
|
109
|
+
end
|
data/lib/resterl.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'yajl/json_gem'
|
4
|
+
################################################################################
|
5
|
+
module Resterl; end
|
6
|
+
################################################################################
|
7
|
+
#require 'resterl/class_level_inheritable_attributes'
|
8
|
+
require 'resterl/cache_interface'
|
9
|
+
require 'resterl/redis_cache'
|
10
|
+
require 'resterl/simple_cache'
|
11
|
+
require 'resterl/client'
|
12
|
+
require 'resterl/request'
|
13
|
+
require 'resterl/response'
|
14
|
+
require 'resterl/base_object'
|
15
|
+
################################################################################
|
16
|
+
Net::HTTP.version_1_1
|
17
|
+
################################################################################
|
18
|
+
|
19
|
+
# TODOs Prio 2:
|
20
|
+
# * Nach Möglichkeit unsere Bibliothek auf Basis von Faraday
|
21
|
+
# * Caching mit Tests absichern
|
22
|
+
# * Objekte auch in den Cache? Ja, im Idealfall nur die Objekte
|
23
|
+
# * Komplettes User-Framework
|
24
|
+
# * Memoization
|
25
|
+
# * Eigener Client?
|
26
|
+
# * Cookie mit remember-Token?
|
27
|
+
# * Persistente Verbindungen
|
28
|
+
|
29
|
+
# TODOs ID-Service-Integration
|
30
|
+
# * Anforderungen in Kunden-DB-2 prüfen
|
31
|
+
# * Zentrale Frage: Fallback-Lösung notwendig?
|
32
|
+
# * Eher zweiten ID-Server?
|
33
|
+
|
34
|
+
|
35
|
+
# Composition-Pattern?
|
36
|
+
|
37
|
+
|
38
|
+
=begin
|
39
|
+
Beispiel Kunden-DB:
|
40
|
+
|
41
|
+
User-Model
|
42
|
+
* Holt prename, email, wiki_name
|
43
|
+
* Hat in der Tabelle login
|
44
|
+
* Merkt sich den User über ein remember_token in einem Cookie
|
45
|
+
|
46
|
+
Zusätzlich lib/authenticated_system.rb
|
47
|
+
|
48
|
+
=end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
=begin
|
54
|
+
http://www.slideshare.net/pengwynn/json-and-the-apinauts
|
55
|
+
|
56
|
+
Transports
|
57
|
+
|
58
|
+
Net::HTTP
|
59
|
+
Patron http://toland.github.com/patron/
|
60
|
+
Typhoeus http://github.com/pauldix/typhoeus
|
61
|
+
em-http-request http://github.com/igrigorik/em-http-request
|
62
|
+
|
63
|
+
Parsers
|
64
|
+
|
65
|
+
Crack http://github.com/jnunemaker/crack
|
66
|
+
yajl-ruby http://github.com/brainmario/yajl-ruby
|
67
|
+
multi_json http://github.com/intridea/multi_json
|
68
|
+
|
69
|
+
|
70
|
+
Higher Level Libs
|
71
|
+
|
72
|
+
HTTParty http://github.com/jnunemaker/httparty
|
73
|
+
monster_mash http://github.com/dbalatero/monster_mash
|
74
|
+
RestClient http://github.com/adamwiggins/rest-client
|
75
|
+
Weary http://github.com/mwunsch/weary
|
76
|
+
RackClient http://github.com/halorgium/rack-client
|
77
|
+
Faraday http://github.com/technoweenie/faraday
|
78
|
+
Faraday Middleware http://github.com/pengwynn/faraday-middleware
|
79
|
+
|
80
|
+
|
81
|
+
Tools
|
82
|
+
|
83
|
+
Hashie
|
84
|
+
hurl
|
85
|
+
HTTPScoop
|
86
|
+
Charles Proxy
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
url = 'http://api.twitter.com/1'
|
91
|
+
conn = Faraday::Connection.new(:url => url ) do |builder|
|
92
|
+
builder.adapter Faraday.default_adapter
|
93
|
+
builder.use Faraday::Response::MultiJson
|
94
|
+
builder.use Faraday::Response::Mashify
|
95
|
+
end
|
96
|
+
|
97
|
+
resp = conn.get do |req|
|
98
|
+
req.url '/users/show.json', :screen_name => 'pengwynn'
|
99
|
+
end
|
100
|
+
|
101
|
+
u = resp.body
|
102
|
+
u.name
|
103
|
+
# => "Wynn Netherland"
|
104
|
+
|
105
|
+
|
106
|
+
=end
|
data/resterl.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{resterl}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Florian Dütsch"]
|
12
|
+
s.date = %q{2010-09-29}
|
13
|
+
s.description = %q{Rudimentary HTTP client with focus on caching}
|
14
|
+
s.email = %q{florian.duetsch@nix-wie-weg.de}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc",
|
18
|
+
"TODO"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"TODO",
|
27
|
+
"VERSION",
|
28
|
+
"lib/resterl.rb",
|
29
|
+
"lib/resterl/base_object.rb",
|
30
|
+
"lib/resterl/cache_interface.rb",
|
31
|
+
"lib/resterl/client.rb",
|
32
|
+
"lib/resterl/redis_cache.rb",
|
33
|
+
"lib/resterl/request.rb",
|
34
|
+
"lib/resterl/response.rb",
|
35
|
+
"lib/resterl/simple_cache.rb",
|
36
|
+
"resterl.gemspec",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_resterl.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://nix-wie-weg.de/}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
44
|
+
s.summary = %q{Rudimentary HTTP client with focus on caching}
|
45
|
+
s.test_files = [
|
46
|
+
"test/helper.rb",
|
47
|
+
"test/test_resterl.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<hashie>, ["~> 0.4.0"])
|
56
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
59
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
63
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resterl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Florian D\xC3\xBCtsch"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-29 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: hashie
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 4
|
31
|
+
- 0
|
32
|
+
version: 0.4.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yajl-ruby
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 7
|
46
|
+
- 7
|
47
|
+
version: 0.7.7
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Rudimentary HTTP client with focus on caching
|
51
|
+
email: florian.duetsch@nix-wie-weg.de
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- TODO
|
60
|
+
files:
|
61
|
+
- .document
|
62
|
+
- .gitignore
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- TODO
|
67
|
+
- VERSION
|
68
|
+
- lib/resterl.rb
|
69
|
+
- lib/resterl/base_object.rb
|
70
|
+
- lib/resterl/cache_interface.rb
|
71
|
+
- lib/resterl/client.rb
|
72
|
+
- lib/resterl/redis_cache.rb
|
73
|
+
- lib/resterl/request.rb
|
74
|
+
- lib/resterl/response.rb
|
75
|
+
- lib/resterl/simple_cache.rb
|
76
|
+
- resterl.gemspec
|
77
|
+
- test/helper.rb
|
78
|
+
- test/test_resterl.rb
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://nix-wie-weg.de/
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- --charset=UTF-8
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Rudimentary HTTP client with focus on caching
|
111
|
+
test_files:
|
112
|
+
- test/helper.rb
|
113
|
+
- test/test_resterl.rb
|