Class: BlinkShortener::Shorten

Inherits:
Object
  • Object
show all
Defined in:
lib/blink_shortener/shorten.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, email, password) ⇒ Shorten

Returns a new instance of Shorten.



7
8
9
10
11
12
# File 'lib/blink_shortener/shorten.rb', line 7

def initialize(url, email, password)
  @token = BlinkShortener::AccessToken.new(email, password).get_token
  @domain_url = URL::DOMAINS_URL
  @shorten_url = "#{URL::BASE_URL}/#{get_domain_id}/links"
  @url = url
end

Instance Method Details

#shortenObject



14
15
16
17
18
19
# File 'lib/blink_shortener/shorten.rb', line 14

def shorten
  response = HTTParty.post(@shorten_url, body: {url: @shorten_url}.to_json, headers: {Authorization: "Bearer #{@token}"})
  response["objects"]&.first["short_link"]
rescue => ex
  raise ex
end