atomutil 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/README.txt +19 -2
- data/lib/atomutil.rb +18 -12
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
|
2
|
+
== 0.0.4 2008-02-12
|
3
|
+
|
4
|
+
* bugfix: SimpleCache - fixed typo
|
5
|
+
CacheResource - fixed type
|
6
|
+
ServiceInfoStorage#clone_collection now returns new collections correctly.
|
7
|
+
ServiceInfo#accepts_media_type? works as expected now.
|
8
|
+
added credential control on Atompub::Client#delete_resource
|
9
|
+
approved error messages.
|
10
|
+
|
2
11
|
== 0.0.3 2008-02-12
|
3
12
|
|
4
13
|
* bugfix: now this handle URL which has query correctly.
|
data/README.txt
CHANGED
@@ -551,8 +551,8 @@ Then feed includes
|
|
551
551
|
At first, construct appropriate authorizer
|
552
552
|
At this time, let's assume that we're requried WSSE Authentication.
|
553
553
|
Of cource, you can choose other authorizer,
|
554
|
-
for example,
|
555
|
-
and in future,
|
554
|
+
for example, Atompub::Auth::Basic(Basic authentication),
|
555
|
+
and in future, Atompub::Auth::OAuth, Atompub::Auth::OpenID, and etc.
|
556
556
|
|
557
557
|
auth = Atompub::Auth::Wsse.new :username => 'myname', :password => 'mypass'
|
558
558
|
|
@@ -612,6 +612,23 @@ and in future, Atom::Auth::OAuth, Atom::Auth::OpenID, and etc.
|
|
612
612
|
|
613
613
|
feed_contains_media_entreis = client.get_feed( media_collection_uri )
|
614
614
|
|
615
|
+
== CONTROL CACHING
|
616
|
+
|
617
|
+
To handle data for controlling cache, for example, ETag or If-Modified-Since,
|
618
|
+
Set Atompub::SimpleCache class's object for client initialization.
|
619
|
+
If you don't pass, Atompub::AbstractCache is set by default.
|
620
|
+
|
621
|
+
SimpleCache provides a simple on-memory caching, merely using hash to
|
622
|
+
store Etag and If-Modified-Since data.
|
623
|
+
|
624
|
+
Define new class inheriting AbstractCache,
|
625
|
+
if you need more flexible cache controller, for example,
|
626
|
+
using file, database, or memcached, etc.
|
627
|
+
|
628
|
+
cache = Atompub::SimpleCache.new
|
629
|
+
auth = Atompub::Auth::Wsse.new :username => 'username', :password => 'password'
|
630
|
+
client = Atompub::Client.new :auth => auth, :cache => cache
|
631
|
+
|
615
632
|
= TO DO
|
616
633
|
|
617
634
|
* More document
|
data/lib/atomutil.rb
CHANGED
@@ -55,7 +55,7 @@ module AtomUtil
|
|
55
55
|
module VERSION#:nodoc:
|
56
56
|
MAJOR = 0
|
57
57
|
MINOR = 0
|
58
|
-
TINY =
|
58
|
+
TINY = 4
|
59
59
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
60
60
|
end
|
61
61
|
end
|
@@ -1129,7 +1129,7 @@ module Atompub
|
|
1129
1129
|
attr_accessor :etag, :last_modified, :resource
|
1130
1130
|
def initialize(params)
|
1131
1131
|
@etag = params[:etag]
|
1132
|
-
@last_modified =
|
1132
|
+
@last_modified = params[:last_modified]
|
1133
1133
|
@resource = params[:rc]
|
1134
1134
|
end
|
1135
1135
|
end
|
@@ -1177,7 +1177,7 @@ module Atompub
|
|
1177
1177
|
end
|
1178
1178
|
# Pick cache resource from hash for indicated uri.
|
1179
1179
|
def get(uri)
|
1180
|
-
@cache.has_key?(
|
1180
|
+
@cache.has_key?(uri) ? @cache[uri] : nil
|
1181
1181
|
end
|
1182
1182
|
# Set cache resource into hash.
|
1183
1183
|
def put(uri, params)
|
@@ -1217,7 +1217,7 @@ module Atompub
|
|
1217
1217
|
return true if @collection.nil?
|
1218
1218
|
if @accepts.nil?
|
1219
1219
|
@accepts = @collection.accepts.collect do |accept|
|
1220
|
-
accept.split(/[\s,]+/)
|
1220
|
+
accept.text.split(/[\s,]+/)
|
1221
1221
|
end.flatten
|
1222
1222
|
@accepts << Atom::MediaType::ENTRY if @accepts.empty?
|
1223
1223
|
end
|
@@ -1245,8 +1245,8 @@ module Atompub
|
|
1245
1245
|
end
|
1246
1246
|
|
1247
1247
|
def put(uri, collection, client=nil)
|
1248
|
-
|
1249
|
-
@info[uri] = ServiceInfo.new(:collection =>
|
1248
|
+
new_collection = clone_collection(collection, client)
|
1249
|
+
@info[uri] = ServiceInfo.new(:collection => new_collection)
|
1250
1250
|
end
|
1251
1251
|
|
1252
1252
|
private
|
@@ -1254,13 +1254,14 @@ module Atompub
|
|
1254
1254
|
coll = Atom::Collection.new
|
1255
1255
|
coll.title = collection.title
|
1256
1256
|
coll.href = collection.href
|
1257
|
-
collection.accepts.each { |a| coll.add_accept a }
|
1257
|
+
collection.accepts.each { |a| coll.add_accept a.text }
|
1258
1258
|
collection.categories_list.each do |cats|
|
1259
1259
|
unless cats.nil?
|
1260
1260
|
new_cats = cats.href.nil?? clone_categories(cats) : get_categories(cats.href, client)
|
1261
1261
|
coll.categories = new_cats unless new_cats.nil?
|
1262
1262
|
end
|
1263
1263
|
end
|
1264
|
+
coll
|
1264
1265
|
end
|
1265
1266
|
|
1266
1267
|
def get_categories(uri, client=nil)
|
@@ -1305,7 +1306,7 @@ module Atompub
|
|
1305
1306
|
throw ArgumentError.new("Atompub::Client needs :auth as argument for constructor.")
|
1306
1307
|
end
|
1307
1308
|
@auth = params[:auth]
|
1308
|
-
@cache = params.has_key?(:cache) && params[:
|
1309
|
+
@cache = params.has_key?(:cache) && params[:cache].kind_of?(AbstractCache) ? params[:cache] : AbstractCache.instance
|
1309
1310
|
@service_info = params.has_key?(:info) && params[:info].kind_of?(ServiceInfoStorage) ? params[:info] : ServiceInfoStorage.instance
|
1310
1311
|
@http_class = Net::HTTP
|
1311
1312
|
@agent = "Atompub::Client/#{AtomUtil::VERSION}"
|
@@ -1434,7 +1435,10 @@ module Atompub
|
|
1434
1435
|
file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname)
|
1435
1436
|
stream = file_path.open { |f| f.binmode; f.read }
|
1436
1437
|
service = @service_info.get(media_uri)
|
1437
|
-
|
1438
|
+
if service.nil?
|
1439
|
+
raise RequestError, "Service information not found. Get service document before you do create_media."
|
1440
|
+
end
|
1441
|
+
unless service.accepts_media_type?(content_type)
|
1438
1442
|
raise RequestError, "Unsupported Media Type: #{content_type}"
|
1439
1443
|
end
|
1440
1444
|
create_resource(media_uri, stream, content_type, slug)
|
@@ -1574,7 +1578,8 @@ module Atompub
|
|
1574
1578
|
}
|
1575
1579
|
end
|
1576
1580
|
else
|
1577
|
-
|
1581
|
+
error_message = @res.body.nil?? "#{@res.code}" : "#{@res.code} / #{@res.body}"
|
1582
|
+
raise RequestError, "Failed to create resource. #{error_message}"
|
1578
1583
|
end
|
1579
1584
|
end
|
1580
1585
|
end
|
@@ -1595,7 +1600,7 @@ module Atompub
|
|
1595
1600
|
@res = http.request(@req)
|
1596
1601
|
case @res
|
1597
1602
|
when Net::HTTPSuccess
|
1598
|
-
warn "Bad Status Code" unless @res.class == Net::HTTPOK
|
1603
|
+
warn "Bad Status Code: #{@res.code}" unless @res.class == Net::HTTPOK || @res.class == Net::HTTPNoContent
|
1599
1604
|
unless @res.body.nil?
|
1600
1605
|
@rc = Atom::MediaType::ENTRY.is_a?(@res['Content-Type']) ? Atom::Entry.new(:stream => @res.body) : @res.body
|
1601
1606
|
@cache.put uri.to_s, {
|
@@ -1613,11 +1618,12 @@ module Atompub
|
|
1613
1618
|
clear
|
1614
1619
|
uri = URI.parse(uri)
|
1615
1620
|
@req = Net::HTTP::Delete.new uri.request_uri
|
1621
|
+
set_common_info(@req)
|
1616
1622
|
@http_class.start(uri.host, uri.port) do |http|
|
1617
1623
|
@res = http.request(@req)
|
1618
1624
|
case @res
|
1619
1625
|
when Net::HTTPSuccess
|
1620
|
-
warn "Bad Status Code" unless @res.class == Net::HTTPOK
|
1626
|
+
warn "Bad Status Code: #{@res.code}" unless @res.class == Net::HTTPOK || @res.class == Net::HTTPNoContent
|
1621
1627
|
else
|
1622
1628
|
raise RequestError, "Failed to delete resource. #{@res.code}"
|
1623
1629
|
end
|