Class: Bitly::V4::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitly/v4/client.rb

Overview

Bitly Client.

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/bitly/v4/client.rb', line 10

def initialize(**args)
  @conn = Faraday.new(BASE_URI)
  @conn.authorization(:Bearer, args[:access_token])
  @conn.headers[:content_type] = 'application/json'
end

Instance Method Details

#shorten(long_url, options = {}) ⇒ Object



16
17
18
19
20
# File 'lib/bitly/v4/client.rb', line 16

def shorten(long_url, options = {})
  body = { long_url: long_url }.merge(options)
  response = post('/v4/shorten', body.to_json)
  Bitly::V4::Bitlink.new(JSON.parse(response.body, symbolize_names: true))
end