pogoplug 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +48 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +123 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +61 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/pogoplug/api_version.rb +10 -0
- data/lib/pogoplug/authentication_error.rb +4 -0
- data/lib/pogoplug/client.rb +117 -0
- data/lib/pogoplug/device.rb +19 -0
- data/lib/pogoplug/file.rb +37 -0
- data/lib/pogoplug/file_listing.rb +27 -0
- data/lib/pogoplug/hash_initializer.rb +9 -0
- data/lib/pogoplug/service.rb +11 -0
- data/lib/pogoplug/version.rb +3 -0
- data/lib/pogoplug.rb +14 -0
- data/listDevices.json +45 -0
- data/listFiles.json +111 -0
- data/pogoplug.gemspec +99 -0
- data/test/pogoplug/client_test.rb +207 -0
- data/test/pogoplug/device_test.rb +81 -0
- data/test/pogoplug/file_listing_test.rb +143 -0
- data/test/pogoplug/file_test.rb +80 -0
- data/test/pogoplug/helper.rb +22 -0
- data/test/pogoplug/service_test.rb +46 -0
- data/test/test_file.txt +1 -0
- metadata +256 -0
data/listFiles.json
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
{
|
2
|
+
"files": [
|
3
|
+
{
|
4
|
+
"fileid": "AnonCRwPRDGnAnaAnD1aHg",
|
5
|
+
"type": "1",
|
6
|
+
"name": "Folder One",
|
7
|
+
"parentid": "0",
|
8
|
+
"mimetype": "",
|
9
|
+
"size": "0",
|
10
|
+
"ctime": "1376082451582",
|
11
|
+
"mtime": "1376082451582",
|
12
|
+
"origtime": "1376082451582",
|
13
|
+
"xcstamp": "",
|
14
|
+
"tnstamp": "",
|
15
|
+
"mdstamp": "",
|
16
|
+
"streamtype": "full",
|
17
|
+
"thumbnail": "",
|
18
|
+
"preview": "",
|
19
|
+
"stream": "",
|
20
|
+
"livestream": "",
|
21
|
+
"flvstream": "",
|
22
|
+
"properties": {
|
23
|
+
"origin": ""
|
24
|
+
},
|
25
|
+
"metaver": "0",
|
26
|
+
"filename": "Folder One",
|
27
|
+
"mediatype": ""
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"fileid": "WJ0I39hPZfSIgLYSes5u0w",
|
31
|
+
"type": "0",
|
32
|
+
"name": "bar.txt",
|
33
|
+
"parentid": "0",
|
34
|
+
"mimetype": "text/plain",
|
35
|
+
"size": "0",
|
36
|
+
"ctime": "1376082434000",
|
37
|
+
"mtime": "1376082434000",
|
38
|
+
"origtime": "1376082434000",
|
39
|
+
"xcstamp": "",
|
40
|
+
"tnstamp": "",
|
41
|
+
"mdstamp": "",
|
42
|
+
"streamtype": "full",
|
43
|
+
"thumbnail": "",
|
44
|
+
"preview": "",
|
45
|
+
"stream": "",
|
46
|
+
"livestream": "",
|
47
|
+
"flvstream": "",
|
48
|
+
"properties": {
|
49
|
+
"origin": ""
|
50
|
+
},
|
51
|
+
"metaver": "0",
|
52
|
+
"filename": "bar.txt",
|
53
|
+
"mediatype": "text"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"fileid": "fb1Ker1AetW8139ZhbPGDQ",
|
57
|
+
"type": "0",
|
58
|
+
"name": "foo.txt",
|
59
|
+
"parentid": "0",
|
60
|
+
"mimetype": "text/plain",
|
61
|
+
"size": "0",
|
62
|
+
"ctime": "1376082428000",
|
63
|
+
"mtime": "1376082428000",
|
64
|
+
"origtime": "1376082428000",
|
65
|
+
"xcstamp": "",
|
66
|
+
"tnstamp": "",
|
67
|
+
"mdstamp": "",
|
68
|
+
"streamtype": "full",
|
69
|
+
"thumbnail": "",
|
70
|
+
"preview": "",
|
71
|
+
"stream": "",
|
72
|
+
"livestream": "",
|
73
|
+
"flvstream": "",
|
74
|
+
"properties": {
|
75
|
+
"origin": ""
|
76
|
+
},
|
77
|
+
"metaver": "0",
|
78
|
+
"filename": "foo.txt",
|
79
|
+
"mediatype": "text"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"fileid": "nZaBs2cdLUKQOu_vvFxn2w",
|
83
|
+
"type": "1",
|
84
|
+
"name": "Folder Two",
|
85
|
+
"parentid": "0",
|
86
|
+
"mimetype": "",
|
87
|
+
"size": "0",
|
88
|
+
"ctime": "1376082458122",
|
89
|
+
"mtime": "1376082458122",
|
90
|
+
"origtime": "1376082458122",
|
91
|
+
"xcstamp": "",
|
92
|
+
"tnstamp": "",
|
93
|
+
"mdstamp": "",
|
94
|
+
"streamtype": "full",
|
95
|
+
"thumbnail": "",
|
96
|
+
"preview": "",
|
97
|
+
"stream": "",
|
98
|
+
"livestream": "",
|
99
|
+
"flvstream": "",
|
100
|
+
"properties": {
|
101
|
+
"origin": ""
|
102
|
+
},
|
103
|
+
"metaver": "0",
|
104
|
+
"filename": "Folder Two",
|
105
|
+
"mediatype": ""
|
106
|
+
}
|
107
|
+
],
|
108
|
+
"pageoffset": "0",
|
109
|
+
"count": "4",
|
110
|
+
"totalcount": "4"
|
111
|
+
}
|
data/pogoplug.gemspec
ADDED
@@ -0,0 +1,99 @@
|
|
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 = "pogoplug"
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Travis Truman"]
|
12
|
+
s.date = "2013-08-19"
|
13
|
+
s.description = ""
|
14
|
+
s.email = "trumant@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
".travis.yml",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"Guardfile",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/pogoplug.rb",
|
31
|
+
"lib/pogoplug/api_version.rb",
|
32
|
+
"lib/pogoplug/authentication_error.rb",
|
33
|
+
"lib/pogoplug/client.rb",
|
34
|
+
"lib/pogoplug/device.rb",
|
35
|
+
"lib/pogoplug/file.rb",
|
36
|
+
"lib/pogoplug/file_listing.rb",
|
37
|
+
"lib/pogoplug/hash_initializer.rb",
|
38
|
+
"lib/pogoplug/service.rb",
|
39
|
+
"lib/pogoplug/version.rb",
|
40
|
+
"listDevices.json",
|
41
|
+
"listFiles.json",
|
42
|
+
"pogoplug.gemspec",
|
43
|
+
"test/pogoplug/client_test.rb",
|
44
|
+
"test/pogoplug/device_test.rb",
|
45
|
+
"test/pogoplug/file_listing_test.rb",
|
46
|
+
"test/pogoplug/file_test.rb",
|
47
|
+
"test/pogoplug/helper.rb",
|
48
|
+
"test/pogoplug/service_test.rb",
|
49
|
+
"test/test_file.txt"
|
50
|
+
]
|
51
|
+
s.homepage = "http://github.com/trumant/pogoplug"
|
52
|
+
s.licenses = ["MIT"]
|
53
|
+
s.require_paths = ["lib"]
|
54
|
+
s.rubygems_version = "1.8.23"
|
55
|
+
s.summary = "A Ruby wrapper around the PogoPlug API"
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
s.specification_version = 3
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
+
s.add_runtime_dependency(%q<pogoplug>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.3"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<guard>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<guard-bundler>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<guard-test>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<ruby_gntp>, [">= 0"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<pogoplug>, [">= 0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.3"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
76
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
79
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
80
|
+
s.add_dependency(%q<guard>, [">= 0"])
|
81
|
+
s.add_dependency(%q<guard-bundler>, [">= 0"])
|
82
|
+
s.add_dependency(%q<guard-test>, [">= 0"])
|
83
|
+
s.add_dependency(%q<ruby_gntp>, [">= 0"])
|
84
|
+
end
|
85
|
+
else
|
86
|
+
s.add_dependency(%q<pogoplug>, [">= 0"])
|
87
|
+
s.add_dependency(%q<bundler>, ["~> 1.3"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
89
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
90
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
91
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
92
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
93
|
+
s.add_dependency(%q<guard>, [">= 0"])
|
94
|
+
s.add_dependency(%q<guard-bundler>, [">= 0"])
|
95
|
+
s.add_dependency(%q<guard-test>, [">= 0"])
|
96
|
+
s.add_dependency(%q<ruby_gntp>, [">= 0"])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
module PogoPlug
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
context "Client" do
|
5
|
+
setup do
|
6
|
+
@client = PogoPlug::Client.new
|
7
|
+
@username = "gem_test_user@mailinator.com"
|
8
|
+
@password = "p@ssw0rd"
|
9
|
+
end
|
10
|
+
|
11
|
+
context "#version" do
|
12
|
+
should "provide version info" do
|
13
|
+
version = @client.version
|
14
|
+
assert_not_nil version
|
15
|
+
assert(version.version.is_a?(String) && !version.version.empty?, "Version number is missing.")
|
16
|
+
assert(version.build_date.is_a?(String) && !version.build_date.empty?, "Build date is missing")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#login" do
|
21
|
+
should "provide a client instance with a token" do
|
22
|
+
logged_in_client = @client.login(@username, @password)
|
23
|
+
assert(logged_in_client.token.is_a?(String) && !logged_in_client.token.empty?, "Auth token is missing")
|
24
|
+
end
|
25
|
+
|
26
|
+
should "raise an AuthenticationError when invalid credentials are provided" do
|
27
|
+
assert_raise(PogoPlug::AuthenticationError, "AuthenticationError should have been raised") do
|
28
|
+
@client.login("bad_email_address@mailinator.com", "bad_password")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#devices" do
|
34
|
+
setup do
|
35
|
+
@client.login(@username, @password)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "provide a list of PogoPlug devices belonging to the user" do
|
39
|
+
devices = @client.devices
|
40
|
+
assert_not_nil(devices, "Devices are missing")
|
41
|
+
first_device = devices.first
|
42
|
+
assert_kind_of(PogoPlug::Device, first_device, "Device model instances should be returned")
|
43
|
+
assert_false(first_device.services.empty?, "Device services should not be empty")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#services" do
|
48
|
+
setup do
|
49
|
+
@client.login(@username, @password)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "provide a list of PogoPlug services available to the user" do
|
53
|
+
services = @client.services
|
54
|
+
assert_not_nil(services, "Services are missing")
|
55
|
+
assert_kind_of(Enumerable, services)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "#files" do
|
60
|
+
setup do
|
61
|
+
@client.login(@username, @password)
|
62
|
+
@device = @client.devices.first
|
63
|
+
end
|
64
|
+
|
65
|
+
should "provide a list of files for a device and service" do
|
66
|
+
files = @client.files(@device.id, @device.services.first.id)
|
67
|
+
assert_not_nil(files, "Files are missing")
|
68
|
+
assert_kind_of(PogoPlug::FileListing, files)
|
69
|
+
assert_false(files.empty?, "Files are not expected to be empty")
|
70
|
+
end
|
71
|
+
|
72
|
+
should "provide a means of paging through the files in the listing" do
|
73
|
+
file_listing = @client.files(@device.id, @device.services.first.id)
|
74
|
+
# dependent on previous test runs for us to have more than one page of files in the listing
|
75
|
+
if file_listing.total_count > file_listing.size
|
76
|
+
second_page = @client.files(@device.id, @device.services.first.id, file_listing.offset + 1)
|
77
|
+
assert_equal(file_listing.offset + 1, second_page.offset, "Expecting the second page listing to have the correct offset")
|
78
|
+
assert_false(second_page.empty?, "Expecting the second page of files to have some files")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "#create_directory" do
|
84
|
+
setup do
|
85
|
+
@client.login(@username, @password)
|
86
|
+
@device = @client.devices.first
|
87
|
+
@directory_name = "My Test Directory #{rand(1000).to_i}"
|
88
|
+
@child_directory_name = "My Test Child Directory #{rand(1000).to_i}"
|
89
|
+
end
|
90
|
+
|
91
|
+
should "create a directory under the root" do
|
92
|
+
directory = @client.create_directory(@device.id, @device.services.first, @directory_name)
|
93
|
+
assert_not_nil(directory, "Directory should have been created")
|
94
|
+
assert_equal(directory.name, @directory_name, "Directory should have the correct name")
|
95
|
+
assert_equal(directory.parent_id, "0", "Directory should be at the root")
|
96
|
+
assert_true(directory.directory?, "Directory should be a directory")
|
97
|
+
end
|
98
|
+
|
99
|
+
should "create a directory under the specified parent" do
|
100
|
+
parent_directory = @client.files(@device.id, @device.services.first.id).files.select { |file| file.directory? }.first
|
101
|
+
directory = @client.create_directory(@device.id, @device.services.first, @child_directory_name, parent_directory.id)
|
102
|
+
assert_not_nil(directory, "Directory should have been created")
|
103
|
+
assert_equal(directory.name, @child_directory_name, "Directory should have the correct name")
|
104
|
+
assert_equal(directory.parent_id, parent_directory.id, "Directory should be under the correct parent")
|
105
|
+
assert_true(directory.directory?, "Directory should be a directory")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "#create_file" do
|
110
|
+
setup do
|
111
|
+
@client.login(@username, @password)
|
112
|
+
@device = @client.devices.first
|
113
|
+
@file_name = "My test file #{rand(1000).to_i}"
|
114
|
+
@parent_directory = @client.files(@device.id, @device.services.first.id).files.select { |file| file.directory? }.first
|
115
|
+
@file_to_create = File.new(name: @file_name, type: File::Type::FILE, parent_id: @parent_directory.id)
|
116
|
+
end
|
117
|
+
|
118
|
+
should "create a file handle" do
|
119
|
+
created_file = @client.create_file(@device.id, @device.services.first, @file_to_create)
|
120
|
+
assert_not_nil(created_file, "File should have been created")
|
121
|
+
assert_equal(@file_name, created_file.name)
|
122
|
+
assert_equal(@file_to_create.type, created_file.type)
|
123
|
+
assert_equal(@file_to_create.parent_id, created_file.parent_id)
|
124
|
+
assert_not_nil(created_file.id)
|
125
|
+
end
|
126
|
+
|
127
|
+
should "create a file handle and attach the bits" do
|
128
|
+
test_file = ::File.new(::File.expand_path('../../test_file.txt', __FILE__), 'rb')
|
129
|
+
@file_to_create.name = ::File.basename(test_file.path)
|
130
|
+
created_file = @client.create_file(@device.id, @device.services.first, @file_to_create, test_file)
|
131
|
+
assert_not_nil(created_file)
|
132
|
+
assert_equal(test_file.size, created_file.size)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "#delete" do
|
137
|
+
setup do
|
138
|
+
@client.login(@username, @password)
|
139
|
+
@device = @client.devices.first
|
140
|
+
end
|
141
|
+
|
142
|
+
should "delete an empty directory" do
|
143
|
+
directory_name = "My test directory #{rand(1000).to_i}"
|
144
|
+
directory = @client.create_file(@device.id, @device.services.first, File.new(name: directory_name, type: File::Type::DIRECTORY))
|
145
|
+
created_directory = @client.files(@device.id, @device.services.first.id).files.select { |file| file.directory? && file.name == directory_name }.first
|
146
|
+
|
147
|
+
assert_not_nil(created_directory, "Test directory was not created")
|
148
|
+
assert_true(@client.delete(@device.id, @device.services.first.id, directory), "Test directory was not deleted")
|
149
|
+
|
150
|
+
deleted_directory = @client.files(@device.id, @device.services.first.id).files.select { |file| file.directory? && file.name == directory_name }.first
|
151
|
+
assert_nil(deleted_directory, "Test directory that was supposed to have been deleted is still returned")
|
152
|
+
end
|
153
|
+
|
154
|
+
should "delete a directory and its children" do
|
155
|
+
parent_directory_name = "My test directory #{rand(1000).to_i}"
|
156
|
+
parent_directory = @client.create_file(@device.id, @device.services.first, File.new(name: parent_directory_name, type: File::Type::DIRECTORY))
|
157
|
+
|
158
|
+
child_directory_name = "My test child directory"
|
159
|
+
child_directory = @client.create_file(@device.id, @device.services.first, File.new(name: child_directory_name, type: File::Type::DIRECTORY, parent_id: parent_directory.id))
|
160
|
+
|
161
|
+
assert_true(@client.delete(@device.id, @device.services.first.id, parent_directory), "Test directory was not deleted")
|
162
|
+
|
163
|
+
deleted_directory = @client.files(@device.id, @device.services.first.id).files.select { |file| file.directory? && file.name == parent_directory_name }.first
|
164
|
+
assert_nil(deleted_directory, "Test directory that was supposed to have been deleted is still returned")
|
165
|
+
end
|
166
|
+
|
167
|
+
should "delete a file" do
|
168
|
+
file_name = "My test file #{rand(1000).to_i}"
|
169
|
+
file_to_create = File.new(name: file_name, type: File::Type::FILE)
|
170
|
+
|
171
|
+
created_file = @client.create_file(@device.id, @device.services.first, file_to_create)
|
172
|
+
assert_true(@client.delete(@device.id, @device.services.first.id, created_file), "File was not deleted")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "#copy" do
|
177
|
+
end
|
178
|
+
|
179
|
+
context "#download" do
|
180
|
+
setup do
|
181
|
+
@client.login(@username, @password)
|
182
|
+
@device = @client.devices.first
|
183
|
+
@service = @device.services.first
|
184
|
+
@fileListing = @client.files(@device.id, @service.id)
|
185
|
+
end
|
186
|
+
|
187
|
+
should "fetch the file specified" do
|
188
|
+
file_to_download = @fileListing.files.select { |f| f.file? }.first
|
189
|
+
if file_to_download
|
190
|
+
io = @client.download(@device.id, @service, file_to_download)
|
191
|
+
file = ::File.write(file_to_download.name, io, nil, mode: 'wb')
|
192
|
+
assert_equal(file_to_download.size, io.size, "File should be the same size as the descriptor said it would be")
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
should "refuse to download a directory" do
|
197
|
+
file_to_download = @fileListing.files.select { |f| f.directory? }.first
|
198
|
+
if file_to_download
|
199
|
+
assert_raise(RuntimeError, "Directories cannot be downloaded") do
|
200
|
+
@client.download(@device.id, @service, file_to_download)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module PogoPlug
|
4
|
+
class DeviceTest < Test::Unit::TestCase
|
5
|
+
context "Device" do
|
6
|
+
setup do
|
7
|
+
@name = "Pogoplug Cloud"
|
8
|
+
@id = "XCLDGAAAHE5B5NKDKMUXJ52F9J"
|
9
|
+
@device = Device.new(name: @name, id: @id)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "provide a name" do
|
13
|
+
assert_equal(@name, @device.name)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "provide an ID" do
|
17
|
+
assert_equal(@id, @device.id)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "allow services to be added" do
|
21
|
+
service = Service.new(name: "some name", id: "some id")
|
22
|
+
@device.services << service
|
23
|
+
assert_equal(service, @device.services.first)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "provide a collection of services" do
|
27
|
+
assert_kind_of(Enumerable, @device.services)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be able to build instances from JSON" do
|
31
|
+
json = %q{
|
32
|
+
{
|
33
|
+
"deviceid": "XCLDGAAAHE5B5NKDKMUXJ52F9J",
|
34
|
+
"type": "xce:cloud",
|
35
|
+
"name": "Pogoplug Cloud",
|
36
|
+
"version": "LINUX GENERIC - 4.6.0.12",
|
37
|
+
"flags": "0",
|
38
|
+
"ownerid": "1a3edf8b7a987226ec0840f37bf35cc5",
|
39
|
+
"sku": {
|
40
|
+
"id": "36",
|
41
|
+
"oem": "Cloud Engines",
|
42
|
+
"name": "POGOCLOUD-MCLOUDFREE",
|
43
|
+
"username": "Pogoplug Cloud",
|
44
|
+
"terms": "0"
|
45
|
+
},
|
46
|
+
"provisionflags": "0",
|
47
|
+
"authorized": "1",
|
48
|
+
"plan": {
|
49
|
+
"duration": "-1",
|
50
|
+
"limit": "0",
|
51
|
+
"name": "POGOCLOUD-MCLOUDFREE",
|
52
|
+
"startdate": "1376079072110",
|
53
|
+
"type": "POGOCLOUD"
|
54
|
+
},
|
55
|
+
"services": [
|
56
|
+
{
|
57
|
+
"deviceid": "XCLDGAAAHE5B5NKDKMUXJ52F9J",
|
58
|
+
"serviceid": "XCLDGAAAHE5B5NKDKMUXJ52F9J",
|
59
|
+
"sclass": "1",
|
60
|
+
"type": "xce:plugfs:cloud",
|
61
|
+
"name": "Pogoplug Cloud",
|
62
|
+
"version": "4.6.0.12",
|
63
|
+
"online": "1",
|
64
|
+
"msgpending": "0",
|
65
|
+
"apiurl": "https://cl0c0.pogoplug.com/svc/api/",
|
66
|
+
"space": "5000000000/5000000000",
|
67
|
+
"flags": "0",
|
68
|
+
"onlan": "0",
|
69
|
+
"metaver": "0"
|
70
|
+
}
|
71
|
+
]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
device = Device.from_json(JSON.parse(json))
|
75
|
+
assert_equal("Pogoplug Cloud", device.name)
|
76
|
+
assert_equal("XCLDGAAAHE5B5NKDKMUXJ52F9J", device.id)
|
77
|
+
assert_equal(1, device.services.size, "Expected 1 service")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module PogoPlug
|
4
|
+
class FileListingTest < Test::Unit::TestCase
|
5
|
+
context "FileListing" do
|
6
|
+
setup do
|
7
|
+
@size = 2
|
8
|
+
@offset = 0
|
9
|
+
@file_listing = FileListing.new(size: @size, offset: @offset, total_count: @size)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "provide the number of files in the listing" do
|
13
|
+
assert_equal(@size, @file_listing.size)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "from_json" do
|
17
|
+
should "produce a FileListing instance when given JSON" do
|
18
|
+
json = %q{
|
19
|
+
{
|
20
|
+
"files": [
|
21
|
+
{
|
22
|
+
"fileid": "AnonCRwPRDGnAnaAnD1aHg",
|
23
|
+
"type": "1",
|
24
|
+
"name": "Folder One",
|
25
|
+
"parentid": "0",
|
26
|
+
"mimetype": "",
|
27
|
+
"size": "0",
|
28
|
+
"ctime": "1376082451582",
|
29
|
+
"mtime": "1376082451582",
|
30
|
+
"origtime": "1376082451582",
|
31
|
+
"xcstamp": "",
|
32
|
+
"tnstamp": "",
|
33
|
+
"mdstamp": "",
|
34
|
+
"streamtype": "full",
|
35
|
+
"thumbnail": "",
|
36
|
+
"preview": "",
|
37
|
+
"stream": "",
|
38
|
+
"livestream": "",
|
39
|
+
"flvstream": "",
|
40
|
+
"properties": {
|
41
|
+
"origin": ""
|
42
|
+
},
|
43
|
+
"metaver": "0",
|
44
|
+
"filename": "Folder One",
|
45
|
+
"mediatype": ""
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"fileid": "WJ0I39hPZfSIgLYSes5u0w",
|
49
|
+
"type": "0",
|
50
|
+
"name": "bar.txt",
|
51
|
+
"parentid": "0",
|
52
|
+
"mimetype": "text/plain",
|
53
|
+
"size": "0",
|
54
|
+
"ctime": "1376082434000",
|
55
|
+
"mtime": "1376082434000",
|
56
|
+
"origtime": "1376082434000",
|
57
|
+
"xcstamp": "",
|
58
|
+
"tnstamp": "",
|
59
|
+
"mdstamp": "",
|
60
|
+
"streamtype": "full",
|
61
|
+
"thumbnail": "",
|
62
|
+
"preview": "",
|
63
|
+
"stream": "",
|
64
|
+
"livestream": "",
|
65
|
+
"flvstream": "",
|
66
|
+
"properties": {
|
67
|
+
"origin": ""
|
68
|
+
},
|
69
|
+
"metaver": "0",
|
70
|
+
"filename": "bar.txt",
|
71
|
+
"mediatype": "text"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"fileid": "fb1Ker1AetW8139ZhbPGDQ",
|
75
|
+
"type": "0",
|
76
|
+
"name": "foo.txt",
|
77
|
+
"parentid": "0",
|
78
|
+
"mimetype": "text/plain",
|
79
|
+
"size": "0",
|
80
|
+
"ctime": "1376082428000",
|
81
|
+
"mtime": "1376082428000",
|
82
|
+
"origtime": "1376082428000",
|
83
|
+
"xcstamp": "",
|
84
|
+
"tnstamp": "",
|
85
|
+
"mdstamp": "",
|
86
|
+
"streamtype": "full",
|
87
|
+
"thumbnail": "",
|
88
|
+
"preview": "",
|
89
|
+
"stream": "",
|
90
|
+
"livestream": "",
|
91
|
+
"flvstream": "",
|
92
|
+
"properties": {
|
93
|
+
"origin": ""
|
94
|
+
},
|
95
|
+
"metaver": "0",
|
96
|
+
"filename": "foo.txt",
|
97
|
+
"mediatype": "text"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"fileid": "nZaBs2cdLUKQOu_vvFxn2w",
|
101
|
+
"type": "1",
|
102
|
+
"name": "Folder Two",
|
103
|
+
"parentid": "0",
|
104
|
+
"mimetype": "",
|
105
|
+
"size": "0",
|
106
|
+
"ctime": "1376082458122",
|
107
|
+
"mtime": "1376082458122",
|
108
|
+
"origtime": "1376082458122",
|
109
|
+
"xcstamp": "",
|
110
|
+
"tnstamp": "",
|
111
|
+
"mdstamp": "",
|
112
|
+
"streamtype": "full",
|
113
|
+
"thumbnail": "",
|
114
|
+
"preview": "",
|
115
|
+
"stream": "",
|
116
|
+
"livestream": "",
|
117
|
+
"flvstream": "",
|
118
|
+
"properties": {
|
119
|
+
"origin": ""
|
120
|
+
},
|
121
|
+
"metaver": "0",
|
122
|
+
"filename": "Folder Two",
|
123
|
+
"mediatype": ""
|
124
|
+
}
|
125
|
+
],
|
126
|
+
"pageoffset": "0",
|
127
|
+
"count": "4",
|
128
|
+
"totalcount": "4"
|
129
|
+
}
|
130
|
+
}
|
131
|
+
listing = FileListing.from_json(JSON::parse(json))
|
132
|
+
assert_equal(4, listing.size, "Size does not match")
|
133
|
+
assert_equal(0, listing.offset, "Offset does not match")
|
134
|
+
assert_equal(4, listing.total_count, "Total count does not match")
|
135
|
+
assert_not_nil(listing.files, "Files are missing")
|
136
|
+
assert_kind_of(Enumerable, listing.files)
|
137
|
+
assert_equal(4, listing.files.size, "Expected 4 files")
|
138
|
+
assert_false(listing.empty?)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|