Class: Twingly::Search::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/search/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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def authority
  @authority
end

#blog_idString (readonly)

the blog ID (Twingly internal identification)

Returns:

  • (String)

    the current value of blog_id



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def blog_id
  @blog_id
end

#blog_nameString (readonly)

the name of the blog

Returns:

  • (String)

    the current value of blog_name



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def blog_rank
  @blog_rank
end

#blog_urlString (readonly)

the blog URL

Returns:

  • (String)

    the current value of blog_url



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def coordinates
  @coordinates
end

#idString (readonly)

the post ID (Twingly internal identification)

Returns:

  • (String)

    the current value of id



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def id
  @id
end

#imagesArray (readonly)

image URLs from the post (currently not populated)

Returns:

  • (Array)

    the current value of images



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def language_code
  @language_code
end

all links from the blog post to other resources

Returns:

  • (Array)

    the current value of links



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

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



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def reindexed_at
  @reindexed_at
end

#tagsArray (readonly)

the post tags/categories

Returns:

  • (Array)

    the current value of tags



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def tags
  @tags
end

#textString (readonly)

the blog post text

Returns:

  • (String)

    the current value of text



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def text
  @text
end

#titleString (readonly)

the post title

Returns:

  • (String)

    the current value of title



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def title
  @title
end

#urlString (readonly)

the post URL

Returns:

  • (String)

    the current value of url



33
34
35
# File 'lib/twingly/search/post.rb', line 33

def url
  @url
end

Instance Method Details

#indexedObject

Deprecated.

Please use #indexed_at instead



75
76
77
78
# File 'lib/twingly/search/post.rb', line 75

def indexed
  warn "[DEPRECATION] `indexed` is deprecated. Please use `indexed_at` instead."
  indexed_at
end
Deprecated.

Please use #links instead



87
88
89
90
# File 'lib/twingly/search/post.rb', line 87

def outlinks
  warn "[DEPRECATION] `outlinks` is deprecated. Please use `links` instead."
  links
end

#publishedObject

Deprecated.

Please use #published_at instead



81
82
83
84
# File 'lib/twingly/search/post.rb', line 81

def published
  warn "[DEPRECATION] `published` is deprecated. Please use `published_at` instead."
  published_at
end

#set_values(params) ⇒ Object

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

Parameters:

  • params (Hash)

    containing blog post data.



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

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

#summaryObject

Deprecated.

Please use #text instead



69
70
71
72
# File 'lib/twingly/search/post.rb', line 69

def summary
  warn "[DEPRECATION] `summary` is deprecated. Please use `text` instead."
  text
end

#to_hHash

Returns a hash containing all post attributes.

Returns:

  • (Hash)

    a hash containing all post attributes.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/twingly/search/post.rb', line 93

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