cliz 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cliz +9 -24
- data/lib/functions.rb +30 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e969650b2cf9c73bcc4ccd6828ae1c017e3b28636c53ab5df834f22b3578be
|
4
|
+
data.tar.gz: c65d9ec553353788a99a7885582ba078cfde12a8f073a341ed554facdf271ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42bf0f66ac2f39af3cd067f817251d84f68fa93cc79cb53b8bff39500208e3d817cc6bc10ca41acef0046b61e2b75075b7c66e5d2812c0517c0ec5b6bb56babe
|
7
|
+
data.tar.gz: 3055bdfb251fd53754a2d0e1c0ca40f3ca07e6d5b12cafe7bf11fb585978aa510177d74477f350ba1f874d8ad69e2b61d48112b9d7691c90e9b9436c48c7130e
|
data/bin/cliz
CHANGED
@@ -1,42 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'securerandom'
|
4
3
|
require 'fileutils'
|
5
4
|
require 'yaml'
|
6
|
-
require 'fileutils'
|
7
5
|
require_relative '../lib/functions.rb'
|
8
6
|
|
9
7
|
include Cliz
|
10
8
|
|
11
|
-
|
12
|
-
|
13
9
|
config = YAML.load(File.read('config.yml'))
|
14
10
|
output_dir = config['output_dir']
|
15
11
|
|
12
|
+
# Is this the right place for this?
|
13
|
+
# Could we have a initialization function?
|
16
14
|
FileUtils.mkdir_p File.join output_dir, 'reverse-index'
|
17
15
|
|
18
16
|
url = ARGV[0]
|
19
17
|
short_suggestion = ARGV[1]
|
18
|
+
short_urls = nil
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
base_domain = config['base_domain']
|
27
|
-
paths = File.open(reverse_index_file).readlines
|
28
|
-
for path in paths
|
29
|
-
puts File.join base_domain, path
|
30
|
-
end
|
31
|
-
exit
|
32
|
-
end
|
20
|
+
if short_suggestion
|
21
|
+
short_urls = [short(config, url, short_suggestion)]
|
22
|
+
else
|
23
|
+
short_urls = previously_shortened_urls(config, url)
|
24
|
+
short_urls ||= [short(config, url)]
|
33
25
|
end
|
34
26
|
|
35
|
-
|
36
|
-
short_url = short config, url, short_suggestion
|
37
|
-
|
38
|
-
# do reverse index
|
39
|
-
|
40
|
-
reverse_index config, short_url
|
41
|
-
|
42
|
-
puts short_url
|
27
|
+
print_urls(short_urls)
|
data/lib/functions.rb
CHANGED
@@ -71,9 +71,12 @@ module Cliz
|
|
71
71
|
folder_path = get_a_folder_path output_dir, short_suggestion
|
72
72
|
create_index_file(url, folder_path)
|
73
73
|
|
74
|
-
|
74
|
+
short_url = File.join base_domain, short_suggestion
|
75
|
+
reverse_index config, short_url
|
75
76
|
|
76
|
-
|
77
|
+
system("sh #{deploy_script}") if deploy_script
|
78
|
+
|
79
|
+
short_url
|
77
80
|
end
|
78
81
|
|
79
82
|
##
|
@@ -94,7 +97,7 @@ module Cliz
|
|
94
97
|
|
95
98
|
def reverse_index config, short_url
|
96
99
|
output_dir = config['output_dir']
|
97
|
-
|
100
|
+
|
98
101
|
long_url = long_url config, short_url
|
99
102
|
|
100
103
|
reverse_index_file = File.join output_dir, 'reverse-index', "#{Digest::SHA2.hexdigest long_url}"
|
@@ -104,4 +107,28 @@ module Cliz
|
|
104
107
|
f.puts path(config, short_url)
|
105
108
|
end
|
106
109
|
end
|
110
|
+
|
111
|
+
def previously_shortened_urls(config, url)
|
112
|
+
output_dir = config['output_dir']
|
113
|
+
|
114
|
+
reverse_index_file = File.join output_dir, 'reverse-index', "#{Digest::SHA2.hexdigest url}"
|
115
|
+
|
116
|
+
if File.exist? reverse_index_file
|
117
|
+
urls = []
|
118
|
+
base_domain = config['base_domain']
|
119
|
+
paths = File.open(reverse_index_file).readlines
|
120
|
+
|
121
|
+
for path in paths
|
122
|
+
urls << File.join(base_domain, path)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
urls
|
127
|
+
end
|
128
|
+
|
129
|
+
def print_urls(urls)
|
130
|
+
for url in urls
|
131
|
+
puts url
|
132
|
+
end
|
133
|
+
end
|
107
134
|
end
|