issuu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ gem "activesupport", ">= 3.0.3"
8
+ gem "multipart-post"
9
+
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.5.2"
14
+ gem "rcov", ">= 0"
15
+ gem "rspec", ">= 2.4.0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.3)
5
+ diff-lcs (1.1.2)
6
+ git (1.2.5)
7
+ jeweler (1.5.2)
8
+ bundler (~> 1.0.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ multipart-post (1.0.1)
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ rspec (2.4.0)
15
+ rspec-core (~> 2.4.0)
16
+ rspec-expectations (~> 2.4.0)
17
+ rspec-mocks (~> 2.4.0)
18
+ rspec-core (2.4.0)
19
+ rspec-expectations (2.4.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.4.0)
22
+ shoulda (2.11.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ activesupport (>= 3.0.3)
29
+ bundler (~> 1.0.0)
30
+ jeweler (~> 1.5.2)
31
+ multipart-post
32
+ rcov
33
+ rspec (>= 2.4.0)
34
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Bastien Vaucher
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.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = issuu
2
+
3
+ Access to the Issuu API based on {Guillem Català post}[http://planet.ubiquo.me/using-the-issuucom-api-to-upload-and-delete-p]
4
+
5
+ See the {full Issuu API reference}[http://issuu.com/services/api/]
6
+
7
+ == Installation
8
+
9
+ gem install issuu
10
+
11
+ == Example of use
12
+
13
+ require 'rubygems'
14
+ require 'issuu'
15
+
16
+ # if you're using rails, put this in an initializer file
17
+ Issuu.configure do |c|
18
+ c.api_key = "YOUR ISSUU API KEY"
19
+ c.secret = "YOUR ISSUU SECRET"
20
+ end
21
+
22
+ puts Issuu::Document.list.inspect
23
+ response = Issuu::Document.upload('path_to_your_file', 'application/pdf')
24
+ name = response["rsp"]["_content"]["document"]["name"]
25
+ puts "File uploaded: #{name}"
26
+ puts Issuu::Document.list.inspect
27
+ Issuu::Document.delete([name])
28
+ puts Issuu::Document.list.inspect
29
+
30
+ == Contributing to issuu
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
+ * Fork the project
35
+ * Start a feature/bugfix branch
36
+ * Commit and push until you are happy with your contribution
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2011 Bastien Vaucher - {MagmaHQ}[http://www.magmahq.com] . See LICENSE.txt for
43
+ further details.
44
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "issuu"
16
+ gem.homepage = "http://github.com/bastien/issuu"
17
+ gem.license = "MIT"
18
+ gem.summary = "Issuu API"
19
+ gem.description = "Provides basic methods to access the Issuu API"
20
+ gem.email = "bastien.vaucher@gmail.com"
21
+ gem.authors = ["Bastien Vaucher"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ gem.add_development_dependency 'rspec', '>= 2.4.0'
26
+ gem.add_dependency "activesupport", '>= 3.0.3'
27
+ gem.add_dependency "multipart-post"
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "issuu #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/issuu.gemspec ADDED
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{issuu}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bastien Vaucher"]
12
+ s.date = %q{2011-01-07}
13
+ s.description = %q{Provides basic methods to access the Issuu API}
14
+ s.email = %q{bastien.vaucher@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "issuu.gemspec",
29
+ "lib/issuu.rb",
30
+ "lib/issuu/bookmark.rb",
31
+ "lib/issuu/cli.rb",
32
+ "lib/issuu/document.rb",
33
+ "lib/issuu/folder.rb",
34
+ "lib/issuu/parameter_set.rb",
35
+ "spec/issuu/bookmark_spec.rb",
36
+ "spec/issuu/document_spec.rb",
37
+ "spec/issuu/folder_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/bastien/issuu}
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.7}
44
+ s.summary = %q{Issuu API}
45
+ s.test_files = [
46
+ "spec/issuu/bookmark_spec.rb",
47
+ "spec/issuu/document_spec.rb",
48
+ "spec/issuu/folder_spec.rb",
49
+ "spec/spec_helper.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.3"])
58
+ s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
59
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
62
+ s.add_development_dependency(%q<rcov>, [">= 0"])
63
+ s.add_development_dependency(%q<rspec>, [">= 2.4.0"])
64
+ s.add_development_dependency(%q<rspec>, [">= 2.4.0"])
65
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.3"])
66
+ s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
67
+ else
68
+ s.add_dependency(%q<activesupport>, [">= 3.0.3"])
69
+ s.add_dependency(%q<multipart-post>, [">= 0"])
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
75
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
76
+ s.add_dependency(%q<activesupport>, [">= 3.0.3"])
77
+ s.add_dependency(%q<multipart-post>, [">= 0"])
78
+ end
79
+ else
80
+ s.add_dependency(%q<activesupport>, [">= 3.0.3"])
81
+ s.add_dependency(%q<multipart-post>, [">= 0"])
82
+ s.add_dependency(%q<shoulda>, [">= 0"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
84
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
85
+ s.add_dependency(%q<rcov>, [">= 0"])
86
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
87
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
88
+ s.add_dependency(%q<activesupport>, [">= 3.0.3"])
89
+ s.add_dependency(%q<multipart-post>, [">= 0"])
90
+ end
91
+ end
92
+
@@ -0,0 +1,50 @@
1
+ module Issuu
2
+ class Bookmark
3
+ def initialize(hash)
4
+ hash.each do |key, value|
5
+ metaclass.send :attr_accessor, key
6
+ instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+
10
+ def metaclass
11
+ class << self
12
+ self
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def add(name, document_user_name, params={})
18
+ response = Cli.http_post(
19
+ Issuu::API_URL,
20
+ ParameterSet.new("issuu.bookmark.add", params.merge({:name => name, :documentUsername => document_user_name})).output
21
+ )
22
+ Bookmark.new(response["rsp"]["_content"]["bookmark"])
23
+ end
24
+
25
+ def list(params={})
26
+ response = Cli.http_get(
27
+ Issuu::API_URL,
28
+ ParameterSet.new("issuu.bookmarks.list", params).output
29
+ )
30
+ response["rsp"]["_content"]["result"]["_content"].map{|bookmark_hash| Document.new(bookmark_hash["bookmark"]) }
31
+ end
32
+
33
+ def update(bookmark_id, params={})
34
+ response = Cli.http_post(
35
+ Issuu::API_URL,
36
+ ParameterSet.new("issuu.bookmark.update", params.merge({:bookmarkId => bookmark_id})).output
37
+ )
38
+ Bookmark.new(response["rsp"]["_content"]["bookmark"])
39
+ end
40
+
41
+ def delete(bookmark_ids)
42
+ Cli.http_post(
43
+ Issuu::API_URL,
44
+ ParameterSet.new("issuu.bookmark.delete", {:bookmarkIds => bookmark_ids.join(',')}).output
45
+ )
46
+ return true
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/issuu/cli.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Issuu
2
+ class Cli
3
+ class << self
4
+ def check_for_exceptions(json_data)
5
+ if json_data['rsp']['stat'].eql?("fail")
6
+ raise(StandardError, json_data['rsp']["_content"]["error"]["message"])
7
+ end
8
+ end
9
+
10
+ def decoded_response_body(response_body)
11
+ json_data = ActiveSupport::JSON.decode(response_body)
12
+ check_for_exceptions(json_data)
13
+ json_data
14
+ end
15
+
16
+ def http_get(url, params)
17
+ path = "#{url.path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.reverse.join('&')) unless params.nil?
18
+ request = Net::HTTP.get(url.host, path)
19
+ decoded_response_body(request)
20
+ end
21
+
22
+ def http_post(url, params)
23
+ request = Net::HTTP.post_form(url+ '?', params)
24
+ decoded_response_body(request.body)
25
+ end
26
+
27
+ def http_multipart_post(url, file, params)
28
+ petition = Net::HTTP::Post::Multipart.new(
29
+ url.path + '?',
30
+ params.merge({:file => file})
31
+ )
32
+ Net::HTTP.start(url.host, url.port) do |http|
33
+ request = http.request(petition)
34
+ decoded_response_body(request.body)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,61 @@
1
+ module Issuu
2
+ class Document
3
+ def initialize(hash)
4
+ hash.each do |key, value|
5
+ metaclass.send :attr_accessor, key
6
+ instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+
10
+ def metaclass
11
+ class << self
12
+ self
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def url_upload(url, params={})
18
+ response = Cli.http_post(
19
+ Issuu::API_URL,
20
+ ParameterSet.new("issuu.document.url_upload", params.merge({:slurpUrl => url})).output
21
+ )
22
+ Document.new(response["rsp"]["_content"]["document"])
23
+ end
24
+
25
+ def upload(file_path, file_type, params={})
26
+ file_to_upload = UploadIO.new(file_path, file_type)
27
+
28
+ response = Cli.http_multipart_post(
29
+ Issuu::API_UPLOAD_URL,
30
+ file_to_upload,
31
+ ParameterSet.new("issuu.document.upload", params).output
32
+ )
33
+ Document.new(response["rsp"]["_content"]["document"])
34
+ end
35
+
36
+ def update(filename, params={})
37
+ response = Cli.http_post(
38
+ Issuu::API_URL,
39
+ ParameterSet.new("issuu.document.update", params.merge({:name => filename})).output
40
+ )
41
+ Document.new(response["rsp"]["_content"]["document"])
42
+ end
43
+
44
+ def list(params={})
45
+ response = Cli.http_get(
46
+ Issuu::API_URL,
47
+ ParameterSet.new("issuu.documents.list", params).output
48
+ )
49
+ response["rsp"]["_content"]["result"]["_content"].map{|document_hash| Document.new(document_hash["document"]) }
50
+ end
51
+
52
+ def delete(filenames)
53
+ Cli.http_post(
54
+ Issuu::API_URL,
55
+ ParameterSet.new("issuu.document.delete", {:names => filenames.join(',')}).output
56
+ )
57
+ return true
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,50 @@
1
+ module Issuu
2
+ class Folder
3
+ def initialize(hash)
4
+ hash.each do |key, value|
5
+ metaclass.send :attr_accessor, key
6
+ instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+
10
+ def metaclass
11
+ class << self
12
+ self
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def add(name, params={})
18
+ response = Cli.http_post(
19
+ Issuu::API_URL,
20
+ ParameterSet.new("issuu.folder.add", params.merge(:folderName => name)).output
21
+ )
22
+ Folder.new(response["rsp"]["_content"]["folder"])
23
+ end
24
+
25
+ def list(params={})
26
+ response = Cli.http_get(
27
+ Issuu::API_URL,
28
+ ParameterSet.new("issuu.folders.list", params).output
29
+ )
30
+ response["rsp"]["_content"]["result"]["_content"].map{|folder_hash| Document.new(folder_hash["folder"]) }
31
+ end
32
+
33
+ def update(folder_id, params={})
34
+ response = Cli.http_post(
35
+ Issuu::API_URL,
36
+ ParameterSet.new("issuu.folder.update", params.merge(:folderId => folder_id)).output
37
+ )
38
+ Folder.new(response["rsp"]["_content"]["folder"])
39
+ end
40
+
41
+ def delete(folder_ids)
42
+ Cli.http_post(
43
+ Issuu::API_URL,
44
+ ParameterSet.new("issuu.folder.delete", {:folderIds => folder_ids.join(',')}).output
45
+ )
46
+ return true
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ module Issuu
2
+ class ParameterSet
3
+ def initialize(action, extra_params={})
4
+ @api_key = extra_params.delete(:api_key) || Issuu.api_key
5
+ @secret = extra_params.delete(:secret) || Issuu.secret
6
+ @params = extra_params.update({
7
+ :action => action,
8
+ :apiKey => @api_key,
9
+ :format => "json"
10
+ })
11
+ end
12
+
13
+ def generate_signature
14
+ string_to_sign = "#{@secret}#{@params.sort_by {|k| k.to_s }.to_s}"
15
+ Digest::MD5.hexdigest(string_to_sign)
16
+ end
17
+
18
+ def output
19
+ @params.merge({:signature => generate_signature})
20
+ end
21
+ end
22
+ end
data/lib/issuu.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "net/http"
2
+ require 'net/http/post/multipart'
3
+ require 'digest/md5'
4
+ require 'uri'
5
+ require 'cgi'
6
+ require 'active_support'
7
+
8
+ module Issuu
9
+ API_URL = URI.parse('http://api.issuu.com/1_0')
10
+ API_UPLOAD_URL = URI.parse('http://upload.issuu.com/1_0')
11
+
12
+ class << self
13
+ attr_accessor :api_key, :secret
14
+
15
+ # In your initializer:
16
+ # Issuu.configure do |c|
17
+ # c.api_key = ENV['ISSUU_API_KEY']
18
+ # c.secret = ENV['ISSUU_SECRET']
19
+ # end
20
+ #
21
+ def configure
22
+ yield self
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ require 'issuu/cli'
29
+ require 'issuu/document'
30
+ require 'issuu/bookmark'
31
+ require 'issuu/folder'
32
+ require 'issuu/parameter_set'
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe Issuu::Bookmark do
4
+ before(:each) { @empty_parameter_set = Issuu::ParameterSet.new("action") }
5
+
6
+ let(:issuu_bookmark_hash) do
7
+ {
8
+ "bookmark"=>
9
+ {
10
+ "bookmarkId" => "11b27cd5-ecdc-4c39-b818-8f3c8eca443c",
11
+ "username" => "travelmagazine",
12
+ "documentId" => "081024182109-9280632f2866416d97634cdccc66715d",
13
+ "documentUsername" => "publination",
14
+ "name" => "wildswim",
15
+ "title" => "Wild Swim: The best outdoor swims across Britain",
16
+ "description" => "Wild Swim by Kate Rew is the definitive guide to over 300 beautiful outdoor swims in rivers, lakes, tidal pools, the sea and lidos across Britain. By the founder of the Outdoor Swimming Society.",
17
+ "page" => 1,
18
+ "created" => "2009-06-22T07:54:17.000Z",
19
+ "folders" => [
20
+ "52ab7b36-946d-45b2-a446-f95e84b2682e"
21
+ ]
22
+ }
23
+ }
24
+ end
25
+
26
+ describe "creating a new bookmark object" do
27
+ subject { Issuu::Bookmark.new({:name => "Magma", :description => "Rocks!"}) }
28
+
29
+ it "should assign all the params given in the hash and make them accessible" do
30
+ subject.name.should == "Magma"
31
+ subject.description.should == "Rocks!"
32
+ end
33
+ end
34
+
35
+ describe "add a bookmark" do
36
+ before(:each) do
37
+ Issuu::Cli.stub!(:http_post).and_return(
38
+ {"rsp"=>
39
+ {
40
+ "_content" => issuu_bookmark_hash,
41
+ "stat" => "ok"
42
+ }
43
+ }
44
+ )
45
+ end
46
+
47
+ describe "basic add" do
48
+ subject { Issuu::Bookmark.add("filename", "username") }
49
+
50
+ it "should return an instance of the uploaded document" do
51
+ subject.class.should == Issuu::Bookmark
52
+ subject.title.should == "Wild Swim: The best outdoor swims across Britain"
53
+ end
54
+ end
55
+
56
+ describe "add with extra parameters" do
57
+ it "should pass the extra parameters to the ParameterSet" do
58
+ Issuu::ParameterSet.should_receive(:new).with(
59
+ "issuu.bookmark.add",
60
+ {:name=>"filename", :documentUsername=>"username"}
61
+ ).and_return(@empty_parameter_set)
62
+ Issuu::Bookmark.add("filename", "username", {:name => "my extra name"})
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "listing bookmarks" do
68
+ before(:each) do
69
+ Issuu::Cli.stub!(:http_get).and_return(
70
+ {"rsp"=>
71
+ {
72
+ "_content" =>
73
+ {
74
+ "result" =>
75
+ {
76
+ "_content" => [issuu_bookmark_hash]
77
+ }
78
+ },
79
+ "stat" => "ok"
80
+ }
81
+ }
82
+ )
83
+ end
84
+
85
+ describe "basic listing" do
86
+ subject { Issuu::Bookmark.list }
87
+
88
+ it "should return an instance of the uploaded document" do
89
+ subject.class.should == Array
90
+ subject.first.title.should == "Wild Swim: The best outdoor swims across Britain"
91
+ end
92
+ end
93
+
94
+ describe "listing with extra parameters" do
95
+ it "should pass the extra parameters to the ParameterSet" do
96
+ Issuu::ParameterSet.should_receive(:new).with(
97
+ "issuu.bookmarks.list",
98
+ {:name => "my extra name"}
99
+ ).and_return(@empty_parameter_set)
100
+ Issuu::Bookmark.list({:name => "my extra name"})
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "delete bookmark" do
106
+ before(:each) do
107
+ Issuu::Cli.stub!(:http_post).and_return({
108
+ "rsp" => {
109
+ "stat" => "ok"
110
+ }
111
+ })
112
+ end
113
+
114
+ subject { Issuu::Bookmark.delete(["bookmark_id"]) }
115
+
116
+ it "should return an instance of the uploaded document" do
117
+ subject == true
118
+ end
119
+ end
120
+
121
+ describe "update a bookmark" do
122
+ before(:each) do
123
+ Issuu::Cli.stub!(:http_post).and_return(
124
+ {"rsp"=>
125
+ {
126
+ "_content" => issuu_bookmark_hash,
127
+ "stat" => "ok"
128
+ }
129
+ }
130
+ )
131
+ Issuu::ParameterSet.should_receive(:new).with(
132
+ "issuu.bookmark.update",
133
+ {:bookmarkId => "bookmark_id", :description => "New description"}
134
+ ).and_return(@empty_parameter_set)
135
+ end
136
+
137
+ subject { Issuu::Bookmark.update("bookmark_id", {:description => "New description"}) }
138
+
139
+ it "should pass the extra parameters to the ParameterSet" do
140
+ subject.class.should == Issuu::Bookmark
141
+ subject.title.should == "Wild Swim: The best outdoor swims across Britain"
142
+ end
143
+ end
144
+
145
+ end
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe Issuu::Document do
4
+ before(:each) { @empty_parameter_set = Issuu::ParameterSet.new("action") }
5
+
6
+ let(:issuu_document_hash) do
7
+ {
8
+ "document"=>
9
+ {
10
+ "ep"=>1245759831,
11
+ "pageCount"=>0,
12
+ "documentId"=>"090623122351-f691a27cfd744b80b25a2c8f5a51d596",
13
+ "name"=>"racing",
14
+ "category"=>"012000",
15
+ "title"=>"Race cars",
16
+ "username"=>"magma",
17
+ "tags"=>["cars", "le man", "racing"],
18
+ "origin"=>"singleupload",
19
+ "type"=>"009000",
20
+ "description"=>"Race cars of Le Man 2009",
21
+ "access"=>"public",
22
+ "folders"=>["3935f331-5d5b-4694-86ce-6f26c6dee809"],
23
+ "state"=>"P"
24
+ }
25
+ }
26
+ end
27
+
28
+ describe "creating a new document object" do
29
+ subject { Issuu::Document.new({:name => "Magma", :description => "Rocks!"}) }
30
+
31
+ it "should assign all the params given in the hash and make them accessible" do
32
+ subject.name.should == "Magma"
33
+ subject.description.should == "Rocks!"
34
+ end
35
+ end
36
+
37
+ describe "uploading a file" do
38
+ before(:each) do
39
+ Issuu::Cli.stub!(:http_multipart_post).and_return(
40
+ {"rsp"=>
41
+ {
42
+ "_content" => issuu_document_hash,
43
+ "stat" => "ok"
44
+ }
45
+ }
46
+ )
47
+ UploadIO.stub!(:new).and_return("a file")
48
+ end
49
+
50
+ describe "basic upload" do
51
+ subject { Issuu::Document.upload("a/file/path", "file/type") }
52
+
53
+ it "should return an instance of the uploaded document" do
54
+ subject.class.should == Issuu::Document
55
+ subject.title.should == "Race cars"
56
+ end
57
+ end
58
+
59
+ describe "upload with extra parameters" do
60
+ it "should pass the extra parameters to the ParameterSet" do
61
+ Issuu::ParameterSet.should_receive(:new).with(
62
+ "issuu.document.upload",
63
+ {:name => "my extra name"}
64
+ ).and_return(@empty_parameter_set)
65
+ Issuu::Document.upload("a/file/path", "file/type", {:name => "my extra name"})
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "uploading a url" do
71
+ before(:each) do
72
+ Issuu::Cli.stub!(:http_post).and_return(
73
+ {"rsp"=>
74
+ {
75
+ "_content" => issuu_document_hash,
76
+ "stat" => "ok"
77
+ }
78
+ }
79
+ )
80
+ end
81
+
82
+ describe "basic url upload" do
83
+ subject { Issuu::Document.url_upload("a/file/url") }
84
+
85
+ it "should return an instance of the uploaded document" do
86
+ subject.class.should == Issuu::Document
87
+ subject.title.should == "Race cars"
88
+ end
89
+ end
90
+
91
+ describe "url upload with extra parameters" do
92
+ it "should pass the extra parameters to the ParameterSet" do
93
+ Issuu::ParameterSet.should_receive(:new).with(
94
+ "issuu.document.url_upload",
95
+ {:slurpUrl=>"a/file/url", :name => "my extra name"}
96
+ ).and_return(@empty_parameter_set)
97
+ Issuu::Document.url_upload("a/file/url", {:name => "my extra name"})
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "listing documents" do
103
+ before(:each) do
104
+ Issuu::Cli.stub!(:http_get).and_return(
105
+ {"rsp"=>
106
+ {
107
+ "_content" =>
108
+ {
109
+ "result" =>
110
+ {
111
+ "_content" => [issuu_document_hash]
112
+ }
113
+ },
114
+ "stat" => "ok"
115
+ }
116
+ }
117
+ )
118
+ end
119
+
120
+ describe "basic listing" do
121
+ subject { Issuu::Document.list }
122
+
123
+ it "should return an instance of the uploaded document" do
124
+ subject.class.should == Array
125
+ subject.first.title.should == "Race cars"
126
+ end
127
+ end
128
+
129
+ describe "listing with extra parameters" do
130
+ it "should pass the extra parameters to the ParameterSet" do
131
+ Issuu::ParameterSet.should_receive(:new).with(
132
+ "issuu.documents.list",
133
+ {:name => "my extra name"}
134
+ ).and_return(@empty_parameter_set)
135
+ Issuu::Document.list({:name => "my extra name"})
136
+ end
137
+ end
138
+ end
139
+
140
+ describe "delete document" do
141
+ before(:each) do
142
+ Issuu::Cli.stub!(:http_post).and_return({
143
+ "rsp" => {
144
+ "stat" => "ok"
145
+ }
146
+ })
147
+ end
148
+
149
+ subject { Issuu::Document.delete(["document_id"]) }
150
+
151
+ it "should return an instance of the uploaded document" do
152
+ subject == true
153
+ end
154
+ end
155
+
156
+ describe "update a document" do
157
+ before(:each) do
158
+ Issuu::Cli.stub!(:http_post).and_return(
159
+ {"rsp"=>
160
+ {
161
+ "_content" => issuu_document_hash,
162
+ "stat" => "ok"
163
+ }
164
+ }
165
+ )
166
+ Issuu::ParameterSet.should_receive(:new).with(
167
+ "issuu.document.update",
168
+ {:name => "document_name", :publishDate => "1997-07-16"}
169
+ ).and_return(@empty_parameter_set)
170
+ end
171
+
172
+ subject { Issuu::Document.update("document_name", {:publishDate => "1997-07-16"}) }
173
+
174
+ it "should pass the extra parameters to the ParameterSet" do
175
+ subject.class.should == Issuu::Document
176
+ subject.title.should == "Race cars"
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Issuu::Folder do
4
+ before(:each) { @empty_parameter_set = Issuu::ParameterSet.new("action") }
5
+
6
+ let(:issuu_folder_hash) do
7
+ {
8
+ "folder"=>
9
+ {
10
+ "folderId" => "4c3ba964-60c3-4349-94d0-ff86db2d47c9",
11
+ "username" => "ferrogate",
12
+ "name" => "Cool stuff",
13
+ "description" => "Stuff I have collected",
14
+ "items" => 0,
15
+ "created" => "2009-07-12T19:52:15.000Z"
16
+ }
17
+ }
18
+ end
19
+
20
+ describe "creating a new folder object" do
21
+ subject { Issuu::Folder.new({:name => "Magma", :description => "Rocks!"}) }
22
+
23
+ it "should assign all the params given in the hash and make them accessible" do
24
+ subject.name.should == "Magma"
25
+ subject.description.should == "Rocks!"
26
+ end
27
+ end
28
+
29
+ describe "add a folder" do
30
+ before(:each) do
31
+ Issuu::Cli.stub!(:http_post).and_return(
32
+ {"rsp"=>
33
+ {
34
+ "_content" => issuu_folder_hash,
35
+ "stat" => "ok"
36
+ }
37
+ }
38
+ )
39
+ end
40
+
41
+ describe "basic add" do
42
+ subject { Issuu::Folder.add("folder_name") }
43
+
44
+ it "should return an instance of the uploaded document" do
45
+ subject.class.should == Issuu::Folder
46
+ subject.name.should == "Cool stuff"
47
+ end
48
+ end
49
+
50
+ describe "add with extra parameters" do
51
+ it "should pass the extra parameters to the ParameterSet" do
52
+ Issuu::ParameterSet.should_receive(:new).with(
53
+ "issuu.folder.add",
54
+ {:folderName=>"folder_name", :description=>"some description"}
55
+ ).and_return(@empty_parameter_set)
56
+ Issuu::Folder.add("folder_name", {:description => "some description"})
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "listing folders" do
62
+ before(:each) do
63
+ Issuu::Cli.stub!(:http_get).and_return(
64
+ {"rsp"=>
65
+ {
66
+ "_content" =>
67
+ {
68
+ "result" =>
69
+ {
70
+ "_content" => [issuu_folder_hash]
71
+ }
72
+ },
73
+ "stat" => "ok"
74
+ }
75
+ }
76
+ )
77
+ end
78
+
79
+ describe "basic listing" do
80
+ subject { Issuu::Folder.list }
81
+
82
+ it "should return an instance of the uploaded document" do
83
+ subject.class.should == Array
84
+ subject.first.name.should == "Cool stuff"
85
+ end
86
+ end
87
+
88
+ describe "listing with extra parameters" do
89
+ it "should pass the extra parameters to the ParameterSet" do
90
+ Issuu::ParameterSet.should_receive(:new).with(
91
+ "issuu.folders.list",
92
+ {:name => "my extra name"}
93
+ ).and_return(@empty_parameter_set)
94
+ Issuu::Folder.list({:name => "my extra name"})
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "delete folder" do
100
+ before(:each) do
101
+ Issuu::Cli.stub!(:http_post).and_return({
102
+ "rsp" => {
103
+ "stat" => "ok"
104
+ }
105
+ })
106
+ end
107
+
108
+ subject { Issuu::Folder.delete(["folder_id"]) }
109
+
110
+ it "should return an instance of the uploaded document" do
111
+ subject == true
112
+ end
113
+ end
114
+
115
+ describe "update a folder" do
116
+ before(:each) do
117
+ Issuu::Cli.stub!(:http_post).and_return(
118
+ {"rsp"=>
119
+ {
120
+ "_content" => issuu_folder_hash,
121
+ "stat" => "ok"
122
+ }
123
+ }
124
+ )
125
+ Issuu::ParameterSet.should_receive(:new).with(
126
+ "issuu.folder.update",
127
+ {:folderId => "folder_id", :description => "New description"}
128
+ ).and_return(@empty_parameter_set)
129
+ end
130
+
131
+ subject { Issuu::Folder.update("folder_id", {:description => "New description"}) }
132
+
133
+ it "should pass the extra parameters to the ParameterSet" do
134
+ subject.class.should == Issuu::Folder
135
+ subject.name.should == "Cool stuff"
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'issuu'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: issuu
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Bastien Vaucher
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-07 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: activesupport
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 1
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 3
35
+ version: 3.0.3
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
39
+ prerelease: false
40
+ name: multipart-post
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ prerelease: false
54
+ name: shoulda
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ prerelease: false
68
+ name: bundler
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 1
77
+ - 0
78
+ - 0
79
+ version: 1.0.0
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ type: :development
83
+ prerelease: false
84
+ name: jeweler
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 7
91
+ segments:
92
+ - 1
93
+ - 5
94
+ - 2
95
+ version: 1.5.2
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ type: :development
99
+ prerelease: false
100
+ name: rcov
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ type: :development
113
+ prerelease: false
114
+ name: rspec
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 31
121
+ segments:
122
+ - 2
123
+ - 4
124
+ - 0
125
+ version: 2.4.0
126
+ requirement: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ type: :development
129
+ prerelease: false
130
+ name: rspec
131
+ version_requirements: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 31
137
+ segments:
138
+ - 2
139
+ - 4
140
+ - 0
141
+ version: 2.4.0
142
+ requirement: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ type: :runtime
145
+ prerelease: false
146
+ name: activesupport
147
+ version_requirements: &id009 !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 1
153
+ segments:
154
+ - 3
155
+ - 0
156
+ - 3
157
+ version: 3.0.3
158
+ requirement: *id009
159
+ - !ruby/object:Gem::Dependency
160
+ type: :runtime
161
+ prerelease: false
162
+ name: multipart-post
163
+ version_requirements: &id010 !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3
169
+ segments:
170
+ - 0
171
+ version: "0"
172
+ requirement: *id010
173
+ description: Provides basic methods to access the Issuu API
174
+ email: bastien.vaucher@gmail.com
175
+ executables: []
176
+
177
+ extensions: []
178
+
179
+ extra_rdoc_files:
180
+ - LICENSE.txt
181
+ - README.rdoc
182
+ files:
183
+ - .document
184
+ - .rspec
185
+ - Gemfile
186
+ - Gemfile.lock
187
+ - LICENSE.txt
188
+ - README.rdoc
189
+ - Rakefile
190
+ - VERSION
191
+ - issuu.gemspec
192
+ - lib/issuu.rb
193
+ - lib/issuu/bookmark.rb
194
+ - lib/issuu/cli.rb
195
+ - lib/issuu/document.rb
196
+ - lib/issuu/folder.rb
197
+ - lib/issuu/parameter_set.rb
198
+ - spec/issuu/bookmark_spec.rb
199
+ - spec/issuu/document_spec.rb
200
+ - spec/issuu/folder_spec.rb
201
+ - spec/spec_helper.rb
202
+ has_rdoc: true
203
+ homepage: http://github.com/bastien/issuu
204
+ licenses:
205
+ - MIT
206
+ post_install_message:
207
+ rdoc_options: []
208
+
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ hash: 3
217
+ segments:
218
+ - 0
219
+ version: "0"
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ hash: 3
226
+ segments:
227
+ - 0
228
+ version: "0"
229
+ requirements: []
230
+
231
+ rubyforge_project:
232
+ rubygems_version: 1.3.7
233
+ signing_key:
234
+ specification_version: 3
235
+ summary: Issuu API
236
+ test_files:
237
+ - spec/issuu/bookmark_spec.rb
238
+ - spec/issuu/document_spec.rb
239
+ - spec/issuu/folder_spec.rb
240
+ - spec/spec_helper.rb