Class: Sendly::ShortLinkListItem

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

Overview

A short link with click analytics, as returned by LinksResource#list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ShortLinkListItem

Returns a new instance of ShortLinkListItem.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sendly/links_resource.rb', line 37

def initialize(data)
  @code = data["code"]
  @short_url = data["shortUrl"] || data["short_url"]
  @destination_url = data["destinationUrl"] || data["destination_url"]
  @brand_slug = data["brandSlug"] || data["brand_slug"]
  @click_count = data["clickCount"] || data["click_count"] || 0
  @disabled = data["disabled"] || false
  @last_country = data["lastCountry"] || data["last_country"]
  @last_clicked_at = parse_time(data["lastClickedAt"] || data["last_clicked_at"])
  @created_at = parse_time(data["createdAt"] || data["created_at"])
  # 14-day daily click histogram, oldest first (today last)
  @spark = data["spark"] || []
end

Instance Attribute Details

#brand_slugObject (readonly)

Returns the value of attribute brand_slug.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def brand_slug
  @brand_slug
end

#click_countObject (readonly)

Returns the value of attribute click_count.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def click_count
  @click_count
end

#codeObject (readonly)

Returns the value of attribute code.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def code
  @code
end

#created_atObject (readonly)

Returns the value of attribute created_at.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def created_at
  @created_at
end

#destination_urlObject (readonly)

Returns the value of attribute destination_url.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def destination_url
  @destination_url
end

#disabledObject (readonly)

Returns the value of attribute disabled.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def disabled
  @disabled
end

#last_clicked_atObject (readonly)

Returns the value of attribute last_clicked_at.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def last_clicked_at
  @last_clicked_at
end

#last_countryObject (readonly)

Returns the value of attribute last_country.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def last_country
  @last_country
end

#short_urlObject (readonly)

Returns the value of attribute short_url.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def short_url
  @short_url
end

#sparkObject (readonly)

Returns the value of attribute spark.



34
35
36
# File 'lib/sendly/links_resource.rb', line 34

def spark
  @spark
end

Instance Method Details

#disabled?Boolean

Returns Whether the link is disabled (its redirect returns 404).

Returns:

  • (Boolean)

    Whether the link is disabled (its redirect returns 404)



52
53
54
# File 'lib/sendly/links_resource.rb', line 52

def disabled?
  disabled
end

#to_hObject



56
57
58
59
60
61
62
63
# File 'lib/sendly/links_resource.rb', line 56

def to_h
  {
    code: code, short_url: short_url, destination_url: destination_url,
    brand_slug: brand_slug, click_count: click_count, disabled: disabled,
    last_country: last_country, last_clicked_at: last_clicked_at&.iso8601,
    created_at: created_at&.iso8601, spark: spark
  }.compact
end