exchange-offline-address-book 0.0.15 → 0.0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e75fd2c8c924ed74a3402e343ad13cbbd5ac50a
4
- data.tar.gz: e58fd3f5ae214dff0b166b92f932cdce8d62e41d
3
+ metadata.gz: 01f25de3bcac4f14eb4d86e16ccdbb374f22b278
4
+ data.tar.gz: f27e58b29d365d8eb2ec5646a6cccf1fdb1a19e2
5
5
  SHA512:
6
- metadata.gz: aa2eb09bf305753d02a37b60e8cd200627672d68a552cc6a320ff1c08b4c9f6600738cd04ed836c993cddd361271d1402ae403acc892f9c5f3946fad5a77fe46
7
- data.tar.gz: a42cac43468946d1d91a6fcf993c1034683af628b2fe29250f111de3621afc1ba8326a4343f52c5d4a57a95d298e8f7dc124dad99ee354751f2369b55ea81ce3
6
+ metadata.gz: caf89146265979fededa91f135c99684b4470efb643ac900d3e02255573243bf60016a29b51d21d5ba26f0b2976b6789fb835829c0ea3be37b8ea811c66fdac8
7
+ data.tar.gz: d83224e032ceffcce72962e50060c5187c74109da26861754716c756d5cee108e009d408cd08f51cd264d4112bce16fecf1755a2fa11e7eb929124fc34c2218c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exchange-offline-address-book (0.0.15)
4
+ exchange-offline-address-book (0.0.16)
5
5
  autodiscover (~> 1)
6
6
  curb (~> 0.9)
7
7
  libmspack (~> 0.1)
@@ -3,15 +3,15 @@
3
3
  require 'dotenv/load'
4
4
 
5
5
  require 'autodiscover'
6
- #require "autodiscover/debug"
7
6
 
7
+ require "autodiscover/debug" if ENV['DEBUG']
8
8
  require 'yaml'
9
9
  require 'nokogiri'
10
10
  require 'tempfile'
11
11
  require 'json'
12
12
  require 'ostruct'
13
+ require 'shellwords'
13
14
 
14
- require 'curb'
15
15
  require_relative 'exchange-offline-address-book/parser'
16
16
  require_relative 'exchange-offline-address-book/mspack'
17
17
 
@@ -25,18 +25,16 @@ class OfflineAddressBook
25
25
  @baseurl = baseurl
26
26
  end
27
27
 
28
- def download(file, target = nil)
29
- client = Curl::Easy.new(baseurl + file)
30
- client.http_auth_types = :ntlm
31
- client.username = @username
32
- client.password = @password
33
- client.perform
34
-
35
- raise client.status unless client.response_code.to_s[0] == '2'
36
-
37
- return client.body_str if target.nil?
28
+ def path(name)
29
+ @files ||= {}
30
+ @files[name] ||= (@cachedir ? File.join(@cachedir, name) : Tempfile.new(name).path)
31
+ end
38
32
 
39
- open(target, 'wb'){|f| f.write(client.body_str) }
33
+ def download(name)
34
+ if !@cachedir || @update || !File.file?(path(name))
35
+ system "curl --#{ENV['DEBUG'] ? 'verbose' : 'silent'} --ntlm --user #{[@username, @password].join(':').shellescape} #{[baseurl, name].join('').shellescape} -o #{path(name).shellescape}"
36
+ end
37
+ return path(name)
40
38
  end
41
39
 
42
40
  def baseurl
@@ -56,35 +54,26 @@ class OfflineAddressBook
56
54
  lzx = File.basename(oab, File.extname(oab)) + '.lzx' if oab
57
55
  end
58
56
 
59
- lzx ||= Nokogiri::XML(download('oab.xml')).at('//Full').inner_text
57
+ lzx ||= Nokogiri::XML(open(download('oab.xml'))).at('//Full').inner_text
60
58
  oab = File.basename(lzx, File.extname(lzx)) + '.oab'
61
59
 
62
- if @cachedir && File.file?(File.join(@cachedir, oab))
63
- oab = File.join(@cachedir, oab)
64
- else
60
+ if !File.file?(path(oab))
65
61
  if @cachedir
66
62
  %w{*.oab *.lzx *.yml *.json}.each{|ext|
67
63
  Dir[File.join(@cachedir, ext)].each{|f| File.unlink(f) }
68
64
  }
69
- download(lzx, File.join(@cachedir, lzx))
70
- lzx = File.join(@cachedir, lzx)
71
- @oab = File.join(@cachedir, oab)
72
- else
73
- _lzx = Tempfile.new('lzx')
74
- download(lzx, _lzx.path)
75
- lzx = _lzx.path
76
- oab = Tempfile.new('oab').path
77
65
  end
78
66
 
79
- LibMsPack.oab_decompress(lzx, oab)
67
+ download(lzx)
68
+ LibMsPack.oab_decompress(path(lzx), path(oab))
80
69
  end
81
70
 
82
- oab
71
+ path(oab)
83
72
  end
84
73
  end
85
74
 
86
75
  def cache
87
- @cache ||= File.join(File.dirname(addressbook), File.basename(addressbook, File.extname(addressbook)) + '.json')
76
+ @cache ||= path(File.basename(addressbook, File.extname(addressbook)) + '.json')
88
77
  end
89
78
 
90
79
  def header
@@ -1,3 +1,3 @@
1
1
  class OfflineAddressBook
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
@@ -3,6 +3,8 @@ require 'dotenv/load'
3
3
  require 'minitest/autorun'
4
4
  require 'exchange-offline-address-book'
5
5
 
6
+ ENV['DEBUG'] = 'true'
7
+
6
8
  class EOABTest < Minitest::Test
7
9
  def test_downlod
8
10
  oab = OfflineAddressBook.new(username: ENV['USERNAME'], password: ENV['PASSWORD'], email: ENV['EMAIL'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange-offline-address-book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Heyns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler