Skip to content

Commit

Permalink
Convert path only uris to include the host and scheme
Browse files Browse the repository at this point in the history
+ Forces every request to use the api_base path
  • Loading branch information
danielwestendorf committed Sep 21, 2023
1 parent 3a4a910 commit ff6f842
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/hoalife/client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ def response
@response ||= validate_response!
end

def uri
@uri ||= URI::HTTPS.build(host: base_uri.host, path: request_uri.path, query: request_uri.query)
end

private

def request!
raise 'Not implemented'
end

def uri
@uri ||= URI(@url)
def request_uri
@request_uri ||= URI(@url)
end

def base_uri
@base_uri ||= URI(HOALife.api_base)
end

def request_headers
Expand Down
9 changes: 9 additions & 0 deletions test/hoalife/client/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Client::BaseTest < HOALifeBaseTest

def setup
HOALife.config do |c|
c.api_base = "https://example.com/foo"
c.api_key = API_KEY
c.signing_secret = SIGNING_SECRET
c.api_version = API_VERSION
Expand Down Expand Up @@ -191,5 +192,13 @@ def test_response
assert_equal response, instance.response
end
end

def test_uri_with_url
assert_equal 'https://example.com/foo?name=bar', HOALife::Client::Base.new('https://example.com/foo?name=bar').uri.to_s
end

def test_uri_with_path
assert_equal 'https://example.com/foo?name=bar', HOALife::Client::Base.new('/foo?name=bar').uri.to_s
end
end
end
1 change: 1 addition & 0 deletions test/hoalife/client/delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class HOALife::Client::DeleteTest < HOALifeBaseTest
def setup
HOALife.config do |cfg|
cfg.api_base = 'https://example.com/foo'
cfg.api_key = 'foo'
cfg.signing_secret = nil
end
Expand Down
1 change: 1 addition & 0 deletions test/hoalife/client/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class HOALife::Client::PostTest < HOALifeBaseTest
def setup
HOALife.config do |cfg|
cfg.api_base = 'https://example.com/foo'
cfg.api_key = 'foo'
cfg.signing_secret = nil
end
Expand Down
1 change: 1 addition & 0 deletions test/hoalife/client/put_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class HOALife::Client::PutTest < HOALifeBaseTest
def setup
HOALife.config do |cfg|
cfg.api_base = 'https://example.com/foo'
cfg.api_key = 'foo'
cfg.signing_secret = nil
end
Expand Down

0 comments on commit ff6f842

Please sign in to comment.