cloudprint 0.0.1 → 0.0.2
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/Gemfile +2 -4
- data/Gemfile.lock +3 -6
- data/README.rdoc +0 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/cloudprint.gemspec +7 -8
- data/lib/cloudprint.rb +3 -1
- data/lib/cloudprint/connection.rb +0 -1
- data/lib/cloudprint/print_job.rb +34 -0
- data/lib/cloudprint/printer.rb +6 -4
- data/test/helper.rb +9 -0
- data/test/print_job_test.rb +74 -0
- data/test/printer_test.rb +46 -18
- metadata +15 -25
data/Gemfile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
gem "oauth2"
|
3
|
-
#gem "curb"
|
4
|
-
gem "faraday"
|
2
|
+
gem "oauth2", "~> 0.5.0"
|
5
3
|
gem "json"
|
6
4
|
|
7
5
|
group :development do
|
@@ -11,7 +9,7 @@ end
|
|
11
9
|
|
12
10
|
group :test do
|
13
11
|
gem "test-unit", ">= 0"
|
14
|
-
gem "net-http-spy"
|
12
|
+
# gem "net-http-spy"
|
15
13
|
gem "rcov", ">= 0"
|
16
14
|
gem "mocha", ">= 0"
|
17
15
|
gem "ruby-debug"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.2.
|
4
|
+
addressable (2.2.7)
|
5
5
|
columnize (0.3.6)
|
6
6
|
faraday (0.7.6)
|
7
7
|
addressable (~> 2.2)
|
@@ -18,9 +18,8 @@ GEM
|
|
18
18
|
metaclass (0.0.1)
|
19
19
|
mocha (0.10.4)
|
20
20
|
metaclass (~> 0.0.1)
|
21
|
-
multi_json (1.0
|
21
|
+
multi_json (1.1.0)
|
22
22
|
multipart-post (1.1.5)
|
23
|
-
net-http-spy (0.2.1)
|
24
23
|
oauth2 (0.5.2)
|
25
24
|
faraday (~> 0.7)
|
26
25
|
multi_json (~> 1.0)
|
@@ -40,12 +39,10 @@ PLATFORMS
|
|
40
39
|
|
41
40
|
DEPENDENCIES
|
42
41
|
bundler (~> 1.0.0)
|
43
|
-
faraday
|
44
42
|
jeweler (~> 1.6.4)
|
45
43
|
json
|
46
44
|
mocha
|
47
|
-
|
48
|
-
oauth2
|
45
|
+
oauth2 (~> 0.5.0)
|
49
46
|
rcov
|
50
47
|
ruby-debug
|
51
48
|
test-unit
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/cloudprint.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cloudprint}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eugen Minciu"]
|
12
|
-
s.date = %q{2012-02-
|
12
|
+
s.date = %q{2012-02-28}
|
13
13
|
s.description = %q{This library provides a ruby-esque interface to Google Cloud Print.
|
14
14
|
cloudprint is a work in progress. I'll be adding documentation once all the basic GCP functionality is supported.}
|
15
15
|
s.email = %q{eugen@lesseverything.com}
|
@@ -28,10 +28,12 @@ cloudprint is a work in progress. I'll be adding documentation once all the basi
|
|
28
28
|
"cloudprint.gemspec",
|
29
29
|
"lib/cloudprint.rb",
|
30
30
|
"lib/cloudprint/connection.rb",
|
31
|
+
"lib/cloudprint/print_job.rb",
|
31
32
|
"lib/cloudprint/printer.rb",
|
32
33
|
"test/cloudprint_test.rb",
|
33
34
|
"test/connection_test.rb",
|
34
35
|
"test/helper.rb",
|
36
|
+
"test/print_job_test.rb",
|
35
37
|
"test/printer_test.rb"
|
36
38
|
]
|
37
39
|
s.homepage = %q{http://github.com/minciue/cloudprint}
|
@@ -44,21 +46,18 @@ cloudprint is a work in progress. I'll be adding documentation once all the basi
|
|
44
46
|
s.specification_version = 3
|
45
47
|
|
46
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<oauth2>, ["
|
48
|
-
s.add_runtime_dependency(%q<faraday>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<oauth2>, ["~> 0.5.0"])
|
49
50
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
50
51
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
52
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
52
53
|
else
|
53
|
-
s.add_dependency(%q<oauth2>, ["
|
54
|
-
s.add_dependency(%q<faraday>, [">= 0"])
|
54
|
+
s.add_dependency(%q<oauth2>, ["~> 0.5.0"])
|
55
55
|
s.add_dependency(%q<json>, [">= 0"])
|
56
56
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
57
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
58
|
end
|
59
59
|
else
|
60
|
-
s.add_dependency(%q<oauth2>, ["
|
61
|
-
s.add_dependency(%q<faraday>, [">= 0"])
|
60
|
+
s.add_dependency(%q<oauth2>, ["~> 0.5.0"])
|
62
61
|
s.add_dependency(%q<json>, [">= 0"])
|
63
62
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
63
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
data/lib/cloudprint.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
module CloudPrint
|
2
|
+
class PrintJob
|
3
|
+
attr_reader :id, :status, :error_code
|
4
|
+
def initialize(options = {})
|
5
|
+
@id = options[:id]
|
6
|
+
@status = options[:status]
|
7
|
+
@error_code = options[:error_code]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find(jobid)
|
11
|
+
response = CloudPrint.connection.post('/jobs', :jobid => jobid) || {}
|
12
|
+
return nil unless response['jobs'].is_a?(Array)
|
13
|
+
job = response['jobs'].first
|
14
|
+
return nil if job.nil?
|
15
|
+
self.new(:id => job['id'], :status => job['status'], :error_code => job['errorCode'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def queued?
|
19
|
+
status == "QUEUED"
|
20
|
+
end
|
21
|
+
|
22
|
+
def in_progress?
|
23
|
+
status == "IN_PROGRESS"
|
24
|
+
end
|
25
|
+
|
26
|
+
def done?
|
27
|
+
status == "DONE"
|
28
|
+
end
|
29
|
+
|
30
|
+
def error?
|
31
|
+
status == "ERROR"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/cloudprint/printer.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module CloudPrint
|
2
2
|
class Printer
|
3
|
-
attr_reader :id, :status, :name
|
3
|
+
attr_reader :id, :status, :name, :tags
|
4
4
|
def initialize(options = {})
|
5
5
|
@id = options[:id]
|
6
6
|
@status = options[:status]
|
7
7
|
@name = options[:name]
|
8
|
+
@tags = options[:tags] || {}
|
8
9
|
end
|
9
10
|
|
10
11
|
def print(options)
|
11
|
-
CloudPrint.connection.post('/submit', :printerid => self.id, :title => options[:title], :content => options[:content], :contentType => options[:content_type])
|
12
|
+
response = CloudPrint.connection.post('/submit', :printerid => self.id, :title => options[:title], :content => options[:content], :contentType => options[:content_type]) || {}
|
13
|
+
CloudPrint::PrintJob.new(:id => response["job"]["id"], :status => response["job"]["status"], :error_code => response["job"]["errorCode"])
|
12
14
|
end
|
13
15
|
|
14
16
|
class << self
|
@@ -26,8 +28,8 @@ module CloudPrint
|
|
26
28
|
private
|
27
29
|
|
28
30
|
def new_from_hash(hash)
|
29
|
-
Printer.new(:id => hash['id'], :status => hash['status'], :name => hash['name'])
|
31
|
+
Printer.new(:id => hash['id'], :status => hash['status'], :name => hash['name'], :tags => hash['tags'])
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
35
|
+
end
|
data/test/helper.rb
CHANGED
@@ -45,4 +45,13 @@ class Test::Unit::TestCase
|
|
45
45
|
def stub_oauth_client
|
46
46
|
CloudPrint.stubs(:oauth_client).returns(mock_oauth_client)
|
47
47
|
end
|
48
|
+
|
49
|
+
def fake_connection
|
50
|
+
@connection ||= mock('connection')
|
51
|
+
end
|
52
|
+
|
53
|
+
def stub_connection
|
54
|
+
CloudPrint.stubs(:connection).returns(fake_connection)
|
55
|
+
@connection.stub_everything
|
56
|
+
end
|
48
57
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class PrintJobTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
CloudPrint.setup('refresh_token')
|
6
|
+
stub_connection
|
7
|
+
end
|
8
|
+
|
9
|
+
test "find a job" do
|
10
|
+
fake_connection.stubs(:post).with('/jobs', :jobid => 'job_id').returns(job_response)
|
11
|
+
assert CloudPrint::PrintJob.find('job_id').is_a?(CloudPrint::PrintJob)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Google doesn't list jobid as a possible value in its public docs, but it seems to work just fine
|
15
|
+
test 'find a job performs a remote request' do
|
16
|
+
fake_connection.expects(:post).with('/jobs', :jobid => 'job_id').returns({})
|
17
|
+
|
18
|
+
CloudPrint::PrintJob.find('job_id')
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'find a job gets the job details' do
|
22
|
+
fake_connection.stubs(:post).with('/jobs', :jobid => 'job_id').returns(job_response)
|
23
|
+
job = CloudPrint::PrintJob.find('job_id')
|
24
|
+
|
25
|
+
assert_equal 'job_id', job.id
|
26
|
+
assert_equal 'status', job.status
|
27
|
+
assert_equal 'Error', job.error_code
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'a job is queued' do
|
31
|
+
job = CloudPrint::PrintJob.new(:status => "QUEUED")
|
32
|
+
|
33
|
+
assert !job.done?
|
34
|
+
assert !job.in_progress?
|
35
|
+
assert !job.error?
|
36
|
+
|
37
|
+
assert job.queued?
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'a job is in progress' do
|
41
|
+
job = CloudPrint::PrintJob.new(:status => "IN_PROGRESS")
|
42
|
+
|
43
|
+
assert !job.done?
|
44
|
+
assert !job.queued?
|
45
|
+
assert !job.error?
|
46
|
+
|
47
|
+
assert job.in_progress?
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'a job is done' do
|
51
|
+
job = CloudPrint::PrintJob.new(:status => "DONE")
|
52
|
+
|
53
|
+
assert !job.in_progress?
|
54
|
+
assert !job.queued?
|
55
|
+
assert !job.error?
|
56
|
+
|
57
|
+
assert job.done?
|
58
|
+
end
|
59
|
+
|
60
|
+
test "a job has an error" do
|
61
|
+
job = CloudPrint::PrintJob.new(:status => "ERROR")
|
62
|
+
|
63
|
+
assert !job.done?
|
64
|
+
assert !job.in_progress?
|
65
|
+
assert !job.queued?
|
66
|
+
|
67
|
+
assert job.error?
|
68
|
+
end
|
69
|
+
private
|
70
|
+
|
71
|
+
def job_response
|
72
|
+
{"jobs" => [{"id" => "job_id", "status" => "status", "errorCode" => "Error"}]}
|
73
|
+
end
|
74
|
+
end
|
data/test/printer_test.rb
CHANGED
@@ -15,6 +15,14 @@ class PrinterTest < Test::Unit::TestCase
|
|
15
15
|
assert_equal 'My Printer', printer.name
|
16
16
|
end
|
17
17
|
|
18
|
+
test "a printer has tags" do
|
19
|
+
printer = CloudPrint::Printer.new(:id => 'printer_id', :status => 'online', :name => "My Printer")
|
20
|
+
assert_equal printer.tags, {}
|
21
|
+
|
22
|
+
printer = CloudPrint::Printer.new(:id => 'printer_id', :status => 'online', :name => "My Printer", :tags => {"email" => 'a@b.com'})
|
23
|
+
assert_equal printer.tags, {"email" => "a@b.com"}
|
24
|
+
end
|
25
|
+
|
18
26
|
test "finding a printer by its id should get a connection" do
|
19
27
|
fake_connection.stubs(:get).returns(one_printer_hash)
|
20
28
|
|
@@ -41,6 +49,7 @@ class PrinterTest < Test::Unit::TestCase
|
|
41
49
|
assert_equal 'my_printer', printer.id
|
42
50
|
assert_equal 'online', printer.status
|
43
51
|
assert_equal 'My Printer', printer.name
|
52
|
+
assert_equal printer.tags, {'email' => 'a@b.com' }
|
44
53
|
end
|
45
54
|
|
46
55
|
test "finding all printer should initialize an array of printers" do
|
@@ -56,20 +65,49 @@ class PrinterTest < Test::Unit::TestCase
|
|
56
65
|
end
|
57
66
|
|
58
67
|
test "print stuff" do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
fake_connection.expects(:post).with('/submit', connection_print_params).returns(empty_job)
|
69
|
+
stub_connection
|
70
|
+
|
71
|
+
print_stuff
|
72
|
+
end
|
73
|
+
|
74
|
+
test "print stuff returns a job" do
|
75
|
+
stub_connection
|
76
|
+
fake_connection.stubs(:post).with('/submit', connection_print_params).returns(empty_job)
|
77
|
+
job = print_stuff
|
78
|
+
assert job.is_a?(CloudPrint::PrintJob)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "print job has an id and a status" do
|
64
82
|
stub_connection
|
83
|
+
fake_connection.expects(:post).with('/submit', connection_print_params).returns({"success" => true, "job" => {"id" => "job_id", "status" => 'status'}})
|
84
|
+
job = print_stuff
|
65
85
|
|
66
|
-
|
86
|
+
assert_equal 'job_id', job.id
|
87
|
+
assert_equal 'status', job.status
|
67
88
|
end
|
68
89
|
|
69
90
|
private
|
70
91
|
|
92
|
+
def empty_job
|
93
|
+
{"job" => {}}
|
94
|
+
end
|
95
|
+
|
96
|
+
def print_stuff
|
97
|
+
printer = CloudPrint::Printer.new(:id => 'printer')
|
98
|
+
printer.print(print_params)
|
99
|
+
end
|
100
|
+
|
101
|
+
def print_params
|
102
|
+
{ :title => "Hello World", :content => "<h1>ohai!</h1>", :content_type => "text/html" }
|
103
|
+
end
|
104
|
+
|
105
|
+
def connection_print_params
|
106
|
+
{ :printerid => 'printer', :title => "Hello World", :content => "<h1>ohai!</h1>", :contentType => "text/html" }
|
107
|
+
end
|
108
|
+
|
71
109
|
def one_printer_hash
|
72
|
-
{'printers' =>[{'id' => 'my_printer', 'status' => 'online', 'name' => "My Printer"}]}
|
110
|
+
{'printers' =>[{'id' => 'my_printer', 'status' => 'online', 'name' => "My Printer", 'tags' => { 'email' => 'a@b.com'}}]}
|
73
111
|
end
|
74
112
|
|
75
113
|
def multiple_printer_hash
|
@@ -79,15 +117,5 @@ class PrinterTest < Test::Unit::TestCase
|
|
79
117
|
]}
|
80
118
|
end
|
81
119
|
|
82
|
-
def fake_connection
|
83
|
-
if @connection.nil?
|
84
|
-
@connection = mock('connection')
|
85
|
-
@connection.stub_everything
|
86
|
-
end
|
87
|
-
@connection
|
88
|
-
end
|
89
120
|
|
90
|
-
|
91
|
-
CloudPrint.stubs(:connection).returns(fake_connection)
|
92
|
-
end
|
93
|
-
end
|
121
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eugen Minciu
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-28 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -23,12 +23,14 @@ dependencies:
|
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 11
|
29
29
|
segments:
|
30
30
|
- 0
|
31
|
-
|
31
|
+
- 5
|
32
|
+
- 0
|
33
|
+
version: 0.5.0
|
32
34
|
requirement: *id001
|
33
35
|
prerelease: false
|
34
36
|
name: oauth2
|
@@ -45,24 +47,10 @@ dependencies:
|
|
45
47
|
version: "0"
|
46
48
|
requirement: *id002
|
47
49
|
prerelease: false
|
48
|
-
name: faraday
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
type: :runtime
|
51
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
hash: 3
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
requirement: *id003
|
61
|
-
prerelease: false
|
62
50
|
name: json
|
63
51
|
- !ruby/object:Gem::Dependency
|
64
52
|
type: :development
|
65
|
-
version_requirements: &
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
66
54
|
none: false
|
67
55
|
requirements:
|
68
56
|
- - ~>
|
@@ -73,12 +61,12 @@ dependencies:
|
|
73
61
|
- 0
|
74
62
|
- 0
|
75
63
|
version: 1.0.0
|
76
|
-
requirement: *
|
64
|
+
requirement: *id003
|
77
65
|
prerelease: false
|
78
66
|
name: bundler
|
79
67
|
- !ruby/object:Gem::Dependency
|
80
68
|
type: :development
|
81
|
-
version_requirements: &
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
82
70
|
none: false
|
83
71
|
requirements:
|
84
72
|
- - ~>
|
@@ -89,7 +77,7 @@ dependencies:
|
|
89
77
|
- 6
|
90
78
|
- 4
|
91
79
|
version: 1.6.4
|
92
|
-
requirement: *
|
80
|
+
requirement: *id004
|
93
81
|
prerelease: false
|
94
82
|
name: jeweler
|
95
83
|
description: |-
|
@@ -114,10 +102,12 @@ files:
|
|
114
102
|
- cloudprint.gemspec
|
115
103
|
- lib/cloudprint.rb
|
116
104
|
- lib/cloudprint/connection.rb
|
105
|
+
- lib/cloudprint/print_job.rb
|
117
106
|
- lib/cloudprint/printer.rb
|
118
107
|
- test/cloudprint_test.rb
|
119
108
|
- test/connection_test.rb
|
120
109
|
- test/helper.rb
|
110
|
+
- test/print_job_test.rb
|
121
111
|
- test/printer_test.rb
|
122
112
|
has_rdoc: true
|
123
113
|
homepage: http://github.com/minciue/cloudprint
|