Class: Shortener::Short
- Inherits:
-
Object
- Object
- Shortener::Short
- 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
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#[](key) ⇒ Object
an alternative way to fetch stuff from @data.
-
#configuration ⇒ Object
the configuration that this short will use.
-
#initialize(short, conf = nil) ⇒ Short
constructor
Set up this short.
- #pretty_print ⇒ Object
-
#short_uri ⇒ Object
a URI of short url.
-
#short_url ⇒ Object
shortened combined with config#shortener_url.
-
#update ⇒ Object
allow the updating of a field.
-
#uri ⇒ Object
return a URI of the URL.
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
#data ⇒ Object (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 |
#configuration ⇒ Object
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_print ⇒ Object
115 116 117 |
# File 'lib/shortener/short.rb', line 115 def pretty_print end |
#short_uri ⇒ Object
a URI of short url.
97 98 99 |
# File 'lib/shortener/short.rb', line 97 def short_uri URI.parse(short_url) end |
#short_url ⇒ Object
shortened combined with config#shortener_url
92 93 94 |
# File 'lib/shortener/short.rb', line 92 def short_url "#{configuration.shortener_url}/#{shortened}" end |
#update ⇒ Object
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 |
#uri ⇒ Object
return a URI of the URL
87 88 89 |
# File 'lib/shortener/short.rb', line 87 def uri URI.parse(url) end |