rhcf-utils 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/rhcf/utils/download_cache.rb +5 -3
- data/lib/rhcf/utils/email.rb +52 -0
- data/lib/rhcf/utils/network.rb +10 -0
- data/lib/rhcf/utils/version.rb +1 -1
- data/spec/lib/rhcf/utils/download_cache_spec.rb +9 -8
- metadata +4 -4
- data/spec/lib/rhcf/utils/.download_cache_spec.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bf241e04517574674c112b8ae6e7112c754f795
|
4
|
+
data.tar.gz: f86503515dfd584020a03e45e1117cced9d73e55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0342944c6a84423d3ac5393db024a4acdd5c39e647577fb792c302c8c705dcee2b1f3a26fee1954bfdb3c3d93c1e8df8a9137aa11bfd23ba726a088f2bd0b076
|
7
|
+
data.tar.gz: 145efcdaf360f62ee412272e72bf9cc7fdccdeaac7a6efbadde7fb27e296976608fa671a48d63f8514d2f03b25120cb9c920b31106094fe51fba4158aa682eda
|
data/.gitignore
CHANGED
@@ -19,15 +19,17 @@ module Rhcf
|
|
19
19
|
return outfile if self.class.hit_fname?(outfile, @ttl) # here goes the cache
|
20
20
|
download!(url, outfile)
|
21
21
|
rescue
|
22
|
-
|
22
|
+
if File.exist?(outfile)
|
23
|
+
File.unlink(outfile)
|
24
|
+
end
|
23
25
|
raise
|
24
26
|
end
|
25
27
|
|
26
28
|
|
27
29
|
def download!(url, outfile)
|
28
30
|
mkdir_p(File.dirname(outfile))
|
29
|
-
File.open(outfile, '
|
30
|
-
open(url, "
|
31
|
+
File.open(outfile, 'wb') do |fd|
|
32
|
+
open(url, "rb") do |down|
|
31
33
|
fd.write(down.read)
|
32
34
|
end
|
33
35
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
require 'stringio'
|
3
|
+
require 'net/smtp'
|
4
|
+
module Net
|
5
|
+
class SMTP
|
6
|
+
def socket
|
7
|
+
@socket
|
8
|
+
end
|
9
|
+
|
10
|
+
def bind_at(ip)
|
11
|
+
@bind_at = ip
|
12
|
+
end
|
13
|
+
|
14
|
+
def tcp_socket(address, port)
|
15
|
+
in_addr = Socket.pack_sockaddr_in(0, @bind_at) if @bind_at
|
16
|
+
|
17
|
+
out_addr = Socket.pack_sockaddr_in(port, address)
|
18
|
+
s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
19
|
+
s.bind(in_addr) if @bind_at
|
20
|
+
s.connect(out_addr)
|
21
|
+
s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
module Rhcf
|
28
|
+
module Utils
|
29
|
+
module Email
|
30
|
+
def self.get_mxs(domain)
|
31
|
+
Resolv::DNS.open do |dns|
|
32
|
+
dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect{|x| x.exchange.to_s}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.transmit(from, to, body, bind_interface, ehlo = 'localhost.localdomain')
|
37
|
+
domain = to.split('@').last
|
38
|
+
|
39
|
+
chat = StringIO.new
|
40
|
+
mx = get_mxs(domain).sample
|
41
|
+
smtp = Net::SMTP.new(mx, 25)
|
42
|
+
smtp.bind_at bind_interface
|
43
|
+
result = smtp.start(ehlo) do |smtp|
|
44
|
+
smtp.socket.debug_output = chat
|
45
|
+
smtp.send_message body, from, to
|
46
|
+
end
|
47
|
+
|
48
|
+
{status: result.status, string: result.string, chat: chat.string}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/rhcf/utils/version.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
|
|
4
4
|
require 'timecop'
|
5
5
|
|
6
6
|
describe Rhcf::Utils::DownloadCache do
|
7
|
-
let(:img_url){"http://
|
7
|
+
let(:img_url){"http://veja2.abrilm.com.br/assets/images/2014/3/212814/imagens-do-dia-20131023-04-original.jpg"}
|
8
8
|
let(:cache_of_30s){Rhcf::Utils::DownloadCache.new('cache_of_30s', 30)}
|
9
9
|
let(:foo_cache_of_30s){Rhcf::Utils::DownloadCache.new('cache_of_30s', 30, '/tmp/foo')}
|
10
10
|
it "should be a class" do
|
@@ -31,11 +31,11 @@ describe Rhcf::Utils::DownloadCache do
|
|
31
31
|
describe "#hit?" do
|
32
32
|
before(:each) do
|
33
33
|
FileUtils.rm_rf "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054ca0b0d5f8"
|
34
|
-
FileUtils.mkdir_p "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/
|
35
|
-
FileUtils.touch "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/
|
34
|
+
FileUtils.mkdir_p "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e7fb5389b6646ebb89aaa5502b75a440"
|
35
|
+
FileUtils.touch "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg"
|
36
36
|
end
|
37
37
|
it "should return true if file downloaded and ttl is null" do
|
38
|
-
cache_of_30s.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/
|
38
|
+
cache_of_30s.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg'
|
39
39
|
cache_of_30s.hit?(img_url).should be_true
|
40
40
|
end
|
41
41
|
it "should return true if file downloaded and newer then ttl" do
|
@@ -47,7 +47,7 @@ describe Rhcf::Utils::DownloadCache do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
it "should return false if doesn't exist" do
|
50
|
-
FileUtils.rm "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/
|
50
|
+
FileUtils.rm "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg"
|
51
51
|
cache_of_30s.hit?(img_url).should be_false
|
52
52
|
end
|
53
53
|
|
@@ -56,7 +56,7 @@ describe Rhcf::Utils::DownloadCache do
|
|
56
56
|
|
57
57
|
describe "#filename_for" do
|
58
58
|
it "should return a path with cache id , file name hash and file hash component" do
|
59
|
-
subject.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/default/
|
59
|
+
subject.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/default/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg'
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -77,8 +77,8 @@ describe Rhcf::Utils::DownloadCache do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "#get" do
|
80
|
-
let(:expected_path){ '/tmp/Rhcf::Utils::DownloadCache/default/
|
81
|
-
let(:expected_30s_path){ '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/
|
80
|
+
let(:expected_path){ '/tmp/Rhcf::Utils::DownloadCache/default/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg' }
|
81
|
+
let(:expected_30s_path){ '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg' }
|
82
82
|
before(:each) do
|
83
83
|
File.unlink(expected_path) rescue nil
|
84
84
|
end
|
@@ -86,6 +86,7 @@ describe Rhcf::Utils::DownloadCache do
|
|
86
86
|
it "should download when not exist"do
|
87
87
|
subject.get(img_url).should == expected_path
|
88
88
|
File.exist?(expected_path).should be_true
|
89
|
+
expect(`file #{expected_path}`).to match_regex /JPEG/
|
89
90
|
end
|
90
91
|
|
91
92
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcf-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romeu Fonseca
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,9 +138,10 @@ files:
|
|
138
138
|
- Rakefile
|
139
139
|
- lib/rhcf/utils.rb
|
140
140
|
- lib/rhcf/utils/download_cache.rb
|
141
|
+
- lib/rhcf/utils/email.rb
|
142
|
+
- lib/rhcf/utils/network.rb
|
141
143
|
- lib/rhcf/utils/version.rb
|
142
144
|
- rhcf-utils.gemspec
|
143
|
-
- spec/lib/rhcf/utils/.download_cache_spec.rb.swp
|
144
145
|
- spec/lib/rhcf/utils/download_cache_spec.rb
|
145
146
|
- spec/spec_helper.rb
|
146
147
|
homepage: ''
|
@@ -168,6 +169,5 @@ signing_key:
|
|
168
169
|
specification_version: 4
|
169
170
|
summary: Personal Ruby Utility Tools.
|
170
171
|
test_files:
|
171
|
-
- spec/lib/rhcf/utils/.download_cache_spec.rb.swp
|
172
172
|
- spec/lib/rhcf/utils/download_cache_spec.rb
|
173
173
|
- spec/spec_helper.rb
|
Binary file
|