zacs / ha-gtfs-rt

Real-time transit information for Home Assistant
MIT License
69 stars 29 forks source link

[BREAKING CHANGE] Add support for custom authorization headers #25

Closed rafaelmagu closed 11 months ago

rafaelmagu commented 1 year ago

In order to support Auckland Transport's API, I need to set a custom authorization header name of Ocp-Apim-Subscription-Key.

Breaking Changes This PR intentionally removes the apikey and x_api_key parameters in favour of a simpler api_key/header_name approach. Merging this PR will break existing setups (potentially), so I'm leaving this to the repo maintainer's discretion.

zacs commented 1 year ago

Apologies for not reviewing this yet. I do like your generic approach much more. It seems like most of the forks are addressing this onesy twosy so might as well be flexible. Will put together some release notes. Would you mind writing up an example of "if this was your old config, here's how it would look now"?

rafaelmagu commented 1 year ago

@zacs to draw on the examples from the README:


Assuming this is your current config:

- platform: gtfs_rt
  trip_update_url: 'https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-bdfm'
  x_api_key: <api key>
  departures:
    - name: "Brooklyn F"
      route: 'F'
      stopid: 'F16S'

After this update, it needs to be updated to:

- platform: gtfs_rt
  trip_update_url: 'https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-bdfm'
  api_key: <api key>       # <- Note key name change here
  header_name: 'X-Api-Key' # <- Add a specific header name
  departures:
    - name: "Brooklyn F"
      route: 'F'
      stopid: 'F16S'
zacs commented 1 year ago

Thanks! I will cut the release and include these notes. 🙌

rafaelmagu commented 1 year ago

@zacs is there anything I can do to help merge this?

CDeLeon94 commented 11 months ago

This would be helpful for Portland Oregon's Trimet as well, requiring an 'appID' header.

zacs commented 11 months ago

Thanks for the reminder here. I just merged #30 which adds support for custom headers without hard-coding in the specific headers themselves. I went with that one since it's non-breaking and long-term more flexible. @rafaelmagu and @CDeLeon94 would you mind trying it out now? Thanks!

isewise commented 8 months ago

This would be helpful for Portland Oregon's Trimet as well, requiring an 'appID' header.

Could you provide your config for as an example for Trimet? I'm in Lake Oswego and I'm trying to set this integration up for at least one stop.

Thanks in advance

CDeLeon94 commented 7 months ago

This would be helpful for Portland Oregon's Trimet as well, requiring an 'appID' header.

Could you provide your config for as an example for Trimet? I'm in Lake Oswego and I'm trying to set this integration up for at least one stop.

Thanks in advance

https://github.com/CDeLeon94/GTFS-V2-Home-Assistant

This was my solution, still working in my system

isewise commented 7 months ago

This would be helpful for Portland Oregon's Trimet as well, requiring an 'appID' header.

Could you provide your config for as an example for Trimet? I'm in Lake Oswego and I'm trying to set this integration up for at least one stop.

Thanks in advance

https://github.com/CDeLeon94/GTFS-V2-Home-Assistant

This was my solution, still working in my system

Thanks for the response. In the meantime between my original comment and your response I came up with my own solution. I'm just invoking a python script against an endpoint and applying some filtering for the routes and buses I'm interested in.

Maybe I'll revisit this integration in the future. As of right now my solution works for me.

Thanks again for the response.