cloudprint 0.0.2 → 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/.gitignore +4 -0
- data/Gemfile +2 -14
- data/Gemfile.lock +15 -25
- data/Rakefile +6 -55
- data/cloudprint.gemspec +25 -59
- data/lib/cloudprint.rb +6 -0
- data/lib/cloudprint/connection.rb +10 -0
- data/lib/cloudprint/print_job.rb +16 -3
- data/lib/cloudprint/printer.rb +2 -1
- data/lib/cloudprint/version.rb +3 -0
- data/test/cloudprint_test.rb +22 -18
- data/test/connection_test.rb +25 -15
- data/test/fixtures/ruby.png +0 -0
- data/test/helper.rb +9 -3
- data/test/print_job_test.rb +31 -15
- data/test/printer_test.rb +35 -15
- metadata +70 -43
- data/VERSION +0 -1
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,16 +1,4 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
gem "oauth2", "~> 0.5.0"
|
3
|
-
gem "json"
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
gem "jeweler", "~> 1.6.4"
|
8
|
-
end
|
9
|
-
|
10
|
-
group :test do
|
11
|
-
gem "test-unit", ">= 0"
|
12
|
-
# gem "net-http-spy"
|
13
|
-
gem "rcov", ">= 0"
|
14
|
-
gem "mocha", ">= 0"
|
15
|
-
gem "ruby-debug"
|
16
|
-
end
|
3
|
+
# Specify your gem's dependencies in cloudprint.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,48 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cloudprint (0.0.2)
|
5
|
+
json
|
6
|
+
oauth2 (~> 0.5.2)
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: http://rubygems.org/
|
3
10
|
specs:
|
4
11
|
addressable (2.2.7)
|
5
|
-
columnize (0.3.6)
|
6
12
|
faraday (0.7.6)
|
7
13
|
addressable (~> 2.2)
|
8
14
|
multipart-post (~> 1.1)
|
9
15
|
rack (~> 1.1)
|
10
|
-
|
11
|
-
jeweler (1.6.4)
|
12
|
-
bundler (~> 1.0)
|
13
|
-
git (>= 1.2.5)
|
14
|
-
rake
|
15
|
-
json (1.6.5)
|
16
|
-
linecache (0.46)
|
17
|
-
rbx-require-relative (> 0.0.4)
|
16
|
+
json (1.6.6)
|
18
17
|
metaclass (0.0.1)
|
19
|
-
mocha (0.10.
|
18
|
+
mocha (0.10.5)
|
20
19
|
metaclass (~> 0.0.1)
|
21
|
-
multi_json (1.
|
20
|
+
multi_json (1.2.0)
|
22
21
|
multipart-post (1.1.5)
|
23
22
|
oauth2 (0.5.2)
|
24
23
|
faraday (~> 0.7)
|
25
24
|
multi_json (~> 1.0)
|
26
25
|
rack (1.4.1)
|
27
26
|
rake (0.9.2.2)
|
28
|
-
|
29
|
-
|
30
|
-
ruby-debug (0.10.4)
|
31
|
-
columnize (>= 0.1)
|
32
|
-
ruby-debug-base (~> 0.10.4.0)
|
33
|
-
ruby-debug-base (0.10.4)
|
34
|
-
linecache (>= 0.3)
|
35
|
-
test-unit (2.4.7)
|
27
|
+
shoulda-context (1.0.0)
|
28
|
+
test-unit (2.4.8)
|
36
29
|
|
37
30
|
PLATFORMS
|
38
31
|
ruby
|
39
32
|
|
40
33
|
DEPENDENCIES
|
41
|
-
|
42
|
-
jeweler (~> 1.6.4)
|
43
|
-
json
|
34
|
+
cloudprint!
|
44
35
|
mocha
|
45
|
-
|
46
|
-
|
47
|
-
ruby-debug
|
36
|
+
rake
|
37
|
+
shoulda-context
|
48
38
|
test-unit
|
data/Rakefile
CHANGED
@@ -1,57 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "cloudprint"
|
18
|
-
gem.homepage = "http://github.com/minciue/cloudprint"
|
19
|
-
#noinspection RubyResolve
|
20
|
-
gem.license = "MIT"
|
21
|
-
gem.summary = %Q{This library provides a ruby-esque interface to Google Cloud Print.}
|
22
|
-
gem.description = %Q{This library provides a ruby-esque interface to Google Cloud Print.\ncloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported.}
|
23
|
-
gem.email = "eugen@lesseverything.com"
|
24
|
-
#noinspection RubyResolve
|
25
|
-
gem.authors = ["Eugen Minciu"]
|
26
|
-
# dependencies defined in Gemfile
|
27
|
-
end
|
28
|
-
Jeweler::RubygemsDotOrgTasks.new
|
29
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
30
2
|
require 'rake/testtask'
|
31
|
-
Rake::TestTask.new(:test) do |test|
|
32
|
-
test.libs << 'lib' << 'test'
|
33
|
-
test.pattern = 'test/*_test.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
3
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# test.rcov_opts << '--exclude "gems/*"'
|
43
|
-
#end
|
44
|
-
|
45
|
-
task :default => :test
|
46
|
-
|
47
|
-
require 'rake/rdoctask'
|
48
|
-
Rake::RDocTask.new do |rdoc|
|
49
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
-
|
51
|
-
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title = "cloudprint #{version}"
|
53
|
-
#noinspection RubyResolve
|
54
|
-
rdoc.rdoc_files.include('README*')
|
55
|
-
#noinspection RubyResolve
|
56
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
-
end
|
4
|
+
Rake::TestTask.new(:test) do |test|
|
5
|
+
test.libs << 'lib' << 'test'
|
6
|
+
test.pattern = 'test/*_test.rb'
|
7
|
+
test.verbose = true
|
8
|
+
end
|
data/cloudprint.gemspec
CHANGED
@@ -1,66 +1,32 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cloudprint/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = "cloudprint"
|
7
|
+
s.version = Cloudprint::VERSION
|
8
|
+
s.authors = ["Eugen Minciu"]
|
9
|
+
s.email = ["eugen@lesseverything.com"]
|
10
|
+
s.homepage = "http://github.com/minciue/cloudprint"
|
11
|
+
s.licenses = ["MIT"]
|
12
|
+
s.summary = "This library provides a ruby-esque interface to Google Cloud Print."
|
13
|
+
s.description = <<-DESC
|
14
|
+
This library provides a ruby-esque interface to Google Cloud Print.
|
15
|
+
cloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported."
|
16
|
+
DESC
|
9
17
|
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.date = %q{2012-02-28}
|
13
|
-
s.description = %q{This library provides a ruby-esque interface to Google Cloud Print.
|
14
|
-
cloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported.}
|
15
|
-
s.email = %q{eugen@lesseverything.com}
|
16
|
-
s.extra_rdoc_files = [
|
17
|
-
"LICENSE.txt",
|
18
|
-
"README.rdoc"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
".document",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"README.rdoc",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"cloudprint.gemspec",
|
29
|
-
"lib/cloudprint.rb",
|
30
|
-
"lib/cloudprint/connection.rb",
|
31
|
-
"lib/cloudprint/print_job.rb",
|
32
|
-
"lib/cloudprint/printer.rb",
|
33
|
-
"test/cloudprint_test.rb",
|
34
|
-
"test/connection_test.rb",
|
35
|
-
"test/helper.rb",
|
36
|
-
"test/print_job_test.rb",
|
37
|
-
"test/printer_test.rb"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/minciue/cloudprint}
|
40
|
-
s.licenses = ["MIT"]
|
41
|
-
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.4.2}
|
43
|
-
s.summary = %q{This library provides a ruby-esque interface to Google Cloud Print.}
|
18
|
+
s.add_dependency 'oauth2', '~> 0.5.2'
|
19
|
+
s.add_dependency 'json'
|
44
20
|
|
45
|
-
|
46
|
-
|
21
|
+
s.add_development_dependency 'mocha'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'shoulda-context'
|
24
|
+
s.add_development_dependency 'test-unit'
|
47
25
|
|
48
|
-
|
49
|
-
s.add_runtime_dependency(%q<oauth2>, ["~> 0.5.0"])
|
50
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
51
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<oauth2>, ["~> 0.5.0"])
|
55
|
-
s.add_dependency(%q<json>, [">= 0"])
|
56
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
|
-
end
|
59
|
-
else
|
60
|
-
s.add_dependency(%q<oauth2>, ["~> 0.5.0"])
|
61
|
-
s.add_dependency(%q<json>, [">= 0"])
|
62
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
64
|
-
end
|
65
|
-
end
|
26
|
+
s.rubyforge_project = "cloudprint"
|
66
27
|
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
end
|
data/lib/cloudprint.rb
CHANGED
@@ -3,6 +3,7 @@ require "bundler/setup"
|
|
3
3
|
require "oauth2"
|
4
4
|
require "json"
|
5
5
|
|
6
|
+
require "cloudprint/version"
|
6
7
|
require "cloudprint/printer"
|
7
8
|
require "cloudprint/connection"
|
8
9
|
require "cloudprint/print_job"
|
@@ -45,6 +46,11 @@ module CloudPrint
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def self.refresh_token=(new_token)
|
50
|
+
@refresh_token = new_token
|
51
|
+
get_new_access_token
|
52
|
+
end
|
53
|
+
|
48
54
|
private
|
49
55
|
|
50
56
|
def self.access_token_valid?
|
@@ -15,6 +15,11 @@ module CloudPrint
|
|
15
15
|
parse_response(response)
|
16
16
|
end
|
17
17
|
|
18
|
+
def multipart_post(path, params = {})
|
19
|
+
response = request(:multipart, path, params)
|
20
|
+
parse_response(response)
|
21
|
+
end
|
22
|
+
|
18
23
|
private
|
19
24
|
|
20
25
|
def parse_response(response)
|
@@ -45,6 +50,11 @@ module CloudPrint
|
|
45
50
|
uri = options[:uri]
|
46
51
|
|
47
52
|
request = case method
|
53
|
+
when :multipart
|
54
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
55
|
+
# Convert hash keys to strings, because that's what Net::HTTPGenericRequest#encode_multipart_form_data assumes they are
|
56
|
+
req.set_form(options[:params].inject({}) {|memo, (k,v)| memo[k.to_s] = v; memo }, 'multipart/form-data')
|
57
|
+
req
|
48
58
|
when :post
|
49
59
|
req = Net::HTTP::Post.new(uri.request_uri)
|
50
60
|
req.set_form_data(options[:params])
|
data/lib/cloudprint/print_job.rb
CHANGED
@@ -8,13 +8,18 @@ module CloudPrint
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.find(jobid)
|
11
|
-
|
12
|
-
return nil unless response['jobs'].is_a?(Array)
|
13
|
-
job = response['jobs'].first
|
11
|
+
job = find_by_id(jobid)
|
14
12
|
return nil if job.nil?
|
15
13
|
self.new(:id => job['id'], :status => job['status'], :error_code => job['errorCode'])
|
16
14
|
end
|
17
15
|
|
16
|
+
def refresh!
|
17
|
+
job = self.class.find_by_id(id)
|
18
|
+
@status = job['status']
|
19
|
+
@error_code = job['errorCode']
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
18
23
|
def queued?
|
19
24
|
status == "QUEUED"
|
20
25
|
end
|
@@ -30,5 +35,13 @@ module CloudPrint
|
|
30
35
|
def error?
|
31
36
|
status == "ERROR"
|
32
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.find_by_id(id)
|
42
|
+
response = CloudPrint.connection.get('/jobs') || {}
|
43
|
+
return nil unless response['jobs'].is_a?(Array)
|
44
|
+
response['jobs'].select{ |job| job['id'] == id }.first
|
45
|
+
end
|
33
46
|
end
|
34
47
|
end
|
data/lib/cloudprint/printer.rb
CHANGED
@@ -9,7 +9,8 @@ module CloudPrint
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def print(options)
|
12
|
-
|
12
|
+
method = options[:content].is_a?(IO) ? :multipart_post : :post
|
13
|
+
response = CloudPrint.connection.send(method, '/submit', :printerid => self.id, :title => options[:title], :content => options[:content], :contentType => options[:content_type]) || {}
|
13
14
|
CloudPrint::PrintJob.new(:id => response["job"]["id"], :status => response["job"]["status"], :error_code => response["job"]["errorCode"])
|
14
15
|
end
|
15
16
|
|
data/test/cloudprint_test.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require "cloudprint"
|
1
|
+
require 'helper'
|
3
2
|
|
4
3
|
class CloudPrintTest < Test::Unit::TestCase
|
5
4
|
def setup
|
6
5
|
stub_access_token
|
7
6
|
end
|
8
7
|
|
9
|
-
|
8
|
+
should "have CloudPrint" do
|
10
9
|
assert_nothing_raised { CloudPrint }
|
11
10
|
end
|
12
11
|
|
13
|
-
|
12
|
+
should "be able to set up CloudPrint" do
|
14
13
|
assert CloudPrint.respond_to?(:setup)
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
should "stores a client id, client secret, callback URL and refresh token" do
|
18
17
|
CloudPrint.setup(:refresh_token => 'refresh_token', :client_id => 'client_id', :client_secret => 'client_secret', :callback_url => 'callback_url')
|
19
18
|
assert_equal 'client_id', CloudPrint.client_id
|
20
19
|
assert_equal 'client_secret', CloudPrint.client_secret
|
@@ -22,13 +21,13 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
22
21
|
assert_equal 'callback_url', CloudPrint.callback_url
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
should "check if the access token is still valid" do
|
26
25
|
CloudPrint.expects(:access_token_valid?).returns(true)
|
27
26
|
CloudPrint.stubs(:get_existing_access_token).returns(mock_access_token)
|
28
27
|
CloudPrint.access_token
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
should "get the existing access token use it if it's still valid" do
|
32
31
|
token = mock_access_token
|
33
32
|
token.expects(:token)
|
34
33
|
|
@@ -38,44 +37,44 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
38
37
|
CloudPrint.access_token
|
39
38
|
end
|
40
39
|
|
41
|
-
|
40
|
+
should "get the existing access token get a new one if it's no longer valid" do
|
42
41
|
CloudPrint.stubs(:access_token_valid?).returns(false)
|
43
42
|
CloudPrint.expects(:get_new_access_token).returns(mock_access_token)
|
44
43
|
CloudPrint.access_token
|
45
44
|
end
|
46
45
|
|
47
|
-
|
46
|
+
should "not set a nil access token" do
|
48
47
|
CloudPrint.expects(:get_existing_access_token).returns(nil)
|
49
48
|
CloudPrint.expects(:get_new_access_token).returns(mock_access_token)
|
50
49
|
CloudPrint.access_token
|
51
50
|
end
|
52
51
|
|
53
|
-
|
52
|
+
should "not have a nil access token" do
|
54
53
|
CloudPrint.expects(:get_existing_access_token).at_least_once.returns(mock_access_token(nil))
|
55
54
|
CloudPrint.expects(:get_new_access_token).returns(mock_access_token)
|
56
55
|
CloudPrint.access_token
|
57
56
|
end
|
58
57
|
|
59
|
-
|
58
|
+
should "not allow a blank string for an access token" do
|
60
59
|
CloudPrint.expects(:get_existing_access_token).at_least_once.returns(mock_access_token(' '))
|
61
60
|
CloudPrint.expects(:get_new_access_token).returns(mock_access_token)
|
62
61
|
CloudPrint.access_token
|
63
62
|
end
|
64
63
|
|
65
|
-
|
64
|
+
should "have a string as an access token" do
|
66
65
|
CloudPrint.stubs(:access_token_valid?).returns(true)
|
67
66
|
CloudPrint.expects(:get_new_access_token).never
|
68
67
|
CloudPrint.expects(:get_existing_access_token).at_least_once.returns(mock_access_token)
|
69
68
|
assert_equal("token", CloudPrint.access_token)
|
70
69
|
end
|
71
70
|
|
72
|
-
|
71
|
+
should "initialize an OAuth2 client when getting a new access token" do
|
73
72
|
CloudPrint.stubs(:access_token_valid?).returns(false)
|
74
73
|
CloudPrint.expects(:oauth_client)
|
75
74
|
CloudPrint.access_token
|
76
75
|
end
|
77
76
|
|
78
|
-
|
77
|
+
should "set up an oauth client" do
|
79
78
|
CloudPrint.setup(:client_id => 'client_id', :client_secret => 'client_secret', :callback_url => "http://test.com/callback")
|
80
79
|
CloudPrint.stubs(:access_token_valid?).returns(false)
|
81
80
|
OAuth2::Client.expects(:new).with('client_id', 'client_secret',
|
@@ -87,7 +86,7 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
87
86
|
CloudPrint.access_token
|
88
87
|
end
|
89
88
|
|
90
|
-
|
89
|
+
should "initialize an access token when getting a new access token" do
|
91
90
|
CloudPrint.setup(:refresh_token => "refresh_token")
|
92
91
|
CloudPrint.stubs(:access_token_valid?).returns(false)
|
93
92
|
|
@@ -95,7 +94,7 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
95
94
|
CloudPrint.access_token
|
96
95
|
end
|
97
96
|
|
98
|
-
|
97
|
+
should "get an auth token from oauth2" do
|
99
98
|
token = mock_access_token
|
100
99
|
CloudPrint.setup(:refresh_token => "refresh_token")
|
101
100
|
CloudPrint.stubs(:access_token_valid?).returns(false)
|
@@ -106,7 +105,7 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
106
105
|
CloudPrint.access_token
|
107
106
|
end
|
108
107
|
|
109
|
-
|
108
|
+
should "expire if the access token is invalid" do
|
110
109
|
token = mock_access_token
|
111
110
|
token.stubs(:expired?).returns(true)
|
112
111
|
CloudPrint.stubs(:get_existing_access_token).returns()
|
@@ -115,4 +114,9 @@ class CloudPrintTest < Test::Unit::TestCase
|
|
115
114
|
CloudPrint.expects(:get_new_access_token).returns(token)
|
116
115
|
CloudPrint.access_token
|
117
116
|
end
|
118
|
-
|
117
|
+
|
118
|
+
should "get a new access token when setting a new refresh token" do
|
119
|
+
CloudPrint.expects(:get_new_access_token)
|
120
|
+
CloudPrint.refresh_token = 'new_token'
|
121
|
+
end
|
122
|
+
end
|
data/test/connection_test.rb
CHANGED
@@ -5,29 +5,31 @@ class ConnectionTest < Test::Unit::TestCase
|
|
5
5
|
@connection = CloudPrint::Connection.new
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
assert_nothing_raised { CloudPrint::Connection }
|
10
|
-
end
|
11
|
-
|
12
|
-
test "you can get using a connection" do
|
8
|
+
should "get using a connection" do
|
13
9
|
stub
|
14
10
|
any_connection.stubs(:request)
|
15
11
|
@connection.get('/foo')
|
16
12
|
end
|
17
13
|
|
18
|
-
|
14
|
+
should "post using a connection" do
|
19
15
|
stub
|
20
16
|
any_connection.stubs(:request)
|
21
17
|
@connection.post('/foo')
|
22
18
|
end
|
23
19
|
|
24
|
-
|
20
|
+
should "post multipart data using a connection" do
|
21
|
+
stub
|
22
|
+
any_connection.stubs(:request)
|
23
|
+
@connection.multipart_post('/foo')
|
24
|
+
end
|
25
|
+
|
26
|
+
should "make requests to the right url with POST" do
|
25
27
|
stub
|
26
28
|
@connection.expects(:make_http_request).with(:method => :post, :url => "https://www.google.com/cloudprint/submit", :params => {})
|
27
29
|
@connection.post('/submit')
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
should "build http connections and requests" do
|
31
33
|
stub
|
32
34
|
@connection.stubs(:build_request)
|
33
35
|
|
@@ -35,7 +37,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
35
37
|
@connection.post('/submit')
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
should "build http request with proper values" do
|
39
41
|
stub
|
40
42
|
@connection.stubs(:build_http_connection).returns(mock_http)
|
41
43
|
|
@@ -43,7 +45,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
43
45
|
@connection.post('/submit', {:text => "ohai!"})
|
44
46
|
end
|
45
47
|
|
46
|
-
|
48
|
+
should "build a URL when parameters are used" do
|
47
49
|
stub
|
48
50
|
@connection.stubs(:build_http_connection).returns(mock_http)
|
49
51
|
|
@@ -52,7 +54,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
52
54
|
@connection.get('/submit', params)
|
53
55
|
end
|
54
56
|
|
55
|
-
|
57
|
+
should "get from the correct URL when params are used" do
|
56
58
|
stub
|
57
59
|
|
58
60
|
params = { :text => 'ohai world' }
|
@@ -60,7 +62,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
60
62
|
@connection.get('/submit', params)
|
61
63
|
end
|
62
64
|
|
63
|
-
|
65
|
+
should "use the access token" do
|
64
66
|
stub
|
65
67
|
@connection.stubs(:build_http_connection).returns(mock_http)
|
66
68
|
|
@@ -68,13 +70,13 @@ class ConnectionTest < Test::Unit::TestCase
|
|
68
70
|
@connection.get('/submit')
|
69
71
|
end
|
70
72
|
|
71
|
-
|
73
|
+
should "parse the response" do
|
72
74
|
stub
|
73
75
|
@connection.expects(:parse_response)
|
74
76
|
@connection.get('/submit')
|
75
77
|
end
|
76
78
|
|
77
|
-
|
79
|
+
should "parse the response as JSON" do
|
78
80
|
stub(:parsing_responses => false)
|
79
81
|
response = mock('response')
|
80
82
|
response.stubs(:body).returns('')
|
@@ -84,6 +86,14 @@ class ConnectionTest < Test::Unit::TestCase
|
|
84
86
|
@connection.get('/submit')
|
85
87
|
end
|
86
88
|
|
89
|
+
should "setup form properly on multipart POSTs" do
|
90
|
+
stub
|
91
|
+
|
92
|
+
file = mock('File')
|
93
|
+
Net::HTTP::Post.any_instance.expects(:set_form).with({'contentType' => 'application/pdf', 'content' => file}, 'multipart/form-data')
|
94
|
+
@connection.multipart_post('/submit', { :contentType => 'application/pdf', :content => file })
|
95
|
+
end
|
96
|
+
|
87
97
|
private
|
88
98
|
|
89
99
|
def stub(options = {})
|
@@ -92,4 +102,4 @@ class ConnectionTest < Test::Unit::TestCase
|
|
92
102
|
stub_http if options[:http]
|
93
103
|
stub_parsing_responses if options[:parsing_responses]
|
94
104
|
end
|
95
|
-
end
|
105
|
+
end
|
Binary file
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'cloudprint'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda/context'
|
4
|
+
require 'mocha'
|
3
5
|
|
4
6
|
class Test::Unit::TestCase
|
5
7
|
def any_connection
|
@@ -54,4 +56,8 @@ class Test::Unit::TestCase
|
|
54
56
|
CloudPrint.stubs(:connection).returns(fake_connection)
|
55
57
|
@connection.stub_everything
|
56
58
|
end
|
57
|
-
|
59
|
+
|
60
|
+
def fixture_file(filename)
|
61
|
+
File.join(File.dirname(__FILE__), 'fixtures', filename)
|
62
|
+
end
|
63
|
+
end
|
data/test/print_job_test.rb
CHANGED
@@ -2,24 +2,24 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class PrintJobTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
# TODO: Is it necessary to pass a fake token to #setup?
|
6
|
+
CloudPrint.setup(:refresh_token => 'refresh_token')
|
6
7
|
stub_connection
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
-
fake_connection.stubs(:
|
10
|
+
should "find a job" do
|
11
|
+
fake_connection.stubs(:get).with('/jobs').returns(jobs_response)
|
11
12
|
assert CloudPrint::PrintJob.find('job_id').is_a?(CloudPrint::PrintJob)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
fake_connection.expects(:post).with('/jobs', :jobid => 'job_id').returns({})
|
15
|
+
should 'perform a remote request when finding a job' do
|
16
|
+
fake_connection.expects(:get).with('/jobs').returns({})
|
17
17
|
|
18
18
|
CloudPrint::PrintJob.find('job_id')
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
fake_connection.stubs(:
|
21
|
+
should 'gets the job details' do
|
22
|
+
fake_connection.stubs(:get).with('/jobs').returns(jobs_response)
|
23
23
|
job = CloudPrint::PrintJob.find('job_id')
|
24
24
|
|
25
25
|
assert_equal 'job_id', job.id
|
@@ -27,7 +27,7 @@ class PrintJobTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal 'Error', job.error_code
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
should 'recognize a job as queued' do
|
31
31
|
job = CloudPrint::PrintJob.new(:status => "QUEUED")
|
32
32
|
|
33
33
|
assert !job.done?
|
@@ -37,7 +37,7 @@ class PrintJobTest < Test::Unit::TestCase
|
|
37
37
|
assert job.queued?
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
should 'recognize a job as in progress' do
|
41
41
|
job = CloudPrint::PrintJob.new(:status => "IN_PROGRESS")
|
42
42
|
|
43
43
|
assert !job.done?
|
@@ -47,7 +47,7 @@ class PrintJobTest < Test::Unit::TestCase
|
|
47
47
|
assert job.in_progress?
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
should 'recognize a job as done' do
|
51
51
|
job = CloudPrint::PrintJob.new(:status => "DONE")
|
52
52
|
|
53
53
|
assert !job.in_progress?
|
@@ -57,7 +57,7 @@ class PrintJobTest < Test::Unit::TestCase
|
|
57
57
|
assert job.done?
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
should "recognize a job has an error" do
|
61
61
|
job = CloudPrint::PrintJob.new(:status => "ERROR")
|
62
62
|
|
63
63
|
assert !job.done?
|
@@ -66,9 +66,25 @@ class PrintJobTest < Test::Unit::TestCase
|
|
66
66
|
|
67
67
|
assert job.error?
|
68
68
|
end
|
69
|
+
|
70
|
+
should "refresh a job" do
|
71
|
+
job = CloudPrint::PrintJob.new(:status => "IN_PROGRESS")
|
72
|
+
CloudPrint::PrintJob.stubs(:find_by_id).returns({"id" => "job_id", "status" => "DONE", "errorCode" => "42"})
|
73
|
+
|
74
|
+
assert_equal job, job.refresh!
|
75
|
+
|
76
|
+
assert job.done?
|
77
|
+
assert_equal "42", job.error_code
|
78
|
+
end
|
79
|
+
|
69
80
|
private
|
70
81
|
|
71
|
-
def
|
72
|
-
{
|
82
|
+
def jobs_response
|
83
|
+
{
|
84
|
+
"jobs" => [
|
85
|
+
{"id" => "other_job", "status" => "status", "errorCode" => "Error"},
|
86
|
+
{"id" => "job_id", "status" => "status", "errorCode" => "Error"}
|
87
|
+
]
|
88
|
+
}
|
73
89
|
end
|
74
|
-
end
|
90
|
+
end
|
data/test/printer_test.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
1
|
require "helper"
|
2
2
|
class PrinterTest < Test::Unit::TestCase
|
3
3
|
def setup
|
4
|
-
|
4
|
+
# TODO: Is it necessary to pass a fake token to #setup?
|
5
|
+
CloudPrint.setup(:refresh_token => 'refresh_token')
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
-
assert_nothing_raised { CloudPrint::Printer }
|
9
|
-
end
|
10
|
-
|
11
|
-
test "initializing a printer" do
|
8
|
+
should "initialize a printer" do
|
12
9
|
printer = CloudPrint::Printer.new(:id => 'printer_id', :status => 'online', :name => "My Printer")
|
13
10
|
assert_equal 'printer_id', printer.id
|
14
11
|
assert_equal 'online', printer.status
|
15
12
|
assert_equal 'My Printer', printer.name
|
16
13
|
end
|
17
14
|
|
18
|
-
|
15
|
+
should "have tags" do
|
19
16
|
printer = CloudPrint::Printer.new(:id => 'printer_id', :status => 'online', :name => "My Printer")
|
20
17
|
assert_equal printer.tags, {}
|
21
18
|
|
@@ -23,26 +20,26 @@ class PrinterTest < Test::Unit::TestCase
|
|
23
20
|
assert_equal printer.tags, {"email" => "a@b.com"}
|
24
21
|
end
|
25
22
|
|
26
|
-
|
23
|
+
should "get a connection when finding a printer by its id" do
|
27
24
|
fake_connection.stubs(:get).returns(one_printer_hash)
|
28
25
|
|
29
26
|
CloudPrint.expects(:connection).returns(fake_connection)
|
30
27
|
CloudPrint::Printer.find('printer')
|
31
28
|
end
|
32
29
|
|
33
|
-
|
30
|
+
should "call a remote request when finding a printer by its id" do
|
34
31
|
fake_connection.expects(:get).returns(one_printer_hash)
|
35
32
|
stub_connection
|
36
33
|
CloudPrint::Printer.find('printer')
|
37
34
|
end
|
38
35
|
|
39
|
-
|
36
|
+
should "call a remote request with the proper params when finding a printer" do
|
40
37
|
fake_connection.expects(:get).with('/printer', :printerid => 'printer').returns(one_printer_hash)
|
41
38
|
stub_connection
|
42
39
|
CloudPrint::Printer.find('printer')
|
43
40
|
end
|
44
41
|
|
45
|
-
|
42
|
+
should "initialize a new object when finding a printer" do
|
46
43
|
fake_connection.stubs(:get).returns(one_printer_hash)
|
47
44
|
stub_connection
|
48
45
|
printer = CloudPrint::Printer.find('my_printer')
|
@@ -52,7 +49,7 @@ class PrinterTest < Test::Unit::TestCase
|
|
52
49
|
assert_equal printer.tags, {'email' => 'a@b.com' }
|
53
50
|
end
|
54
51
|
|
55
|
-
|
52
|
+
should "initialize an array of printers when finding all printers" do
|
56
53
|
fake_connection.stubs(:get).returns(multiple_printer_hash)
|
57
54
|
stub_connection
|
58
55
|
printers = CloudPrint::Printer.all
|
@@ -64,21 +61,28 @@ class PrinterTest < Test::Unit::TestCase
|
|
64
61
|
assert_equal 'Second Printer', second_printer.name
|
65
62
|
end
|
66
63
|
|
67
|
-
|
64
|
+
should "print stuff" do
|
68
65
|
fake_connection.expects(:post).with('/submit', connection_print_params).returns(empty_job)
|
69
66
|
stub_connection
|
70
67
|
|
71
68
|
print_stuff
|
72
69
|
end
|
73
70
|
|
74
|
-
|
71
|
+
should "return a job" do
|
75
72
|
stub_connection
|
76
73
|
fake_connection.stubs(:post).with('/submit', connection_print_params).returns(empty_job)
|
77
74
|
job = print_stuff
|
78
75
|
assert job.is_a?(CloudPrint::PrintJob)
|
79
76
|
end
|
80
77
|
|
81
|
-
|
78
|
+
should "print file" do
|
79
|
+
fake_connection.expects(:multipart_post).with('/submit', connection_print_file_params).returns(empty_job)
|
80
|
+
stub_connection
|
81
|
+
|
82
|
+
print_file
|
83
|
+
end
|
84
|
+
|
85
|
+
should "print jobs returning an id and a status" do
|
82
86
|
stub_connection
|
83
87
|
fake_connection.expects(:post).with('/submit', connection_print_params).returns({"success" => true, "job" => {"id" => "job_id", "status" => 'status'}})
|
84
88
|
job = print_stuff
|
@@ -106,6 +110,19 @@ class PrinterTest < Test::Unit::TestCase
|
|
106
110
|
{ :printerid => 'printer', :title => "Hello World", :content => "<h1>ohai!</h1>", :contentType => "text/html" }
|
107
111
|
end
|
108
112
|
|
113
|
+
def print_file
|
114
|
+
printer = CloudPrint::Printer.new(:id => 'printer')
|
115
|
+
printer.print(print_file_params)
|
116
|
+
end
|
117
|
+
|
118
|
+
def print_file_params
|
119
|
+
{ :title => "Ruby!", :content => ruby_png_fixture, :content_type => "image/png" }
|
120
|
+
end
|
121
|
+
|
122
|
+
def connection_print_file_params
|
123
|
+
{ :printerid => 'printer', :title => "Ruby!", :content => ruby_png_fixture, :contentType => "image/png" }
|
124
|
+
end
|
125
|
+
|
109
126
|
def one_printer_hash
|
110
127
|
{'printers' =>[{'id' => 'my_printer', 'status' => 'online', 'name' => "My Printer", 'tags' => { 'email' => 'a@b.com'}}]}
|
111
128
|
end
|
@@ -117,5 +134,8 @@ class PrinterTest < Test::Unit::TestCase
|
|
117
134
|
]}
|
118
135
|
end
|
119
136
|
|
137
|
+
def ruby_png_fixture
|
138
|
+
@ruby_png_fixture ||= File.open(fixture_file('ruby.png'))
|
139
|
+
end
|
120
140
|
|
121
141
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eugen Minciu
|
@@ -15,28 +15,29 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-10 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
22
|
+
name: oauth2
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
29
|
+
hash: 15
|
29
30
|
segments:
|
30
31
|
- 0
|
31
32
|
- 5
|
32
|
-
-
|
33
|
-
version: 0.5.
|
34
|
-
requirement: *id001
|
35
|
-
prerelease: false
|
36
|
-
name: oauth2
|
37
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
- 2
|
34
|
+
version: 0.5.2
|
38
35
|
type: :runtime
|
39
|
-
version_requirements:
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: json
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
43
|
- - ">="
|
@@ -45,67 +46,93 @@ dependencies:
|
|
45
46
|
segments:
|
46
47
|
- 0
|
47
48
|
version: "0"
|
48
|
-
|
49
|
-
|
50
|
-
name: json
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
53
|
-
|
52
|
+
name: mocha
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
55
|
none: false
|
55
56
|
requirements:
|
56
|
-
- -
|
57
|
+
- - ">="
|
57
58
|
- !ruby/object:Gem::Version
|
58
|
-
hash:
|
59
|
+
hash: 3
|
59
60
|
segments:
|
60
|
-
- 1
|
61
61
|
- 0
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
prerelease: false
|
66
|
-
name: bundler
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
67
65
|
- !ruby/object:Gem::Dependency
|
66
|
+
name: rake
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
68
77
|
type: :development
|
69
|
-
version_requirements:
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: shoulda-context
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
70
83
|
none: false
|
71
84
|
requirements:
|
72
|
-
- -
|
85
|
+
- - ">="
|
73
86
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
87
|
+
hash: 3
|
75
88
|
segments:
|
76
|
-
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: test-unit
|
81
95
|
prerelease: false
|
82
|
-
|
83
|
-
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
type: :development
|
106
|
+
version_requirements: *id006
|
107
|
+
description: |
|
84
108
|
This library provides a ruby-esque interface to Google Cloud Print.
|
85
|
-
cloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported.
|
86
|
-
|
109
|
+
cloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported."
|
110
|
+
|
111
|
+
email:
|
112
|
+
- eugen@lesseverything.com
|
87
113
|
executables: []
|
88
114
|
|
89
115
|
extensions: []
|
90
116
|
|
91
|
-
extra_rdoc_files:
|
92
|
-
|
93
|
-
- README.rdoc
|
117
|
+
extra_rdoc_files: []
|
118
|
+
|
94
119
|
files:
|
95
120
|
- .document
|
121
|
+
- .gitignore
|
96
122
|
- Gemfile
|
97
123
|
- Gemfile.lock
|
98
124
|
- LICENSE.txt
|
99
125
|
- README.rdoc
|
100
126
|
- Rakefile
|
101
|
-
- VERSION
|
102
127
|
- cloudprint.gemspec
|
103
128
|
- lib/cloudprint.rb
|
104
129
|
- lib/cloudprint/connection.rb
|
105
130
|
- lib/cloudprint/print_job.rb
|
106
131
|
- lib/cloudprint/printer.rb
|
132
|
+
- lib/cloudprint/version.rb
|
107
133
|
- test/cloudprint_test.rb
|
108
134
|
- test/connection_test.rb
|
135
|
+
- test/fixtures/ruby.png
|
109
136
|
- test/helper.rb
|
110
137
|
- test/print_job_test.rb
|
111
138
|
- test/printer_test.rb
|
@@ -138,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
165
|
version: "0"
|
139
166
|
requirements: []
|
140
167
|
|
141
|
-
rubyforge_project:
|
168
|
+
rubyforge_project: cloudprint
|
142
169
|
rubygems_version: 1.4.2
|
143
170
|
signing_key:
|
144
171
|
specification_version: 3
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|