mozier 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/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ == Mozier
2
+
3
+ Small library to access backup info from mozy.com
4
+
5
+ === Usage
6
+
7
+ Instantiate a new Mozier object, and ask it for info.
8
+
9
+ require 'mozier'
10
+ moz = Mozier.new("your@user.com","andpassword")
11
+ moz.info
12
+ [
13
+ {:last_backup=>Sun Jun 13 13:35:27 +0200 2010, :size=>29184, :name=>"AMICHI"},
14
+ {:last_backup=>nil, :size=>0, :name=>"Erasmo"}
15
+ ]
@@ -0,0 +1,25 @@
1
+ require 'chronic'
2
+
3
+ class String
4
+ def to_time
5
+ Chronic.parse(self)
6
+ end
7
+
8
+ def to_size
9
+ amount,unit = self.split(" ")
10
+ if amount and unit
11
+ case unit.downcase
12
+ when "bytes","b","by"
13
+ amount.to_i
14
+ when "mb","megabytes","mbs","m","mi","mo"
15
+ (amount.to_f * 1024).to_i
16
+ when "gb","gigabytes","gbs","g","gi"
17
+ (amount.to_f * 1024 * 1024).to_i
18
+ else
19
+ nil
20
+ end
21
+ else
22
+ nil
23
+ end
24
+ end
25
+ end
data/lib/mozier.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'mechanize'
2
+
3
+ class Mozier
4
+
5
+ attr_accessor :username
6
+ attr_accessor :password
7
+ attr_accessor :agent
8
+ attr_accessor :logged_in_page
9
+ attr_accessor :info
10
+
11
+ URLS = {:login => "https://mozy.com/login"}
12
+
13
+ def initialize(username,password)
14
+ @username = username
15
+ @password = password
16
+ @agent = Mechanize.new
17
+ end
18
+
19
+ def logged_in_page
20
+ return @logged_in_page unless @logged_in_page.nil?
21
+ page = @agent.get(URLS[:login])
22
+ form = page.forms.last
23
+ form.username = @username
24
+ form.password = @password
25
+ @logged_in_page = @agent.submit(form, form.buttons.first)
26
+ end
27
+
28
+ def info
29
+ return @info unless @info.nil?
30
+ @info = []
31
+ logged_in_page.search("table#machines_box tr").each_with_index do |row,idx|
32
+ if tds = row.css("td") and tds.size > 3
33
+ @info[idx] ||= {}
34
+ @info[idx] = { :name => tds[0].text.strip,
35
+ :size => tds[1].text.strip.to_size,
36
+ :last_backup => tds[2].text.strip.to_time }
37
+ end
38
+ end
39
+ @info.compact!
40
+ end
41
+
42
+ def reload_info
43
+ @info = nil
44
+ @logged_in_page = nil
45
+ info
46
+ end
47
+
48
+ end
data/mozier.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'mozier'
3
+ gem.version = '0.0.2'
4
+ gem.date = Date.today.to_s
5
+
6
+ gem.summary = "Small library to access backup info from mozy.com"
7
+
8
+ gem.authors = ['Albert Llop']
9
+ gem.email = 'mrsimo@gmail.com'
10
+ gem.homepage = 'http://github.com/albertllop/mozier'
11
+
12
+ # README.rdoc
13
+ # core_ext/string.rb
14
+ # lib/mozier.rb
15
+ # mozier.gemspec
16
+ # mozier.rb
17
+ # test/string_test.rb
18
+
19
+ gem.files = ["README.rdoc","core_ext/string.rb", "lib/mozier.rb", "mozier.rb","mozier.gemspec","test/string_test.rb"]
20
+ end
data/mozier.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'core_ext/string'
2
+ require 'lib/mozier'
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mozier'
4
+
5
+ class StringTest < Test::Unit::TestCase
6
+ def test_size_success
7
+ assert_equal(28, "28 bytes".to_size)
8
+ assert_equal(29184, "28.5 MB".to_size)
9
+ assert_equal(10485760, "10 GB".to_size)
10
+ end
11
+
12
+ def test_size_failure
13
+ assert_equal(nil, "foo".to_size)
14
+ assert_equal(nil, "28 cents".to_size)
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mozier
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Albert Llop
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-13 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: mrsimo@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.rdoc
32
+ - core_ext/string.rb
33
+ - lib/mozier.rb
34
+ - mozier.rb
35
+ - mozier.gemspec
36
+ - test/string_test.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/albertllop/mozier
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !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
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Small library to access backup info from mozy.com
71
+ test_files: []
72
+