resterl 0.0.1 → 0.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/LICENSE +1 -1
- data/README.rdoc +6 -4
- data/Rakefile +8 -9
- data/{TODO → TODO.rdoc} +2 -0
- data/VERSION +1 -1
- data/lib/resterl.rb +11 -93
- data/lib/resterl/base_object.rb +4 -2
- data/lib/resterl/{cache_interface.rb → caches/cache_interface.rb} +1 -1
- data/lib/resterl/caches/key_prefix_decorator.rb +21 -0
- data/lib/resterl/caches/rails_memcached_cache.rb +14 -0
- data/lib/resterl/{redis_cache.rb → caches/redis_cache.rb} +1 -1
- data/lib/resterl/{simple_cache.rb → caches/simple_cache.rb} +1 -1
- data/lib/resterl/class_level_inheritable_attributes.rb +28 -0
- data/lib/resterl/client.rb +1 -1
- data/resterl.gemspec +14 -10
- data/test/test_resterl.rb +14 -2
- metadata +29 -14
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= resterl
|
2
2
|
|
3
|
-
|
3
|
+
resterl is a rudimentary HTTP client with focus on caching.
|
4
|
+
Please consider this library as beta, see TODO.rdoc for open issues.
|
4
5
|
|
5
6
|
== Note on Patches/Pull Requests
|
6
7
|
|
@@ -9,9 +10,10 @@ Description goes here.
|
|
9
10
|
* Add tests for it. This is important so I don't break it in a
|
10
11
|
future version unintentionally.
|
11
12
|
* 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
|
13
|
-
|
13
|
+
(if you want to have your own version, that is fine but bump version in a commit
|
14
|
+
by itself I can ignore when I pull)
|
15
|
+
* Send us a pull request. Bonus points for topic branches.
|
14
16
|
|
15
17
|
== Copyright
|
16
18
|
|
17
|
-
Copyright (c) 2010
|
19
|
+
Copyright (c) 2010 Nix-wie-weg Reisen GmbH & Co. KG. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,20 +5,19 @@ require 'rake'
|
|
5
5
|
begin
|
6
6
|
require 'jeweler'
|
7
7
|
Jeweler::Tasks.new do |gem|
|
8
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20
|
9
|
+
# for additional settings
|
10
|
+
|
8
11
|
gem.name = "resterl"
|
9
12
|
gem.summary = %Q{Rudimentary HTTP client with focus on caching}
|
10
|
-
|
13
|
+
# TODO Prio 2
|
14
|
+
#gem.description = %Q{}
|
11
15
|
gem.email = "florian.duetsch@nix-wie-weg.de"
|
12
|
-
gem.homepage = "http://
|
16
|
+
gem.homepage = "http://github.com/Nix-wie-weg/resterl"
|
13
17
|
gem.authors = ["Florian Dütsch"]
|
14
18
|
|
15
|
-
#
|
16
|
-
|
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?
|
19
|
+
# Dependencies
|
20
|
+
gem.add_development_dependency 'shoulda'
|
22
21
|
gem.add_dependency 'hashie', '~> 0.4.0'
|
23
22
|
gem.add_dependency 'yajl-ruby', '~> 0.7.7'
|
24
23
|
end
|
data/{TODO → TODO.rdoc}
RENAMED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/resterl.rb
CHANGED
@@ -3,104 +3,22 @@ require 'net/https'
|
|
3
3
|
require 'yajl/json_gem'
|
4
4
|
################################################################################
|
5
5
|
module Resterl; end
|
6
|
+
module Resterl::Caches; end
|
6
7
|
################################################################################
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require 'resterl/
|
8
|
+
require 'resterl/class_level_inheritable_attributes'
|
9
|
+
|
10
|
+
# Caches
|
11
|
+
require 'resterl/caches/cache_interface'
|
12
|
+
require 'resterl/caches/redis_cache'
|
13
|
+
require 'resterl/caches/simple_cache'
|
14
|
+
require 'resterl/caches/rails_memcached_cache'
|
15
|
+
require 'resterl/caches/key_prefix_decorator'
|
16
|
+
|
11
17
|
require 'resterl/client'
|
12
18
|
require 'resterl/request'
|
13
19
|
require 'resterl/response'
|
14
20
|
require 'resterl/base_object'
|
21
|
+
|
15
22
|
################################################################################
|
16
23
|
Net::HTTP.version_1_1
|
17
24
|
################################################################################
|
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/lib/resterl/base_object.rb
CHANGED
@@ -2,8 +2,10 @@ require 'hashie'
|
|
2
2
|
|
3
3
|
class Resterl::BaseObject #< Hashie::Mash
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
include ClassLevelInheritableAttributes
|
6
|
+
inheritable_attributes :resterl_client, :parser, :complete_mime_type,
|
7
|
+
:mapper
|
8
|
+
|
7
9
|
#self.resterl_client = nil
|
8
10
|
#self.complete_mime_type = 'text/plain'
|
9
11
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Resterl::Caches::KeyPrefixDecorator < Resterl::Caches::CacheInterface
|
2
|
+
def initialize cache, key_prefix
|
3
|
+
@cache = cache
|
4
|
+
@key_prefix = key_prefix
|
5
|
+
end
|
6
|
+
def read key
|
7
|
+
@cache.read key_ext(key)
|
8
|
+
end
|
9
|
+
def write key, value, expires_in
|
10
|
+
@cache.write key_ext(key), value, expires_in
|
11
|
+
end
|
12
|
+
def delete key
|
13
|
+
@cache.delete key_ext(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def key_ext key
|
19
|
+
"#{@key_prefix}#{key}"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
class Resterl::Caches::RailsMemcachedCache < Resterl::Caches::CacheInterface
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def initialize client
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def_delegators :@client, :read, :delete
|
10
|
+
|
11
|
+
def write key, value, expires_in
|
12
|
+
@client.write key, value, :expires_in => expires_in
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# From:
|
2
2
|
# http://github.com/der-flo/localmemcache_store/blob/master/lib/expiry_cache.rb
|
3
3
|
|
4
|
-
class Resterl::SimpleCache < Resterl::CacheInterface
|
4
|
+
class Resterl::Caches::SimpleCache < Resterl::Caches::CacheInterface
|
5
5
|
|
6
6
|
class Entry < Struct.new(:data, :expires_at)
|
7
7
|
def expired?
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# From:
|
2
|
+
# http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/
|
3
|
+
module ClassLevelInheritableAttributes
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def inheritable_attributes(*args)
|
10
|
+
@inheritable_attributes ||= [:inheritable_attributes]
|
11
|
+
@inheritable_attributes += args
|
12
|
+
args.each do |arg|
|
13
|
+
class_eval %(
|
14
|
+
class << self; attr_accessor :#{arg} end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
@inheritable_attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
def inherited(subclass)
|
21
|
+
@inheritable_attributes.each do |inheritable_attribute|
|
22
|
+
instance_var = "@#{inheritable_attribute}"
|
23
|
+
subclass.instance_variable_set(instance_var,
|
24
|
+
instance_variable_get(instance_var))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/resterl/client.rb
CHANGED
@@ -2,7 +2,7 @@ class Resterl::Client
|
|
2
2
|
attr_reader :options
|
3
3
|
DEFAULTS = {
|
4
4
|
:max_redirect_depth => 10,
|
5
|
-
:cache => Resterl::SimpleCache.new,
|
5
|
+
:cache => Resterl::Caches::SimpleCache.new,
|
6
6
|
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
7
7
|
:expiry_multiplier => 10,
|
8
8
|
:minimum_cache_lifetime => 5 * 60 # 5 Minuten
|
data/resterl.gemspec
CHANGED
@@ -5,17 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{resterl}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Florian Dütsch"]
|
12
|
-
s.date = %q{2010-09-
|
13
|
-
s.description = %q{Rudimentary HTTP client with focus on caching}
|
12
|
+
s.date = %q{2010-09-30}
|
14
13
|
s.email = %q{florian.duetsch@nix-wie-weg.de}
|
15
14
|
s.extra_rdoc_files = [
|
16
15
|
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
"TODO"
|
16
|
+
"README.rdoc"
|
19
17
|
]
|
20
18
|
s.files = [
|
21
19
|
".document",
|
@@ -23,21 +21,24 @@ Gem::Specification.new do |s|
|
|
23
21
|
"LICENSE",
|
24
22
|
"README.rdoc",
|
25
23
|
"Rakefile",
|
26
|
-
"TODO",
|
24
|
+
"TODO.rdoc",
|
27
25
|
"VERSION",
|
28
26
|
"lib/resterl.rb",
|
29
27
|
"lib/resterl/base_object.rb",
|
30
|
-
"lib/resterl/cache_interface.rb",
|
28
|
+
"lib/resterl/caches/cache_interface.rb",
|
29
|
+
"lib/resterl/caches/key_prefix_decorator.rb",
|
30
|
+
"lib/resterl/caches/rails_memcached_cache.rb",
|
31
|
+
"lib/resterl/caches/redis_cache.rb",
|
32
|
+
"lib/resterl/caches/simple_cache.rb",
|
33
|
+
"lib/resterl/class_level_inheritable_attributes.rb",
|
31
34
|
"lib/resterl/client.rb",
|
32
|
-
"lib/resterl/redis_cache.rb",
|
33
35
|
"lib/resterl/request.rb",
|
34
36
|
"lib/resterl/response.rb",
|
35
|
-
"lib/resterl/simple_cache.rb",
|
36
37
|
"resterl.gemspec",
|
37
38
|
"test/helper.rb",
|
38
39
|
"test/test_resterl.rb"
|
39
40
|
]
|
40
|
-
s.homepage = %q{http://
|
41
|
+
s.homepage = %q{http://github.com/Nix-wie-weg/resterl}
|
41
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
43
|
s.require_paths = ["lib"]
|
43
44
|
s.rubygems_version = %q{1.3.7}
|
@@ -52,13 +53,16 @@ Gem::Specification.new do |s|
|
|
52
53
|
s.specification_version = 3
|
53
54
|
|
54
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
55
57
|
s.add_runtime_dependency(%q<hashie>, ["~> 0.4.0"])
|
56
58
|
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
57
59
|
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
61
|
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
59
62
|
s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
60
63
|
end
|
61
64
|
else
|
65
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
62
66
|
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
63
67
|
s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
|
64
68
|
end
|
data/test/test_resterl.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestResterl < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
should 'load successfully' do
|
6
|
+
dummy = nil
|
7
|
+
cache = Resterl::Caches::KeyPrefixDecorator.new(
|
8
|
+
Resterl::Caches::RailsMemcachedCache.new(dummy),
|
9
|
+
'prefix_'
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
ODIN_CLIENT = Resterl::Client.new(
|
14
|
+
:base_uri => 'http://www.google.com/',
|
15
|
+
:cache => cache
|
16
|
+
)
|
6
17
|
end
|
18
|
+
|
7
19
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Florian D\xC3\xBCtsch"
|
@@ -14,13 +14,26 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: shoulda
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hashie
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
24
37
|
none: false
|
25
38
|
requirements:
|
26
39
|
- - ~>
|
@@ -31,11 +44,11 @@ dependencies:
|
|
31
44
|
- 0
|
32
45
|
version: 0.4.0
|
33
46
|
type: :runtime
|
34
|
-
version_requirements: *
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: yajl-ruby
|
37
50
|
prerelease: false
|
38
|
-
requirement: &
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
52
|
none: false
|
40
53
|
requirements:
|
41
54
|
- - ~>
|
@@ -46,8 +59,8 @@ dependencies:
|
|
46
59
|
- 7
|
47
60
|
version: 0.7.7
|
48
61
|
type: :runtime
|
49
|
-
version_requirements: *
|
50
|
-
description:
|
62
|
+
version_requirements: *id003
|
63
|
+
description:
|
51
64
|
email: florian.duetsch@nix-wie-weg.de
|
52
65
|
executables: []
|
53
66
|
|
@@ -56,28 +69,30 @@ extensions: []
|
|
56
69
|
extra_rdoc_files:
|
57
70
|
- LICENSE
|
58
71
|
- README.rdoc
|
59
|
-
- TODO
|
60
72
|
files:
|
61
73
|
- .document
|
62
74
|
- .gitignore
|
63
75
|
- LICENSE
|
64
76
|
- README.rdoc
|
65
77
|
- Rakefile
|
66
|
-
- TODO
|
78
|
+
- TODO.rdoc
|
67
79
|
- VERSION
|
68
80
|
- lib/resterl.rb
|
69
81
|
- lib/resterl/base_object.rb
|
70
|
-
- lib/resterl/cache_interface.rb
|
82
|
+
- lib/resterl/caches/cache_interface.rb
|
83
|
+
- lib/resterl/caches/key_prefix_decorator.rb
|
84
|
+
- lib/resterl/caches/rails_memcached_cache.rb
|
85
|
+
- lib/resterl/caches/redis_cache.rb
|
86
|
+
- lib/resterl/caches/simple_cache.rb
|
87
|
+
- lib/resterl/class_level_inheritable_attributes.rb
|
71
88
|
- lib/resterl/client.rb
|
72
|
-
- lib/resterl/redis_cache.rb
|
73
89
|
- lib/resterl/request.rb
|
74
90
|
- lib/resterl/response.rb
|
75
|
-
- lib/resterl/simple_cache.rb
|
76
91
|
- resterl.gemspec
|
77
92
|
- test/helper.rb
|
78
93
|
- test/test_resterl.rb
|
79
94
|
has_rdoc: true
|
80
|
-
homepage: http://
|
95
|
+
homepage: http://github.com/Nix-wie-weg/resterl
|
81
96
|
licenses: []
|
82
97
|
|
83
98
|
post_install_message:
|