shelf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rune Myrland
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.
@@ -0,0 +1,21 @@
1
+ = shelf
2
+
3
+ Publish ebooks to Epubify Shelf
4
+
5
+ == Description
6
+
7
+ Epubify Shelf is presently under construction. It will be an online bookshelf for ebooks.
8
+
9
+ == Note on Patches/Pull Requests
10
+
11
+ * Fork the project.
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is important so I don't break it in a
14
+ future version unintentionally.
15
+ * Commit, do not mess with rakefile, version, or history.
16
+ (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)
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2011 Rune Myrland. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "shelf"
8
+ gem.summary = %Q{Publish ebooks to Epubify Shelf}
9
+ gem.description = %Q{Epubify Shelf is presently under construction. It will be an online bookshelf for ebooks.}
10
+ gem.email = "rune@epubify.com"
11
+ gem.homepage = "http://github.com/wrimle/shelf"
12
+ gem.authors = ["Rune Myrland"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "shelf #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ require 'shelf'
6
+
7
+
8
+ Epubify::Shelf.base_uri 'localhost:3000'
9
+ Epubify::Shelf.api_key = "tlzr_ZMgVEPRiHCK-Nix"
10
+ shelf = Epubify::Shelf
11
+
12
+ #res = Epubify::Item.find(1)
13
+ #puts res.inspect
14
+
15
+ #res = shelf.items
16
+ #puts res.inspect
17
+
18
+
19
+ #res = shelf.item(1)
20
+ #puts res["item"].inspect
21
+
22
+ #item = Epubify::Item.new
23
+ #item.title = "MyDaily2 #{Date.today.to_s}"
24
+ #item.summary = "Daily news aggregated at #{DateTime.now.to_s}"
25
+
26
+ #puts item.inspect
27
+ #res = item.save
28
+
29
+
30
+ item = Epubify::Item.find(1)
31
+ #puts item.inspect
32
+ res = item.share(2)
33
+ puts res.inspect
34
+
35
+ #res = Epubify::Item.find(2)
36
+ #puts res.inspect
37
+
@@ -0,0 +1,4 @@
1
+
2
+ test:
3
+ server: localhost:3000
4
+ api_key: your single_access_token
@@ -0,0 +1,98 @@
1
+
2
+ require 'rubygems'
3
+ require 'httparty'
4
+ require 'date'
5
+
6
+ module Epubify
7
+ class ShelfApi
8
+ include HTTParty
9
+
10
+ base_uri 'shelf.epubify.com'
11
+
12
+ def self.api_key
13
+ @api_key
14
+ end
15
+
16
+ def self.api_key= k
17
+ @api_key = k
18
+ end
19
+
20
+ def self.items
21
+ get "/api/#{api_key}/items.xml"
22
+ end
23
+
24
+ def self.item id
25
+ get "/api/#{api_key}/items/#{id}.xml"
26
+ end
27
+
28
+ def self.update_item id, query
29
+ put("/api/#{api_key}/items/#{id}.xml", :query => query)
30
+ end
31
+
32
+ def self.create_item query
33
+ post("/api/#{api_key}/items.xml", :query => query)
34
+ end
35
+
36
+ def self.destroy_item id
37
+ delete("/api/#{api_key}/items/#{id}.xml")
38
+ end
39
+
40
+
41
+ def self.share_item query
42
+ post("/api/#{api_key}/shelf_items.xml", :query => query)
43
+ end
44
+
45
+
46
+ def self.downloads item_id
47
+ get "/api/#{api_key}/downloads.xml", :query => { :item_id => item_id }
48
+ end
49
+
50
+ def self.download id
51
+ get "/api/#{api_key}/downloads/#{id}.xml"
52
+ end
53
+
54
+
55
+ def self.update_download id, query
56
+ put("/api/#{api_key}/downloads/#{id}.xml", :query => query)
57
+ end
58
+
59
+ def self.create_download query
60
+ post("/api/#{api_key}/downloads.xml", :query => query)
61
+ end
62
+
63
+ def self.destroy_download id
64
+ delete("/api/#{api_key}/downloads/#{id}.xml")
65
+ end
66
+
67
+ end
68
+
69
+
70
+ end
71
+
72
+
73
+ require 'shelf/download.rb'
74
+ require 'shelf/item.rb'
75
+
76
+
77
+ module Epubify
78
+
79
+ class Shelf
80
+ def initialize
81
+ @items = nil
82
+ end
83
+
84
+
85
+ def items
86
+ unless @items
87
+ res = ShelfApi.items
88
+ @items = []
89
+ res["items"].each do |hash|
90
+ @items << Item.new(hash)
91
+ end
92
+ end
93
+ @items
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -0,0 +1,64 @@
1
+
2
+
3
+ module Epubify
4
+
5
+ class Download
6
+ attr_accessor :id, :item_id, :content_type, :url
7
+
8
+ def initialize h = nil, &block
9
+ content_type = "application/epub+zip"
10
+
11
+ from_hash h if h
12
+ yield self if block
13
+ end
14
+
15
+
16
+ def from_hash h
17
+ self.id = h["id"]
18
+ self.item_id = h["item_id"]
19
+ self.content_type = h["content_type"]
20
+ self.url = h["url"]
21
+ end
22
+
23
+
24
+ def item= v
25
+ @item = v
26
+ item_id = v.id
27
+ end
28
+
29
+
30
+ def item
31
+ @item
32
+ end
33
+
34
+
35
+ def self.find id
36
+ res = ShelfApi.download(id)
37
+
38
+ download = res["download"]
39
+ Download.new do |d|
40
+ d.from_hash download
41
+ end
42
+ end
43
+
44
+
45
+ def destroy
46
+ ShelfApi.destroy_download(id) if id
47
+ end
48
+
49
+
50
+ def save
51
+ @query = { :download => { :item_id => item_id, :content_type => content_type, :url => url } }
52
+
53
+ if id
54
+ res = ShelfApi.update_download(id, @query)
55
+ else
56
+ res = ShelfApi.create_download(@query)
57
+ from_hash res["download"]
58
+ end
59
+
60
+ res
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,70 @@
1
+ require 'shelf/download.rb'
2
+
3
+
4
+ module Epubify
5
+
6
+ class Item
7
+ attr_accessor :id, :title, :summary, :description, :cover_url, :thumbnail_url, :language, :issued
8
+
9
+ def initialize hash = nil, &block
10
+ summary = ""
11
+ description = ""
12
+ language = "no"
13
+ issued = "#{Date.today.to_s}"
14
+
15
+ from_hash hash if hash
16
+ yield self if block
17
+ end
18
+
19
+ def self.find id
20
+ res = ShelfApi.item(id)
21
+
22
+ item = res["item"]
23
+ Item.new do |i|
24
+ i.from_hash item
25
+ end
26
+ end
27
+
28
+ def from_hash h
29
+ self.id = h["id"]
30
+ self.title = h["title"]
31
+ self.summary = h["summary"]
32
+ self.description = h["description"]
33
+ self.cover_url = h["cover_url"]
34
+ self.thumbnail_url = h["thumbnail_url"]
35
+ self.language = h["language"]
36
+ self.issued = h["issued"]
37
+ end
38
+
39
+ def save
40
+ @query = { :item => { :title => title, :summary => summary, :description => description, :cover_url => cover_url, :thumbnail_url => thumbnail_url, :language => language, :issued => issued } }
41
+
42
+ if id
43
+ res = ShelfApi.update_item(id, @query)
44
+ else
45
+ res = ShelfApi.create_item(@query)
46
+ from_hash res["item"]
47
+ end
48
+ res
49
+ end
50
+
51
+ def destroy
52
+ ShelfApi.destroy_item(id) if id
53
+ end
54
+
55
+ def share item_id
56
+ @query = { :shelf_item => { :shelf_id => nil, :item_id => item_id } }
57
+ ShelfApi.share_item(@query)
58
+ end
59
+
60
+ def downloads
61
+ res = ShelfApi.downloads(id)
62
+ d = []
63
+ res["downloads"].each do |hash|
64
+ d << Download.new(hash)
65
+ end
66
+ d
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'yaml'
4
+
5
+
6
+ module Epubify
7
+ config = YAML::load(File.open("config/config.yaml"))
8
+
9
+
10
+ ShelfApi.api_key= config["test"]["api_key"]
11
+ ShelfApi.base_uri config["test"]["server"]
12
+
13
+
14
+ describe Download do
15
+ before(:each) do
16
+ end
17
+
18
+ it "gets a download" do
19
+ download = Download.find(1)
20
+ download.id.should_not be_nil
21
+ end
22
+
23
+
24
+ it "updates a download" do
25
+ download = Download.find(1)
26
+ old_url = download.url
27
+ new_url = "www.example.com/dummy"
28
+
29
+ download.url = new_url
30
+ download.save
31
+
32
+ download = Download.find(1)
33
+ download.url.should eql new_url
34
+
35
+ # Restore original value
36
+ download.url = old_url
37
+ download.save
38
+ end
39
+
40
+
41
+ it "creates a download" do
42
+ item = Item.find(1)
43
+ count = item.downloads.length
44
+
45
+ download = Epubify::Download.new
46
+ download.url = "/example.epub"
47
+ download.item_id = 1
48
+ download.save
49
+
50
+ item = Item.find(1)
51
+ item.downloads.length.should be > count
52
+ download.id.should_not be_nil
53
+ end
54
+
55
+
56
+ it "destroys a download" do
57
+ item = Item.find(1)
58
+ count = item.downloads.length
59
+ count.should be > 1
60
+
61
+ download = item.downloads.pop
62
+ download.destroy
63
+
64
+
65
+ item = Item.find(1)
66
+ item.downloads.length.should be < count
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'yaml'
4
+
5
+
6
+ module Epubify
7
+ config = YAML::load(File.open("config/config.yaml"))
8
+
9
+ ShelfApi.api_key= config["test"]["api_key"]
10
+ ShelfApi.base_uri config["test"]["server"]
11
+
12
+
13
+ describe Item do
14
+ before(:each) do
15
+ end
16
+
17
+
18
+ it "finds an item" do
19
+ item = Item.find(1)
20
+ item.id.should be 1
21
+ item.title.should_not be_nil
22
+ end
23
+
24
+
25
+ it "updates a download" do
26
+ item = Item.find(1)
27
+ old_title = item.title
28
+ new_title = "Test title"
29
+
30
+ item.title = new_title
31
+ item.save
32
+
33
+ item = Item.find(1)
34
+ item.title.should eql new_title
35
+
36
+ # Restore original value
37
+ item.title = old_title
38
+ item.save
39
+ end
40
+
41
+
42
+ it "gets the downloads of an item" do
43
+ item = Item.find(1)
44
+ downloads = item.downloads
45
+ downloads.length.should be > 0
46
+ downloads[0].id.should_not be_nil
47
+ end
48
+
49
+
50
+ it "creates an item" do
51
+ count = Shelf.new.items.length
52
+
53
+ item = Epubify::Item.new
54
+ item.title = "MyDaily #{Date.today.to_s}"
55
+ item.summary = "Daily news aggregated at #{DateTime.now.to_s}"
56
+ item.save
57
+
58
+ Shelf.new.items.length.should be > count
59
+ item.id.should_not be_nil
60
+ end
61
+
62
+
63
+ it "destroys an item" do
64
+ items = Shelf.new.items
65
+ count = items.length
66
+ count.should be > 1
67
+ item = items.pop
68
+ item.destroy
69
+
70
+ Shelf.new.items.length.should be < count
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'yaml'
4
+
5
+
6
+ module Epubify
7
+ config = YAML::load(File.open("config/config.yaml"))
8
+
9
+
10
+ ShelfApi.api_key= config["test"]["api_key"]
11
+ ShelfApi.base_uri config["test"]["server"]
12
+
13
+
14
+ describe ShelfApi do
15
+ end
16
+
17
+
18
+ describe Shelf do
19
+ before(:each) do
20
+ end
21
+
22
+ it "lists owned items" do
23
+ shelf = Shelf.new
24
+ shelf.items.length.should be > 0
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'shelf'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shelf
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Rune Myrland
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-20 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Epubify Shelf is presently under construction. It will be an online bookshelf for ebooks.
38
+ email: rune@epubify.com
39
+ executables:
40
+ - shelf.rb~
41
+ - eshelf.rb
42
+ - eshelf.rb~
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - LICENSE
47
+ - README.rdoc
48
+ files:
49
+ - .document
50
+ - .gitignore
51
+ - LICENSE
52
+ - README.rdoc
53
+ - Rakefile
54
+ - VERSION
55
+ - config/config.yaml.template
56
+ - lib/shelf.rb
57
+ - lib/shelf/download.rb
58
+ - lib/shelf/item.rb
59
+ - spec/download_spec.rb
60
+ - spec/item_spec.rb
61
+ - spec/shelf_spec.rb
62
+ - spec/spec.opts
63
+ - spec/spec_helper.rb
64
+ - bin/shelf.rb~
65
+ - bin/eshelf.rb
66
+ - bin/eshelf.rb~
67
+ has_rdoc: true
68
+ homepage: http://github.com/wrimle/shelf
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Publish ebooks to Epubify Shelf
101
+ test_files:
102
+ - spec/spec_helper.rb
103
+ - spec/item_spec.rb
104
+ - spec/download_spec.rb
105
+ - spec/shelf_spec.rb