kyledecot / app_store_connect

A Ruby interface to the App Store Connect API
https://rubygems.org/gems/app_store_connect
MIT License
54 stars 28 forks source link

Every request results in an exception #214

Open kassi opened 6 months ago

kassi commented 6 months ago

Describe the bug Followed the README.md

AppStoreConnect.config = {
          issuer_id: ENV["XCC_ISSUER_ID"],
          key_id: ENV["XCC_PRIVATE_KEY_ID"],
          private_key: ENV["XCC_PRIVATE_KEY"]
        }
client = AppStoreConnect::Client.new
pp client.apps

and of course filled in env variables. The call (and every other method I call on client) results in

/Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http/generic_request.rb:17:in `initialize': not an HTTP URI (ArgumentError)

      raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http/request.rb:38:in `initialize'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/request.rb:89:in `new'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/request.rb:89:in `request'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/request.rb:20:in `block in execute'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1238:in `start'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:687:in `start'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/request.rb:19:in `execute'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/base.rb:40:in `call'
    from /Users/Kassi/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/app_store_connect-0.38.0/lib/app_store_connect/base.rb:20:in `method_missing'

Expected behavior Code should list all apps and not break.

Desktop (please complete the following information):

Additional context I tried to debug until generic_request.rb and the uri that is passed is an instance of URI::Generic. I added the following into generic_request.rb at line 17:

pp uri_or_path
pp uri_or_path === URI::Generic
pp uri_or_path === URI::HTTP
pp uri_or_path === URI::HTTPS

and the result is

#<URI::Generic https://api.appstoreconnect.apple.com/v1/apps?>
false
false
false

which is somehow strange and I wonder how this will ever work.

I appreciate every clue on what's going on here.

JohnReeze commented 5 months ago

I've got the same issue. Crashes here

 Net::HTTP.start(uri.host, uri.port, net_http_options) do |http

As I see it, the problem is that uri.host == api.appstoreconnect.apple.com which may relate to absence of http// like here https://stackoverflow.com/questions/67367905/not-an-http-uri
But if I change this line to a valid https://api.appstoreconnect.apple.com string it still crashes with Failed to open TCP connection to https://api.appstoreconnect.apple.com/v1/apps: (getaddrinfo: nodename nor servname provided, or not known) so I guess it's more complicated error than I described)

kyledecot commented 5 months ago

👋 Thanks for reporting this. I was able to reproduce this using 0.38.0 from rubygems.org. It seems to be working as expected when using git main:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'app_store_connect', github: 'kyledecot/app_store_connect@main'
end

require 'app_store_connect'

AppStoreConnect.config = {
  issuer_id: ENV["XCC_ISSUER_ID"],
  key_id: ENV["XCC_PRIVATE_KEY_ID"],
  private_key: ENV["XCC_PRIVATE_KEY"]
}

client = AppStoreConnect::Client.new

pp client.apps

Let me know if this fixes your issue and if so I'll release a new version of the gem.

JohnReeze commented 5 months ago

Specified in Gemfile and updated, but still facing same issue.

Screenshot 2024-06-10 at 13 22 48