atomutil 0.0.9 → 0.1.0

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/README.txt DELETED
@@ -1,635 +0,0 @@
1
- = Utilities for AtomPub / Atom Syndication Format
2
-
3
- This library allows you to handle AtomPub and Atom Syndication Format easily.
4
- Most of the idea is from great Perl modules on CPAN.
5
-
6
- = INSTALLATION
7
-
8
- sudo gem install atomutil
9
-
10
- = SYNOPSIS
11
-
12
- == Building or parsing XML with Atom Syndication Format
13
-
14
- === How To Construct Each Atom Element
15
-
16
- Create new object and setup with each accessor.
17
-
18
- entry = Atom::Entry.new
19
-
20
- entry.title = 'Title!'
21
- entry.summary = 'Summary!'
22
- entry.published = Time.now
23
-
24
- Or you can do that at once with passing hash parameter to constructor
25
-
26
- entry = Atom::Entry.new(
27
- :title => 'Title!',
28
- :summary => 'Summary',
29
- :published => Time.now
30
- )
31
-
32
- And you also can setup new element within a block if you pass one.
33
-
34
- entry = Atom::Entry.new(:title => 'New Entry') do |e|
35
- e.summary = 'New Summary'
36
- author = Atom::Author.new :name => 'John'
37
- e.author = author
38
- e.published = Time.now
39
- end
40
-
41
- And finally you can get xml-document from them.
42
-
43
- xml_string = entry.to_s
44
-
45
- If you pass false to to_s, it returns non-indented string
46
-
47
- xml_string = entry.to_s(false)
48
-
49
- === How To Parse Each Atom XML Document
50
-
51
- xml_string = <<-EOS
52
- <?xml version="1.0" encoding="UTF-8"?>
53
- <entry xmlns="http://www.w3.org/2005/Atom">
54
- <id>tag:example.org,2007-12-01:mybook</id>
55
- <title>Title</title>
56
- <summary>Summary</summary>
57
- <author><name>John</name></author>
58
- </entry>
59
- EOS
60
-
61
- Pass the xml-string to proper Atom Element Class with :stream key
62
-
63
- entry = Atom::Entry.new :stream => xml_string
64
- puts entry.title # Book
65
- puts entry.summary # Summary
66
- puts entry.author.name # John
67
-
68
- Atom::Feed and Atom::Entry can be build from files
69
-
70
- entry = Atom::Feed.new :file => 'my_feed.atom'
71
-
72
- or from uri
73
-
74
- entry = Atom::Feed.new :uri => 'http://example.com/feed.atom'
75
-
76
- == How To Handle other Namespace
77
-
78
- There are times when you want to extend your atom element
79
- with other namespaces.
80
- For example, in case you want to deal pagination with OpenSearch
81
-
82
- xmlstring = <<-EOS
83
- <feed xmlns="http://www.w3.org/2005/Atom"
84
- xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
85
- <openSearch:totalResult>153</openSearch:totalResult>
86
- <openSearch:startIndex>40</openSearch:startIndex>
87
- <openSearch:itemsPerPage>20</openSearch:itemsPerPage>
88
- ...
89
- </feed>
90
- EOS
91
-
92
- How to get these values?
93
- The answer is using 'get' method.
94
- And then, just a reminder, you have to prepare Atom::Namespace object.
95
- Pass the object and element name to the method.
96
- And it returns REXML::Element object.
97
-
98
- feed = Atom::Feed.new :stream => xmlstring
99
- open_search_ns = Atom::Namespace.new(
100
- :prefix => 'openSearch',
101
- :uri => 'http://a9.com/-/spec/opensearchrss/1.1/')
102
-
103
- total = feed.get(open_search_ns, 'totalResult').text.to_i
104
- start = feed.get(open_search_ns, 'startIndex').text.to_i
105
- per_page = feed.get(open_search_ns, 'itemsPerPage').text.to_i
106
-
107
- And of cource, you also can 'set'
108
-
109
- feed = Atom::Feed.new
110
- feed.title = 'my new feed'
111
- feed.set(open_search_ns, 'totalResult', 153)
112
- feed.set(open_search_ns, 'startIndex', 40)
113
- feed.set(open_search_ns, 'itemsPerPage', 20)
114
-
115
- In this example, I take the 'openSearch' for pagination, but it's already implemented with
116
- useful methods.
117
-
118
- feed = Atom::Feed.new
119
- feed.total_results = 35
120
- feed.start_index = 1
121
- feed.items_per_page = 20
122
-
123
- puts feed.total_results
124
- puts feed.start_index
125
- puts feed.items_per_page
126
-
127
- === Build a Service Document
128
-
129
- Create root service element
130
-
131
- service = Atom::Service.new
132
-
133
- Create workspace element which the service appends.
134
-
135
- blog_workspace = Atom::Workspace.new
136
- blog_workspace.title = 'My Blog'
137
-
138
- collection = Atom::Collection.new
139
- collection.href = 'http://blog.example.org/feed'
140
- collection.title = 'Sample Blog'
141
-
142
- Create categories that your collection handles
143
-
144
- cats = Atom::Categories.new
145
- cats.fixed = 'no'
146
-
147
- You can set each concrete categories here
148
-
149
- category1 = Atom::Category.new
150
- category1.term = 'technology'
151
- category2 = Atom::Category.new
152
- category2.term = 'music'
153
- category3 = Atom::Category.new
154
- category3.term = 'sport'
155
- cats.add_category category1
156
- cats.add_category category2
157
- cats.add_category category3
158
-
159
- Or set only href parameter that represents uri for Categories Document,
160
- Instead of setting each categories here.
161
- Then you should provides Categories Document at indicated uri.
162
-
163
- cats.href = 'http://blog.example.org/categories'
164
-
165
- collection.add_categories cats
166
- blog_workspace.add_collection collection
167
- service.add_workspace blog_workspace
168
- service_document_xml_string = service.to_s
169
-
170
- === Build a Categories Document
171
-
172
- cats = Atom::Categories.new
173
- category1 = Atom::Category.new
174
- category1.term = 'technology'
175
- category2 = Atom::Category.new
176
- category2.term = 'music'
177
- category3 = Atom::Category.new
178
- category3.term = 'sport'
179
- cats.add_category category1
180
- cats.add_category category2
181
- cats.add_category category3
182
-
183
- categories_xml_string = cats.to_s
184
-
185
- === Build an Entry
186
-
187
- entry = Atom::Entry.new
188
-
189
- * id
190
- * title
191
- * summary
192
- * rights
193
- * source
194
-
195
- Simple text accessors
196
-
197
- entry.id = 'tag:example.org,2007:example'
198
- entry.title = 'My First Blog Post'
199
- entry.summary = 'This is summary'
200
- entry.rights = 'Copyright(c) 2007 Lyo Kato all rights reserved.'
201
-
202
- * published
203
- * updated
204
-
205
- You can set them with Time class
206
-
207
- entry.published = Time.now
208
- entry.updated = Time.now
209
-
210
- Or you can set with W3CDTF formatted string
211
-
212
- entry.published = "2007-12-01T01:30:00Z"
213
-
214
- And pick it up as Time object
215
-
216
- published = entry.published
217
- puts published.year
218
- puts published.month
219
-
220
- * author
221
- * contributor
222
-
223
- Set person construct with Atom::Person
224
-
225
- person = Atom::Person.new
226
- person.name = 'Lyo Kato'
227
- person.email = 'lyo.kato atmark gmail.com'
228
- person.uri = 'http://www.lyokato.net/'
229
-
230
- entry.author = person.to_author
231
- entry.contributor = person.to_contributor
232
-
233
- Or Atom::Author, Atom::Contributor directly
234
-
235
- cont = Atom::Contributor.new
236
- cont.name = 'Lyo'
237
- cont.email = 'lyo.kato atmark gmail.com'
238
- entry.contributor = cont
239
-
240
- To set multiple data
241
-
242
- entry.add_author author1
243
- entry.add_author author2
244
- entry.add_contributor contributor1
245
- entry.add_contributor contributor2
246
-
247
- Get all authors and contributors
248
-
249
- authors = entry.authors
250
- contributors = entry.contributors
251
-
252
- Get only first author and contributor
253
-
254
- author = entry.author
255
- contributor = entry.contributor
256
-
257
- * link
258
-
259
- Link Element Accessor
260
-
261
- link = Atom::Link.new
262
- link.href = 'http://example.org/entry/1'
263
- link.rel = 'alternate'
264
- link.type = 'text/html'
265
- link.hreflang = 'fr'
266
- link.length = '512'
267
- link.title = 'My Blog Post'
268
- entry.link = link
269
-
270
- You can set multiple links
271
-
272
- entry.add_link link1
273
- entry.add_link link2
274
-
275
- To get all links as an Array
276
-
277
- links = entry.links
278
-
279
- To get first one
280
-
281
- link = entry.link
282
- puts link.href
283
- puts link.rel
284
-
285
- Further more, useful methods are implemented for major 'rel' types.
286
-
287
- entry.alternate_link = 'http://example.org/entry/1'
288
-
289
- This is same as
290
-
291
- link = Atom::Link.new
292
- link.rel = 'alternate'
293
- link.href = 'http://example.org/entry/1'
294
- entry.add_link link
295
-
296
- And
297
-
298
- puts entry.alternate_link # http://example.org/entry1
299
-
300
- This is same as
301
-
302
- links = entry.links
303
- alternate_link = links.select{ |l| l.rel == 'alternate' }.first
304
- puts alternate_link.href
305
-
306
- If it contains multiple 'alternate' links, to get all of them,
307
-
308
- alternate_links = links.alternate_links
309
-
310
- Like this, you can use following methods for each links
311
-
312
- entry.self_link:: <link rel='self' href='...'/>
313
- entry.edit_link:: <link rel='edit' href='...'/>
314
- entry.edit_media_link:: <link rel='edit-media' href='...'/>
315
- entry.enclosure_link:: <link rel='enclosure' href='...'/>
316
- entry.related_link:: <link rel='related' href='...' />
317
- entry.via_link:: <link rel='via' href='...' />
318
- entry.first_link:: <link rel='first' href='...'/>
319
- entry.previous_link:: <link rel='previous' href='...'/>
320
- entry.next_link:: <link rel='next' href='...' />
321
- entry.last_link:: <link rel='last' href='...' />
322
-
323
- * category
324
-
325
- Category Element Accessor
326
-
327
- category = Atom::Category.new
328
- category.term = 'music'
329
- category.scheme = 'http://example.org/category/music'
330
- category.label = 'My Music'
331
- entry.category = category
332
-
333
- You can set multiple categories
334
-
335
- entry.add_category cat1
336
- entry.add_category cat2
337
-
338
- To get all categories as an Array
339
-
340
- categories = entry.categories
341
-
342
- To get first one
343
-
344
- first_category = entry.category
345
- puts first_category.term
346
- puts first_category.scheme
347
-
348
- * content
349
-
350
- You can push it as a text
351
-
352
- entry.content = 'This is a content'
353
-
354
- Or an Atom::Content object
355
-
356
- content = Atom::Content.new :body => 'This is a content'
357
- entry.content = content
358
-
359
- To pick it up
360
-
361
- content = entry.content
362
-
363
- puts content.type
364
- puts content.body
365
-
366
- * control
367
-
368
- Control Element Accessor
369
-
370
- control = Atom::Control.new
371
- control.draft = 'yes'
372
- entry.control = control
373
-
374
- Then entry includes
375
-
376
- <app:control xmlns:app='http://www.w3.org/2007/app'>
377
- <app:draft>yes</app:draft>
378
- </app:control>
379
-
380
- * edited
381
-
382
- Represents what time this entry was edited.
383
-
384
- entry.edited = Time.now
385
-
386
- Then entry includes
387
-
388
- <app:edited>2007-09-01T00:00:00Z</app:edited>
389
-
390
- To pick it up
391
-
392
- edited = entry.edited
393
- puts edited.year
394
- puts edited.month
395
-
396
- You also can handle Atom-Threading
397
- (http://tools.ietf.org/html/rfc4685)
398
-
399
- target = Atom::ReplyTarget.new
400
- target.id = 'tag:example.org,2007:12:example'
401
- target.href = 'http://example.org/blog/2007/12/archive01'
402
- target.type = 'text/xhtml'
403
-
404
- entry.in_reply_to target
405
-
406
- Or you can set the target direclty with hash
407
-
408
- entry.in_reply_to(
409
- :id => 'tag:example.org,2007:12:example',
410
- :href => 'http://example.org/blog/2007/12/archive01',
411
- :type => 'text/xhtml'
412
- )
413
-
414
- And then entry includes xml
415
-
416
- <thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0'
417
- ref='tag:example.org,2007:12:example'
418
- href='http://example.org/blog/2007/12/archive01'
419
- type='text/xhtml'/>
420
-
421
- Pick it up from entry
422
-
423
- target = entry.in_reply_to
424
- puts target.id
425
- puts target.href
426
- puts target.type
427
-
428
- Add a replies link
429
-
430
- link = Atom::RepliesLink.new
431
- link.href = 'http://example.org/entry/1/replies'
432
- link.count = 10
433
- link.updated = Time.now
434
-
435
- entry.add_link link
436
-
437
- Then entry includes
438
-
439
- <link rel='replies' href='http://example.org/entry/1/replies'
440
- thr:count='10' thr:updated='2007-01-01T00:00:00Z'>
441
-
442
- Add total replies count
443
-
444
- entry.total = 10
445
-
446
- Then entry includes
447
-
448
- <thr:total>10</thr:total>
449
-
450
- === Build a Feed
451
-
452
- feed = Atom::Feed.new
453
-
454
- * id
455
- * title
456
- * subtitle
457
- * rights
458
- * icon
459
- * logo
460
- * language
461
- * version
462
-
463
- Simple text accessors
464
-
465
- feed.id = 'tag:example.org,2007:example'
466
- feed.title = 'Example Feed'
467
- feed.subtitle = 'Subtitle of Example Feed'
468
- feed.rights = 'Copyright(c) 2007 example.org all rights reserved'
469
- feed.icon = 'http://example.org/icon.png'
470
- feed.logo = 'http://example.org/logo.png'
471
- feed.language = 'fr'
472
- feed.version = '1.0'
473
-
474
- * updated
475
-
476
- Time accessor
477
-
478
- feed.updated = Time.now
479
- updated = feed.updated
480
- puts updated.year
481
- puts updated.month
482
-
483
- * generator
484
-
485
- You can set generator information
486
-
487
- feed.generator = 'MyGenerator'
488
-
489
- Or more in detail
490
-
491
- generator = Atom::Generator.new(
492
- :name => 'MyGenerator',
493
- :uri => 'http://example.org/mygenerator',
494
- :version => '1.0'
495
- )
496
- feed.generator = generator
497
-
498
- generator = feed.generator
499
- puts generator.name
500
- puts generator.uri
501
- puts generator.version
502
-
503
- * link
504
-
505
- You can set links like you do with entry
506
-
507
- link1 = Atom::Link.new :href => 'http://example.org/entry/1', :rel => 'alternate'
508
- feed.add_link link1
509
-
510
- feed.edit_link = 'http://example.org/entry/1/edit'
511
-
512
- * category
513
-
514
- You can set categoryes like you do with entry
515
-
516
- * author
517
- * contributor
518
-
519
- Person construct data.
520
- You can set authors/contributors on same way for entry.
521
-
522
- * entry
523
-
524
- Entry Accessors
525
-
526
- entry1 = Atom::Entry.new
527
- entry1.title = 'Entry1'
528
-
529
- entry2 = Atom::Entry.new
530
- entry2.title = 'Entry2'
531
-
532
- feed.add_entry entry1
533
- feed.add_entry entry2
534
-
535
- entries = feed.entries
536
-
537
- OpenSeach Pagination Control
538
-
539
- feed.total_results = 35
540
- feed.items_per_page = 10
541
- feed.start_index = 11
542
-
543
- Then feed includes
544
-
545
- <openSearch:totalResults>35</openSearch:totalResults>
546
- <openSearch:itemsPerPage>10</openSearch:itemsPerPage>
547
- <openSearch:startIndex>11</openSearch:startIndex>
548
-
549
- == Using service that provides AtomPub API
550
-
551
- At first, construct appropriate authorizer
552
- At this time, let's assume that we're requried WSSE Authentication.
553
- Of cource, you can choose other authorizer,
554
- for example, Atom::Auth::Basic(Basic authentication),
555
- and in future, Atom::Auth::OAuth, Atom::Auth::OpenID, and etc.
556
-
557
- auth = Atompub::Auth::Wsse.new :username => 'myname', :password => 'mypass'
558
-
559
- client = Atompub::Client.new :auth => auth
560
-
561
- service = client.get_service( 'http://example/service/api/endpoint' )
562
- collection = service.workspaces.first.collection.first
563
- categories = client.get_categories( collection.categories.href )
564
-
565
- categories.categories.each do |category|
566
- puts category.label
567
- puts category.scheme
568
- puts category.term
569
- end
570
-
571
- feed = client.get_feed( collection.href )
572
-
573
- puts feed.title # 'Example Feed'
574
- puts feed.icon # http://example/icon.jpg
575
- puts feed.logo # http://example/logo.jpg
576
-
577
- entries = feed.entries
578
- entries.each do |entry|
579
- puts entry.id
580
- puts entry.title
581
- end
582
-
583
- entry = entries.first
584
- entry.title = 'Changed!'
585
-
586
- client.update_entry( entry.edit_link, entry )
587
-
588
- client.delete_entry( entries[2].edit_link )
589
-
590
- new_entry = Atom::Entry.new
591
- new_entry.title = 'New!'
592
- new_entry.summary = 'New Entry for Example'
593
- new_entry.published = Time.now
594
-
595
- edit_uri = client.create_entry( collection.href, new_entry )
596
-
597
- # you also can use 'slug'
598
- slug = 'new entry'
599
- edit_uri = client.create_entry( collection.href, new_entry, slug )
600
-
601
- media_collection = service.workspaces.first.collections[1]
602
- media_collection_uri = media_collection.href
603
-
604
- media_uri = client.create_media( media_collection_uri, 'foo.jpg', 'image/jpeg')
605
- # with slug
606
- # client.create_media( media_collection_uri, 'foo.jpg', 'image/jpeg', 'new-image')
607
-
608
- media_entry = client.get_entry( media_uri )
609
- edit_media_link = media_entry.edit_media_link
610
- client.update_media( edit_media_link, 'bar.jpg', 'image/jpeg' )
611
- client.delete_media( edit_media_link )
612
-
613
- feed_contains_media_entreis = client.get_feed( media_collection_uri )
614
-
615
- = TO DO
616
-
617
- * More document
618
- * More tests (RSpec)
619
- * Encoding control
620
- * New Auth classes Atompub::Auth::OpenID and Atompub::Auth::OAuth
621
-
622
- = SEE ALSO
623
-
624
- AtomPub Spec(RFC):: http://atompub.org/rfc4287.html
625
- XML::Atom(Perl):: http://search.cpan.org/perldoc?XML%3A%3AAtom
626
- XML::Atom::Service(Perl):: http://search.cpan.org/perldoc?XML%3A%3AAtom%3A%3AService
627
- XML::Atom::Ext::Threading(Perl):: http://search.cpan.org/perldoc?XML%3A%3AAtom%3A%3AExt%3A%3AThreading
628
- Atompub(Perl):: http://search.cpan.org/perldoc?Atompub
629
-
630
- = Author and License
631
-
632
- Author:: Lyo Kato (lyo.kato atmark gmail.com)
633
- Copyright:: Copyright (c) 2007, Lyo Kato All rights reserved.
634
- License:: Ruby License
635
-
data/config/hoe.rb DELETED
@@ -1,71 +0,0 @@
1
- require 'atomutil'
2
-
3
- AUTHOR = 'Lyo Kato' # can also be an array of Authors
4
- EMAIL = "lyo.kato atmark gmail.com"
5
- DESCRIPTION = "Utilities for AtomPub / Atom Syndication Format"
6
- GEM_NAME = 'atomutil' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'atomutil' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "~/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "lyokato"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
-
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
- VERS = AtomUtil::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'atomutil documentation',
36
- "--opname", "index.html",
37
- "--line-numbers",
38
- "--main", "README",
39
- "--inline-source"]
40
-
41
- class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
- @extra_deps
45
- end
46
- end
47
-
48
- # Generate all the Rake tasks
49
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
- p.author = AUTHOR
52
- p.description = DESCRIPTION
53
- p.email = EMAIL
54
- p.summary = DESCRIPTION
55
- p.url = HOMEPATH
56
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
- p.test_globs = ["test/**/test_*.rb"]
58
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
-
60
- # == Optional
61
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
-
64
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
-
66
- end
67
-
68
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
- hoe.rsync_args = '-av --delete --ignore-errors'
@@ -1,17 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'atomutil'