Class: Metalbird::UrlProcessor::Google

Inherits:
Object
  • Object
show all
Defined in:
lib/metalbird/url_processors/google.rb

Constant Summary collapse

RETRY_LIMIT =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Google

Returns a new instance of Google


10
11
12
13
# File 'lib/metalbird/url_processors/google.rb', line 10

def initialize(opts)
  @client = Googl
  @key = opts[:api_key]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


8
9
10
# File 'lib/metalbird/url_processors/google.rb', line 8

def client
  @client
end

Instance Method Details

#expand(shorten_link) ⇒ Object


25
26
27
28
29
30
31
32
33
# File 'lib/metalbird/url_processors/google.rb', line 25

def expand(shorten_link)
  retry_counter ||=  0
  Googl.expand(shorten_link, key: @key).long_url
rescue => error
  Metalbird::Logger.error(error)
  retry_counter += 1
  retry if retry_counter <= RETRY_LIMIT
  raise URLExpandFailError
end

#generate(link) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'lib/metalbird/url_processors/google.rb', line 15

def generate(link)
  retry_counter ||= 0
  Googl.shorten(link, nil, @key).short_url
rescue => error
  Metalbird::Logger.error(error)
  retry_counter += 1
  retry if retry_counter <= RETRY_LIMIT
  raise URLShortenFailError
end