philnash / bitly

🗜 A Ruby wrapper for the bit.ly API
https://rubygems.org/gems/bitly
MIT License
451 stars 139 forks source link

404 Not found while executing client.expand #80

Closed luilver closed 1 year ago

luilver commented 2 years ago

Following the README when I try to client.expand I get a 404.

This is my code:

require 'bitly'
token = '«myTokenHere»'
client = Bitly::API::Client.new(token: token)
bitlink = client.expand(bitlink: "https://bit.ly/«myShortCode»")
p bitlink.long_url

This is my env:

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

$ gem list | grep bitly
bitly (2.0.1)

This is the pry-ed output ( :

$ ruby bitly.rb

From: /home/luilver/.rvm/gems/ruby-2.7.1/gems/bitly-2.0.1/lib/bitly/api/client.rb:58 Bitly::API::Client#request:

    52: def request(path:, method: 'GET', params: {}, headers: {})
    53:   params = params.select { |k,v| !v.nil? }
    54:   headers = default_headers.merge(headers)
    55:   uri = Bitly::API::BASE_URL.dup
    56:   uri.path += path
    57:   request = Bitly::HTTP::Request.new(uri: uri, method: method, params: params, headers: headers)
 => 58:   binding.pry
    59:   @http.request(request)
    60: end

[1] pry(#<Bitly::API::Client>)> @http.request(request)
Bitly::Error: [404] NOT_FOUND
from /home/luilver/.rvm/gems/ruby-2.7.1/gems/bitly-2.0.1/lib/bitly/http/client.rb:28:in `request'
[2] pry(#<Bitly::API::Client>)> uri
=> #<URI::HTTPS https://api-ssl.bitly.com/v4/expand>
[3] pry(#<Bitly::API::Client>)>
luilver commented 2 years ago

I found the problem is the included protocol within bitlink. Removing https:// fixed it.