tchak-restbooks 0.1.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.
@@ -0,0 +1,109 @@
1
+ #
2
+ # book.rb
3
+ # restbooks
4
+ #
5
+ # Created by Paul Chavard on 2009-09-12.
6
+ # Copyright 2009
7
+ #
8
+ # This file is part of RestBooks.
9
+ #
10
+ # RestBooks is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # RestBooks is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with RestBooks. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ module RestBooks
25
+ module Models
26
+ class Book
27
+ include RestBooks::Model
28
+ attr_reader :title, :id, :author, :updated, :language, :date, :subject, :description, :rights
29
+
30
+ def initialize( element=nil )
31
+ @updated = Time.now
32
+ @subject = []
33
+ if element
34
+ @element = element
35
+ @element.elements.each do |tag|
36
+ case tag.name
37
+ when 'title'
38
+ @title = tag.text
39
+ when 'id'
40
+ @id = tag.text.split('/').last
41
+ @id = @id.split(':').last if @id.split(':').length > 1
42
+ when 'updated'
43
+ @updated = Date.parse( tag.text )
44
+ when 'author'
45
+ @author = tag.elements['name'].text
46
+ @author_id = tag.elements['uri'].text.split('/').last
47
+ when 'language'
48
+ @language = tag.text
49
+ when 'date'
50
+ @date = tag.text
51
+ when 'subject'
52
+ @subject << tag.text
53
+ when 'description'
54
+ @description = tag.text.strip()
55
+ when 'rights'
56
+ @rights = tag.text
57
+ when 'content'
58
+ @html = tag.text if tag.attributes['type'] == "xhtml"
59
+ end
60
+ end
61
+ else
62
+ @element = REXML::Element.new( 'entry' )
63
+ end
64
+ end
65
+
66
+ # def language=( str )
67
+ # @language = str
68
+ # @element.elements['dc:language'].text = str
69
+ # end
70
+ #
71
+ # def date=( str )
72
+ # @date = str
73
+ # @element.elements['dc:date'].text = str
74
+ # end
75
+ #
76
+ # def subject=( str )
77
+ #
78
+ # end
79
+ #
80
+ # def description=( str )
81
+ # @description = str
82
+ # @element.elements['dc:description'].text = str
83
+ # end
84
+ #
85
+ # def rights=( str )
86
+ # @rights = str
87
+ # @element.elements['dc:rights'].text = str
88
+ # end
89
+
90
+ def to_html
91
+ return @html
92
+ end
93
+
94
+ def to_hash
95
+ return { :title => @title,
96
+ :id => @id,
97
+ :author => @author,
98
+ :author_id => @author_id,
99
+ :updated => @updated,
100
+ :language => @language,
101
+ :date => @date,
102
+ :subject => @subject,
103
+ :description => @description,
104
+ :rights => @rights }
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # category.rb
3
+ # restbooks
4
+ #
5
+ # Created by Paul Chavard on 2009-09-12.
6
+ # Copyright 2009
7
+ #
8
+ # This file is part of RestBooks.
9
+ #
10
+ # RestBooks is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # RestBooks is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with RestBooks. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ module RestBooks
25
+ module Models
26
+ class Category
27
+ include RestBooks::Model
28
+ attr_reader :title, :id, :updated, :description
29
+
30
+ def initialize( element )
31
+ if element
32
+ @element = element
33
+ @element.elements.each do |tag|
34
+ case tag.name
35
+ when 'title'
36
+ @title = tag.text.strip()
37
+ @id = CGI.escape( @title )
38
+ when 'updated'
39
+ @updated = Date.parse( tag.text )
40
+ end
41
+ end
42
+ else
43
+ @element = REXML::Element.new( 'entry' )
44
+ end
45
+ end
46
+
47
+ def to_hash
48
+ return { :title => @title,
49
+ :id => @id,
50
+ :updated => @updated }
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # comment.rb
3
+ # restbooks
4
+ #
5
+ # Created by Paul Chavard on 2009-09-12.
6
+ # Copyright 2009
7
+ #
8
+ # This file is part of RestBooks.
9
+ #
10
+ # RestBooks is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # RestBooks is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with RestBooks. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ module RestBooks
25
+ module Models
26
+ class Comment
27
+ include RestBooks::Model
28
+ attr_reader :title, :id, :author, :published, :updated, :body
29
+
30
+ def initialize( element )
31
+ if element
32
+ @element = element
33
+ @element.elements.each do |tag|
34
+ case tag.name
35
+ when 'title'
36
+ @title = tag.text
37
+ when 'id'
38
+ @id = tag.text.split('#').last
39
+ when 'author'
40
+ @author = tag.elements['name'].text
41
+ when 'published'
42
+ @published = Date.parse( tag.text )
43
+ when 'updated'
44
+ @updated = Date.parse( tag.text )
45
+ when 'content'
46
+ @body = tag.text.strip()
47
+ end
48
+ end
49
+ else
50
+ @element = REXML::Element.new( 'entry' )
51
+ end
52
+ end
53
+
54
+ def to_hash
55
+ return { :title => @title,
56
+ :id => @id,
57
+ :author => @author,
58
+ :published => @published,
59
+ :updated => @updated,
60
+ :body => @date }
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # list.rb
3
+ # restbooks
4
+ #
5
+ # Created by Paul Chavard on 2009-09-12.
6
+ # Copyright 2009
7
+ #
8
+ # This file is part of RestBooks.
9
+ #
10
+ # RestBooks is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # RestBooks is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with RestBooks. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ module RestBooks
25
+ module Models
26
+ class List
27
+ include RestBooks::Model
28
+ attr_reader :title, :id, :updated, :description
29
+
30
+ def initialize( element )
31
+ if element
32
+ @element = element
33
+ @element.elements.each do |tag|
34
+ case tag.name
35
+ when 'title'
36
+ @title = tag.text.strip()
37
+ when 'id'
38
+ @id = tag.text.split('/').last
39
+ @id = @id.split(':').last if @id.split(':').length > 1
40
+ when 'updated'
41
+ @updated = Date.parse( tag.text )
42
+ when 'content'
43
+ @description = tag.text.strip()
44
+ end
45
+ end
46
+ else
47
+ @element = REXML::Element.new( 'entry' )
48
+ end
49
+ end
50
+
51
+ def to_hash
52
+ return { :title => @title,
53
+ :id => @id,
54
+ :updated => @updated,
55
+ :description => @description }
56
+ end
57
+
58
+ end
59
+ end
60
+ end
data/restbooks.rb ADDED
@@ -0,0 +1,99 @@
1
+ #
2
+ # restbooks.rb
3
+ # restbooks
4
+ #
5
+ # Created by Paul Chavard on 2009-09-12.
6
+ # Copyright 2009
7
+ #
8
+ # This file is part of RestBooks.
9
+ #
10
+ # RestBooks is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # RestBooks is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with RestBooks. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ require 'rubygems'
25
+ require 'rest_client'
26
+ require 'rexml/document'
27
+ require 'cgi'
28
+ require 'digest/md5'
29
+ #require 'json'
30
+
31
+ require 'lib/extend/uri'
32
+ require 'lib/mixins/api'
33
+ require 'lib/mixins/model'
34
+ require 'lib/models/author'
35
+ require 'lib/models/book'
36
+ require 'lib/models/comment'
37
+ require 'lib/models/list'
38
+ require 'lib/models/category'
39
+ require 'lib/authors'
40
+ require 'lib/books'
41
+ require 'lib/lists'
42
+ require 'lib/categories'
43
+
44
+ module RestBooks
45
+ class Client
46
+ attr_reader :uri, :user_agent
47
+
48
+ def initialize( options={} )
49
+ # Set host
50
+ host = options.has_key?( :host ) ? options.delete(:host) : 'http://feedbooks.com'
51
+
52
+ # Set user-agent
53
+ @user_agent = options.has_key?( :user_agent ) ? options.delete( :user_agent ) : "RestBooks 0.1"
54
+
55
+ # Set service URI
56
+ @uri = URI.parse( host )
57
+
58
+ # Set authentification
59
+ if options.has_key?( :user ) && options.has_key?( :password )
60
+ @uri.user = options.delete( :user )
61
+ @uri.password = Digest::MD5.hexdigest( options.delete( :password ) )
62
+ end
63
+
64
+ # Set logger output
65
+ RestClient.log = options.delete( :log ) if options.has_key?( :log )
66
+
67
+ # Init services
68
+ @books = false
69
+ @authors = false
70
+ @lists = false
71
+ @categories = false
72
+ end
73
+
74
+ # Use this object to acess books resource
75
+ def books
76
+ @books = Books.new( self ) if !@books
77
+ return @books
78
+ end
79
+
80
+ # Use this object to acess authors resource
81
+ def authors
82
+ @authors = Authors.new( self ) if !@authors
83
+ return @authors
84
+ end
85
+
86
+ # Use this object to acess lists resource
87
+ def lists
88
+ @lists = Lists.new( self ) if !@lists
89
+ return @lists
90
+ end
91
+
92
+ # Use this object to acess categories resource
93
+ def categories
94
+ @categories = Categories.new( self ) if !@categories
95
+ return @categories
96
+ end
97
+
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tchak-restbooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Chavard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest_client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.3
24
+ version:
25
+ description: Restbooks is a client library for feedbooks.com api.
26
+ email: paul@chavard.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - LICENSE
36
+ - restbooks.rb
37
+ - lib/books.rb
38
+ - lib/authors.rb
39
+ - lib/categories.rb
40
+ - lib/lists.rb
41
+ - lib/extend/uri.rb
42
+ - lib/mixins/api.rb
43
+ - lib/mixins/model.rb
44
+ - lib/models/author.rb
45
+ - lib/models/book.rb
46
+ - lib/models/category.rb
47
+ - lib/models/comment.rb
48
+ - lib/models/list.rb
49
+ has_rdoc: false
50
+ homepage: http://restbooks.tchak.net
51
+ licenses:
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Restbooks is a client library for feedbooks.com api.
76
+ test_files: []
77
+