Class: Bitly::Client::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(long_url, api_token = nil, api_url = nil) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
15
# File 'lib/bitly/client/connection.rb', line 11

def initialize(long_url, api_token = nil, api_url = nil)
  @api_token = api_token || Bitly::Client.configuration.api_token
  @api_url = api_url || Bitly::Client.configuration.api_url
  @long_url = long_url
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



7
8
9
# File 'lib/bitly/client/connection.rb', line 7

def api_token
  @api_token
end

#api_urlObject

Returns the value of attribute api_url.



8
9
10
# File 'lib/bitly/client/connection.rb', line 8

def api_url
  @api_url
end

#long_urlObject

Returns the value of attribute long_url.



9
10
11
# File 'lib/bitly/client/connection.rb', line 9

def long_url
  @long_url
end

Instance Method Details

#shortenObject



17
18
19
20
21
22
# File 'lib/bitly/client/connection.rb', line 17

def shorten
  @response = HTTParty.post(api_url, headers: headers, body: body)
  if !@response.nil? && @response.success?
    @response["link"]
  end
end