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 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 long url
35
- shortened.full #=> return full shortened url
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
@@ -2,6 +2,7 @@ $:.unshift File.expand_path("../../lib", __FILE__)
2
2
 
3
3
  require "dogo"
4
4
 
5
+ Dogo.host = "http://localhost:9292"
5
6
  Dogo.api_key = "abc"
6
7
  Dogo.default_url = "http://hellobits.com"
7
8
 
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
- "#{request.scheme}://#{request.host_with_port}/#{shortened.id}"
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
- url = find_or_pass(params[:id])
32
+ shortened = find_or_pass(params[:id])
33
+ shortened.click!
34
34
 
35
- url.click!
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 :url, :id
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(url)
21
- @url = url
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}", url)
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(url)
60
+ @hash ||= Digest::MD5.hexdigest(full)
57
61
  end
58
62
  end
59
63
  end
data/lib/dogo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dogo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dogo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira