Add public_suffix method to allow users to access the PublicSuffix::Domain object easily.
This exposes the PublicSuffix::Domain object so users can interact with that as needed. Plus it provides a consistent interface for Addressable::URI to interact with.
This is useful for accessing subdomains. PublicSuffix's #trd method returns "www.test" from "www.test.example.org".
I'd also like to add subdomain & subdomains methods to Addressable::URI for direct access to subdomains (which I have a follow up Pull Request for if this is accepted).
This exposes the PublicSuffix::Domain object
a bit hesitant about this, sure this object looks simple enough now, but what if it changes down the road? There could be unexpected breaking changes for users of addressable then
Addressable already relies on it, so it would need to be updated for breaking changes as well. It also seems pretty unlikely to change since it only handles parsing domains.
I've been working with a lot of apps that allow custom domains & subdomains and it would be really helpful for Addressable to support parsing those out. I was surprised that wasn't a feature considering it was already using PublicSuffix.
I can merge the subdomain & subdomains feature into this branch if you'd prefer to consider it all together.
Decided to merge the subdomain methods into this PR to show the complete feature.
Addressable already relies on it, so it would need to be updated for breaking changes as well.
Yes, but we own the API, and I think it is a difference in interacting with PublicSuffix to get a basic value (e.g. String) then returning a full PublicSuffix object.
It also seems pretty unlikely to change since it only handles parsing domains.
Yeah, PublicSuffix::Domain probably wont change but let's not take any chances.
What do you think works best? Should we keep the subdomain and subdomains methods and make public_suffix private?
I'm not sold on these additions. I'm feel there's ambiguity around the terms "subdomain" and "subdomains"... this looks a bit different from what publicsuffix-ruby does?
irb(main):006:0> PublicSuffix.parse("www.google.com", ignore_private: true).subdomain
=> "www.google.com"
I'm not sold on these additions. I'm feel there's ambiguity around the terms "subdomain" and "subdomains"... this looks a bit different from what publicsuffix-ruby does?
That was on purpose. I wanted a way to access the subdomains (without the primary domain).
The subdomain method from PublicSuffix doesn't really add any value since it's basically the same as host in Addressable.
@sporkmonger any thoughts on this?