Class: Twingly::LiveFeed::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/livefeed/post.rb

Overview

A blog post

Constant Summary collapse

EMPTY_ARRAY =
[].freeze
EMPTY_HASH =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorString (readonly)

the author of the blog post

Returns:

  • (String)

    the current value of author



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def author
  @author
end

#authorityInteger (readonly)

the blog’s authority/influence. See developer.twingly.com/resources/ranking/#authority

Returns:

  • (Integer)

    the current value of authority



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def authority
  @authority
end

#blog_idString (readonly)

the blog ID (Twingly internal identification)

Returns:

  • (String)

    the current value of blog_id



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def blog_id
  @blog_id
end

#blog_nameString (readonly)

the name of the blog

Returns:

  • (String)

    the current value of blog_name



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def blog_name
  @blog_name
end

#blog_rankInteger (readonly)

the rank of the blog, based on authority and language. See developer.twingly.com/resources/ranking/#blogrank

Returns:

  • (Integer)

    the current value of blog_rank



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def blog_rank
  @blog_rank
end

#blog_urlString (readonly)

the blog URL

Returns:

  • (String)

    the current value of blog_url



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def blog_url
  @blog_url
end

#coordinatesHash (readonly)

a hash containing :latitude and :longitude from the post RSS

Returns:

  • (Hash)

    the current value of coordinates



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def coordinates
  @coordinates
end

#idString (readonly)

the post ID (Twingly internal identification)

Returns:

  • (String)

    the current value of id



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def id
  @id
end

#imagesArray (readonly)

image URLs from the post (currently not populated)

Returns:

  • (Array)

    the current value of images



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def images
  @images
end

#indexed_atTime (readonly)

the time, in UTC, when the post was indexed by Twingly

Returns:

  • (Time)

    the current value of indexed_at



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def indexed_at
  @indexed_at
end

number of links to this post that was found in other blog posts

Returns:

  • (String)

    the current value of inlinks_count



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def inlinks_count
  @inlinks_count
end

#language_codeString (readonly)

ISO two letter language code for the language that the post was written in

Returns:

  • (String)

    the current value of language_code



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def language_code
  @language_code
end

all links from the blog post to other resources

Returns:

  • (Array)

    the current value of links



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def links
  @links
end

#location_codeString (readonly)

ISO two letter country code for the location of the blog

Returns:

  • (String)

    the current value of location_code



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def location_code
  @location_code
end

#published_atTime (readonly)

the time, in UTC, when the post was published

Returns:

  • (Time)

    the current value of published_at



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def published_at
  @published_at
end

#reindexed_atTime (readonly)

timestamp when the post last was changed in our database/index

Returns:

  • (Time)

    the current value of reindexed_at



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def reindexed_at
  @reindexed_at
end

#tagsArray (readonly)

the post tags/categories

Returns:

  • (Array)

    the current value of tags



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def tags
  @tags
end

#textString (readonly)

the blog post text

Returns:

  • (String)

    the current value of text



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def text
  @text
end

#titleString (readonly)

the post title

Returns:

  • (String)

    the current value of title



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def title
  @title
end

#urlString (readonly)

the post URL

Returns:

  • (String)

    the current value of url



34
35
36
# File 'lib/twingly/livefeed/post.rb', line 34

def url
  @url
end

Instance Method Details

#set_values(params) ⇒ Object

Sets all instance variables for the Twingly::LiveFeed::Post, given a Hash.

Parameters:

  • params (Hash)

    containing blog post data.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/twingly/livefeed/post.rb', line 46

def set_values(params)
  @id            = params.fetch('id')
  @author        = params.fetch('author')
  @url           = params.fetch('url')
  @title         = params.fetch('title')
  @text          = params.fetch('text')
  @language_code = params.fetch('languageCode')
  @location_code = params.fetch('locationCode')
  @coordinates   = params.fetch('coordinates') { EMPTY_HASH }
  @links         = params.fetch('links') { EMPTY_ARRAY }
  @tags          = params.fetch('tags') { EMPTY_ARRAY }
  @images        = params.fetch('images') { EMPTY_ARRAY }
  @indexed_at    = Time.parse(params.fetch('indexedAt'))
  @published_at  = Time.parse(params.fetch('publishedAt'))
  @reindexed_at  = Time.parse(params.fetch('reindexedAt'))
  @inlinks_count = params.fetch('inlinksCount').to_i
  @blog_id       = params.fetch('blogId')
  @blog_name     = params.fetch('blogName')
  @blog_url      = params.fetch('blogUrl')
  @blog_rank     = params.fetch('blogRank').to_i
  @authority     = params.fetch('authority').to_i
end

#to_hHash

Returns a hash containing all post attributes.

Returns:

  • (Hash)

    a hash containing all post attributes.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/twingly/livefeed/post.rb', line 70

def to_h
  {
    id: @id,
    author: @author,
    url: @url,
    title: @title,
    text: @text,
    language_code: @language_code,
    location_code: @location_code,
    coordinates: @coordinates,
    links: @links,
    tags: @tags,
    images: @images,
    indexed_at: @indexed_at,
    published_at: @published_at,
    reindexed_at: @reindexed_at,
    inlinks_count: @inlinks_count,
    blog_id: @blog_id,
    blog_name: @blog_name,
    blog_url: @blog_url,
    blog_rank: @blog_rank,
    authority: @authority,
  }
end