Module: GetShorty::ClassMethods

Defined in:
lib/get_shorty.rb

Instance Method Summary collapse

Instance Method Details

#has_short_url(options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/get_shorty.rb', line 20

def has_short_url(options={})
  include InstanceMethods
  include ActionController::UrlWriter if defined?(ActionController )# non mvc - but need to know the url for model instance to persist the short_url.
  @short_url_options = {:long_url_method => :generate_long_url, :short_url_method => :short_url}.update(options) 
  @shortening_serivce = options[:shortener_service] || Bitly::Client.connection
  set_long_url_host options[:long_url_host]
end

#set_long_url_host(value) ⇒ Object

for Rails when using UrlWriter



29
30
31
32
33
34
35
# File 'lib/get_shorty.rb', line 29

def set_long_url_host(value)
  self.default_url_options[:host] = if value.is_a?(Hash) && defined?(Rails)
    value.stringify_keys[Rails.env]
  else
    value
  end
end

#short_url_optionsObject

Returns the short_url_options defined by each call to has_short_url.



12
13
14
# File 'lib/get_shorty.rb', line 12

def short_url_options
  @short_url_options
end

#shortening_serivceObject



16
17
18
# File 'lib/get_shorty.rb', line 16

def shortening_serivce
  @shortening_serivce
end