class BlinkShortener::Shorten

Public Class Methods

new(url, email, password) click to toggle source
# 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

Public Instance Methods

shorten() click to toggle source
# 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

Private Instance Methods

get_domain_id() click to toggle source
# File lib/blink_shortener/shorten.rb, line 23
def get_domain_id
  response = HTTParty.get(@domain_url, headers: {Authorization: "Bearer #{@token}"})
  response["objects"]&.first["id"]
rescue => ex
  raise ex
end