diff --git a/spec/thunderstore/methods/package_spec.cr b/spec/thunderstore/methods/package_spec.cr index e7c5ed6..8d8ac7e 100644 --- a/spec/thunderstore/methods/package_spec.cr +++ b/spec/thunderstore/methods/package_spec.cr @@ -4,7 +4,7 @@ describe Thunderstore::Package do context "valheim" do describe ".list_packages" do it "retrieves all packages" do - WebMock.stub(:get, "https://valheim.thunderstore.io/api/v1/package/") + WebMock.stub(:get, "https://thunderstore.io/api/v1/package/") .to_return(status: 200, body: File.read("spec/support/All_Packages-1650682645115.json"), headers: {"Content-Type" => "application/json"}) client = Thunderstore::Client.new("valheim") diff --git a/src/thunderstore/client.cr b/src/thunderstore/client.cr index d6998a1..d11b49c 100644 --- a/src/thunderstore/client.cr +++ b/src/thunderstore/client.cr @@ -2,6 +2,8 @@ module Thunderstore class Client property community = "" + BASE_URL = "https://thunderstore.io" + def initialize(@community : String = "") end @@ -14,9 +16,9 @@ module Thunderstore # Returns the base url for which this client will make API requests to. def base_url : URI - return URI.parse("https://thunderstore.io") if community.empty? + return URI.parse(BASE_URL) if community.empty? - URI.parse("https://#{community}.thunderstore.io") + URI.parse("#{BASE_URL}/c/#{community}") end # Initializes an `HTTP::Client` for the configured `base_url`, and executes a GET request on the specified `path`.