class Bitly::Client::Connection
Attributes
api_token[RW]
api_url[RW]
long_url[RW]
Public Class Methods
new(long_url, api_token = nil, api_url = nil)
click to toggle source
# 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
Public Instance Methods
shorten()
click to toggle source
# 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
Private Instance Methods
body()
click to toggle source
# File lib/bitly/client/connection.rb, line 26 def body { long_url: long_url }.to_json end
headers()
click to toggle source
# File lib/bitly/client/connection.rb, line 32 def headers { "Content-Type" => "application/json", "Authorization" => "Bearer #{api_token}" } end