Class: Panchira::TwitterResolver

Inherits:
Resolver
  • Object
show all
Defined in:
lib/panchira/resolvers/twitter_resolver.rb

Constant Summary collapse

URL_REGEXP =
/twitter.com\/(\w+)\/status\/(\d+)/.freeze

Instance Method Summary collapse

Methods inherited from Resolver

applicable?

Constructor Details

#initialize(url, options = nil) ⇒ TwitterResolver

Returns a new instance of TwitterResolver.



9
10
11
12
13
14
15
16
17
18
# File 'lib/panchira/resolvers/twitter_resolver.rb', line 9

def initialize(url, options = nil)
  super(url, options)
  @screen_name = @url.slice(URL_REGEXP, 1)
  @id = @url.slice(URL_REGEXP, 2)

  @bearer_token = options&.dig(:twitter, :bearer_token)

  @author = nil
  @response = nil
end

Instance Method Details

#fetchObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/panchira/resolvers/twitter_resolver.rb', line 20

def fetch
  return super unless @bearer_token

  @response = fetch_api if @bearer_token

  result = PanchiraResult.new

  result.canonical_url = parse_canonical_url
  result.title = parse_title
  result.description = parse_description
  result.image = parse_image
  result.tags = parse_tags
  result.author = parse_author
  result.resolver = parse_resolver

  result
end