Class: Shortener::Short

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/shortener/short.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SHORT_KEYS =
[:url, :shortened, :type, :ext, :s3, :'click-count', :'max-count',
:'set-count', :'expire-time', :sha]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

delete, fetch, index, request, shorten, upload

Constructor Details

#initialize(short, conf = nil) ⇒ Short

Set up this short. Will:

  • store the configuration if necessary

  • parse JSON if short is JSON

  • symbolize the shorts keys

  • turn string numbers in to actual numbers.



69
70
71
72
73
74
# File 'lib/shortener/short.rb', line 69

def initialize(short, conf = nil)
  @configuration = conf unless conf.nil?
  short = parse_return(short) unless short.is_a?(Hash)
  @data = symbolize_keys(short)
  normalize_data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/shortener/short.rb', line 8

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object

an alternative way to fetch stuff from @data



82
83
84
# File 'lib/shortener/short.rb', line 82

def [](key)
  @data[key.to_sym]
end

#configurationObject

the configuration that this short will use.



77
78
79
# File 'lib/shortener/short.rb', line 77

def configuration
  @configuation.nil? ? Shortener::Configuration.current : @configuration
end

#pretty_printObject



115
116
117
# File 'lib/shortener/short.rb', line 115

def pretty_print

end

#short_uriObject

a URI of short url.



97
98
99
# File 'lib/shortener/short.rb', line 97

def short_uri
  URI.parse(short_url)
end

#short_urlObject

shortened combined with config#shortener_url



92
93
94
# File 'lib/shortener/short.rb', line 92

def short_url
  "#{configuration.shortener_url}/#{shortened}"
end

#updateObject

allow the updating of a field. considering an arity like: update(hsh_of_fields_with_values) and it will create a POST request to send server side.



104
105
106
# File 'lib/shortener/short.rb', line 104

def update
  #TODO
end

#uriObject

return a URI of the URL



87
88
89
# File 'lib/shortener/short.rb', line 87

def uri
  URI.parse(url)
end