class UrlExpander::Expanders::Dldbz

Expand dld.bz URLS Usage: UrlExpander::Client.expand(“dld.bz/ahsJ2”)

Constants

PATTERN

NOTICE: We ignored the / before the key

Attributes

parent_klass[R]
short_url[R]

Public Class Methods

new(short_url, options={}) click to toggle source
# File lib/url_expander/expanders/api/dldbz.rb, line 15
def initialize(short_url, options={})
  @parent_klass = self
  @short_url = short_url
  fetch_url
end

Private Instance Methods

fetch_url() click to toggle source
# File lib/url_expander/expanders/api/dldbz.rb, line 30
def fetch_url
  data = JSON.parse Request.get("/api/expand?url=#{@short_url}").response.body
  if(data.include?("data"))
    @long_url = data["data"]["long_url"]
  else
    error = data["error"]
    raise UrlExpander::Error.new(error["message"],error["code"])
  end
end