mite-backup 0.0.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e2a1de229359b4ec2c13e670f632669885c1fab3b3de816eae6890f924e3e4a
4
+ data.tar.gz: 4284bc243e1f88e5b3a71647a68cf08eb14907fad396796ca3fb69090c253bfa
5
+ SHA512:
6
+ metadata.gz: 6e2b252caf37075b1752da4f51b6f83a0be45be881916120b8af1386454e7702b3f5965b718f3ad114fa6cb313fb6e718aa6d7ff3a7153a349cf548874608632
7
+ data.tar.gz: 91615a738bfc2b0fd7ff2b18e88c30358dca80a07904e5f802bded1b5b3343664544356bf5caf673de3ce9994a52a11cba254884bc9b384dd648b4d8c146a0d7
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .ruby-version
6
+ .rbenv-*
data/README.md CHANGED
@@ -5,22 +5,21 @@ Simple command-line tool for downloading a backup in XML of your [mite](http://m
5
5
  ## Installation
6
6
 
7
7
  gem install mite-backup
8
-
8
+
9
9
  ## Usage
10
10
 
11
- mite-backup -a [ACCOUNT] -e [EMAIL] -p [PASSWORD]
12
-
11
+ mite-backup -a [ACCOUNT-SUBDOMAIN] -e [EMAIL] -p [PASSWORD]
12
+
13
13
  This will output the backup file in XML to the prompt. You propably want to pipe it into an file:
14
14
 
15
- mite-backup -a [ACCOUNT] -e [EMAIL] -p [PASSWORD] > my_backup_file.xml
15
+ mite-backup -a [ACCOUNT-SUBDOMAIN] -e [EMAIL] -p [PASSWORD] > my_backup_file.xml
16
16
 
17
17
  For further instructions run
18
18
 
19
19
  mite-backup -h
20
-
21
20
 
22
21
  ## BlaBla
23
22
 
24
- Copyright (c) 2011 [Yolk](http://yo.lk/) Sebastian Munz & Julia Soergel GbR
23
+ Copyright (c) 2011-2012 [Yolk](http://yo.lk/) Sebastian Munz & Julia Soergel GbR
25
24
 
26
25
  Beyond that, the implementation is licensed under the MIT License.
@@ -13,7 +13,7 @@ parser = OptionParser.new do |opts|
13
13
  opts.separator ""
14
14
  opts.separator "Options:"
15
15
 
16
- opts.on("-a", "--account [ACCOUNT]", "your mite account-name (subdomain without .mite.yo.lk)") do |account|
16
+ opts.on("-a", "--account [ACCOUNT-SUBDOMAIN]", "your mite account subdomain (without .mite.yo.lk)") do |account|
17
17
  @options["account"] = account
18
18
  end
19
19
 
@@ -1,20 +1,20 @@
1
1
  require "mite-backup/version"
2
2
  require "multi_json"
3
- require "net/http"
3
+ require "net/https"
4
4
  require "uri"
5
5
  require 'zlib'
6
6
  require 'yaml'
7
7
 
8
8
  class MiteBackup
9
- MAX_CHECKS = 30
10
- SLEEP_BEFORE_EACH_CHECK = 2 # seconds
9
+ MAX_CHECKS = 48
10
+ SLEEP_BEFORE_EACH_CHECK = 5 # seconds
11
11
  CONFIG_FILE = File.expand_path('~/.mite-backup.yml')
12
12
  USER_AGENT = "mite-backup/#{MiteBackup::VERSION}"
13
13
 
14
14
  def initialize(options={})
15
15
  @options = options
16
16
  self.class.clear_config if options["clear_config"]
17
- @account = options["account"] || config["account"]
17
+ @account = correct_account(options["account"] || config["account"])
18
18
  @email = options["email"] || config["email"]
19
19
  @password = options["password"] || config["password"]
20
20
  end
@@ -30,7 +30,7 @@ class MiteBackup
30
30
  (config["account"] = @account) || config.delete("account")
31
31
  (config["email"] = @email) || config.delete("email")
32
32
  (config["password"] = @password) || config.delete("password")
33
-
33
+
34
34
  if config.size == 0
35
35
  self.class.clear_config
36
36
  else
@@ -47,13 +47,15 @@ class MiteBackup
47
47
  private
48
48
 
49
49
  def runnable?
50
- failed "Please provide your account name with --account [ACCOUNT]." unless @account
50
+ failed "Please provide your account subdomain with --account [ACCOUNT-SUBDOMAIN]." unless @account
51
51
  failed "Please provide your mite.users email with --email [EMAIL]." unless @email
52
52
  failed "Please provide your mite.users password with --password [PASSWORD]." unless @password
53
53
  end
54
54
 
55
55
  def create
56
- @id = parse_json(perform_request(Net::HTTP::Post.new("/account/backup.json")))["id"]
56
+ @id = parse_json(perform_request(Net::HTTP::Post.new("/account/backup.json")){ |code|
57
+ "Could not find any account located at #{domain}" if code == "404"
58
+ })["id"]
57
59
  end
58
60
 
59
61
  def check
@@ -67,7 +69,12 @@ class MiteBackup
67
69
  def download
68
70
  if @ready
69
71
  content = perform_request(Net::HTTP::Get.new("/account/backup/#{@id}/download.json"))
70
- gz = Zlib::GzipReader.new(StringIO.new(content), :external_encoding => content.encoding)
72
+ content_str = StringIO.new(content)
73
+ gz = if RUBY_VERSION =~ /\A1\.8\./
74
+ Zlib::GzipReader.new(content_str)
75
+ else
76
+ Zlib::GzipReader.new(content_str, :external_encoding => content.encoding)
77
+ end
71
78
  puts gz.read
72
79
  else
73
80
  failed "Backup was not ready for download after #{MAX_CHECKS*SLEEP_BEFORE_EACH_CHECK} seconds. Contact the mite support."
@@ -81,7 +88,8 @@ class MiteBackup
81
88
  if response.code == "401"
82
89
  failed "Could not authenticate with email #{@email.inspect} and provided password. The user needs to be an admin or the owner of the mite.account!"
83
90
  elsif !["200", "201"].include?(response.code)
84
- failed "mite responded with irregular code #{response.code}"
91
+ message = block_given? && yield(response.code)
92
+ failed(message || "mite responded with irregular code #{response.code}")
85
93
  end
86
94
  response.body
87
95
  end
@@ -91,15 +99,27 @@ class MiteBackup
91
99
  end
92
100
 
93
101
  def mite
94
- @mite ||= Net::HTTP.new(URI.parse("http://#{@account}.mite.yo.lk/").host)
102
+ @mite ||= begin
103
+ mite = Net::HTTP.new(URI.parse(domain).host, 443)
104
+ mite.use_ssl = true
105
+ mite
106
+ end
107
+ end
108
+
109
+ def domain
110
+ "https://#{@account}.mite.yo.lk/"
95
111
  end
96
112
 
97
113
  def failed(reason)
98
114
  $stderr.puts "Failed: #{reason}"
99
115
  exit(1)
100
116
  end
101
-
117
+
102
118
  def config
103
119
  @config ||= File.exist?(CONFIG_FILE) && YAML::load( File.open( CONFIG_FILE ) ) || {}
104
120
  end
121
+
122
+ def correct_account(account)
123
+ account.split(/\/\//, 2)[-1].split(/\./, 2)[0] if account
124
+ end
105
125
  end
@@ -1,3 +1,3 @@
1
1
  class MiteBackup
2
- VERSION = "0.0.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,5 +19,4 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency "multi_json"
22
- s.add_development_dependency "rake"
23
22
  end
metadata CHANGED
@@ -1,38 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mite-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sebastian
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-11-18 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
- requirement: &2167794720 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2167794720
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &2167794300 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
26
  version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *2167794300
36
27
  description: Download a backup of your mite.account from the command-line.
37
28
  email:
38
29
  - sebastian@yo.lk
@@ -41,8 +32,7 @@ executables:
41
32
  extensions: []
42
33
  extra_rdoc_files: []
43
34
  files:
44
- - .gitignore
45
- - .rvmrc
35
+ - ".gitignore"
46
36
  - Gemfile
47
37
  - MIT-LICENSE
48
38
  - README.md
@@ -53,32 +43,24 @@ files:
53
43
  - mite-backup.gemspec
54
44
  homepage: http://mite.yo.lk/en
55
45
  licenses: []
56
- post_install_message:
46
+ metadata: {}
47
+ post_install_message:
57
48
  rdoc_options: []
58
49
  require_paths:
59
50
  - lib
60
51
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
52
  requirements:
63
- - - ! '>='
53
+ - - ">="
64
54
  - !ruby/object:Gem::Version
65
55
  version: '0'
66
- segments:
67
- - 0
68
- hash: -1264802230694611080
69
56
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
57
  requirements:
72
- - - ! '>='
58
+ - - ">="
73
59
  - !ruby/object:Gem::Version
74
60
  version: '0'
75
- segments:
76
- - 0
77
- hash: -1264802230694611080
78
61
  requirements: []
79
- rubyforge_project: mite-backup
80
- rubygems_version: 1.8.10
81
- signing_key:
82
- specification_version: 3
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
+ specification_version: 4
83
65
  summary: Download a backup of your mite.account from the command-line.
84
66
  test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3@mite-backup --create