Class: Use0MK::ShortenedURI

Inherits:
Object
  • Object
show all
Defined in:
lib/use0mk.rb

Overview

Represents a shortened URI from 0.mk. It contains only the information retrieved by the API call to 0.mk. The volume of information with any API call is not consistent therefore any attribute of this class that is nil or empty should be ignored.

The origin (the API call which generated the object of this class) of this object can be tracked with the origin attribute. The origin is a Symbol which is a member of ORIGINS.

It is not a good idea to create instances of this class by hand, as it contains only data available from API calls to 0.mk.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, attributes = {}) ⇒ ShortenedURI

Initializes this class. Usually called from either shorten or preview.

Parameters:

  • origin (Symbol)

    origin of this class (which API call created it), a member of ORIGINS

  • attributes (Hash) (defaults to: {})

    hash of the attributes needed to create the object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/use0mk.rb', line 183

def initialize(origin, attributes = {})

  if !(Use0MK::ORIGINS.member? origin)
    raise ArgumentError, "origin should be a member of Use0MK::ORIGINS"
  end

  @origin = origin
  @deleted = @origin != :shorten

  @long_uri = attributes[:long_uri]
  @short_uri = attributes[:short_uri]
  @short_name = attributes[:short_name]
  @stats_uri = attributes[:stats_uri]
  @title = attributes[:title]
  @delete_uri = attributes[:delete_uri]
  @delete_code = attributes[:delete_code]
end

Instance Attribute Details

#delete_codeString? (readonly)

the deletion code

Returns:

  • (String, nil)


174
175
176
# File 'lib/use0mk.rb', line 174

def delete_code
  @delete_code
end

#delete_uriString? (readonly)

the deletion URI

Returns:

  • (String, nil)


171
172
173
# File 'lib/use0mk.rb', line 171

def delete_uri
  @delete_uri
end

#deletedtrue, false (readonly)

whether this URI is deleted

Returns:

  • (true, false)


177
178
179
# File 'lib/use0mk.rb', line 177

def deleted
  @deleted
end

#long_uriString? (readonly)

the long URI

Returns:

  • (String, nil)


156
157
158
# File 'lib/use0mk.rb', line 156

def long_uri
  @long_uri
end

#originSymbol (readonly)

a member of ORIGINS

Returns:

  • (Symbol)


153
154
155
# File 'lib/use0mk.rb', line 153

def origin
  @origin
end

#short_nameString? (readonly)

the short name (http://0.mk/short_name)

Returns:

  • (String, nil)


162
163
164
# File 'lib/use0mk.rb', line 162

def short_name
  @short_name
end

#short_uriString? (readonly)

the shortened URI

Returns:

  • (String, nil)


159
160
161
# File 'lib/use0mk.rb', line 159

def short_uri
  @short_uri
end

#stats_uriString? (readonly)

the stats URI

Returns:

  • (String, nil)


165
166
167
# File 'lib/use0mk.rb', line 165

def stats_uri
  @stats_uri
end

#titleString? (readonly)

the document title of the long URI

Returns:

  • (String, nil)


168
169
170
# File 'lib/use0mk.rb', line 168

def title
  @title
end

Instance Method Details

#deletetrue, false

Deletes the shortened URI. This method calls Interface.delete internally.

Returns:

  • (true, false)

    wheter deletion succeeds (usually true when origin is :shorten)



205
206
207
208
209
210
211
# File 'lib/use0mk.rb', line 205

def delete
  if @deleted
    return false
  end

  @deleted = Use0MK::Interface.delete(@delete_uri, @delete_code)
end