dogo 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.
- data/README.md +3 -3
- data/examples/config.ru +1 -0
- data/lib/dogo/server.rb +4 -5
- data/lib/dogo/url.rb +9 -5
- data/lib/dogo/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -30,9 +30,9 @@ You can create shortened urls by using `Dogo::Url.new`.
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
shortened = Dogo::Url.new("http://hellobits.com")
|
33
|
-
shortened.id #=> return some an integer
|
34
|
-
shortened.url #=> return the
|
35
|
-
shortened.full #=> return full
|
33
|
+
shortened.id #=> return some an integer in base 36
|
34
|
+
shortened.url #=> return the shortened url
|
35
|
+
shortened.full #=> return full url
|
36
36
|
```
|
37
37
|
|
38
38
|
Starting the server:
|
data/examples/config.ru
CHANGED
data/lib/dogo/server.rb
CHANGED
@@ -17,12 +17,11 @@ module Dogo
|
|
17
17
|
end
|
18
18
|
|
19
19
|
get "/shorten" do
|
20
|
-
require "pry"; binding.pry
|
21
20
|
halt 401, erb(:"401") unless Dogo.api_key == params[:api_key]
|
22
21
|
|
23
22
|
if Dogo::Url.valid?(params[:url])
|
24
23
|
shortened = Dogo::Url.new(params[:url])
|
25
|
-
|
24
|
+
shortened.url
|
26
25
|
else
|
27
26
|
status 422
|
28
27
|
erb(:"422")
|
@@ -30,10 +29,10 @@ module Dogo
|
|
30
29
|
end
|
31
30
|
|
32
31
|
get "/:id" do
|
33
|
-
|
32
|
+
shortened = find_or_pass(params[:id])
|
33
|
+
shortened.click!
|
34
34
|
|
35
|
-
|
36
|
-
redirect url.url
|
35
|
+
redirect shortened.full
|
37
36
|
end
|
38
37
|
|
39
38
|
not_found do
|
data/lib/dogo/url.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Dogo
|
2
2
|
class Url
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :full, :id
|
4
4
|
|
5
5
|
# Check if the given URL is valid, according the the
|
6
6
|
# +URI+ regular expression.
|
@@ -17,11 +17,15 @@ module Dogo
|
|
17
17
|
new Dogo.redis.get(key)
|
18
18
|
end
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(full)
|
21
|
+
@full = full
|
22
22
|
load_or_create
|
23
23
|
end
|
24
24
|
|
25
|
+
def url
|
26
|
+
File.join(Dogo.host, id)
|
27
|
+
end
|
28
|
+
|
25
29
|
# Increment the click counter for this URL.
|
26
30
|
def click!
|
27
31
|
Dogo.redis.incr(click_key)
|
@@ -48,12 +52,12 @@ module Dogo
|
|
48
52
|
@id = key.split(":").last
|
49
53
|
else
|
50
54
|
@id = next_id.to_s(36)
|
51
|
-
Dogo.redis.set("urls:#{hash}:#{id}",
|
55
|
+
Dogo.redis.set("urls:#{hash}:#{id}", full)
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
59
|
def hash
|
56
|
-
@hash ||= Digest::MD5.hexdigest(
|
60
|
+
@hash ||= Digest::MD5.hexdigest(full)
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
data/lib/dogo/version.rb
CHANGED