CityofSantaMonica / mds-provider

Python tools for working with MDS Provider data
https://github.com/openmobilityfoundation/mobility-data-specification
MIT License
18 stars 20 forks source link

Refactor to support API versioning #71

Closed thekaveman closed 5 years ago

thekaveman commented 5 years ago

To support the version header requirements of MDS >= 0.3.0.

Breaking Changes

As part of moving to support versioning of MDS API endpoints, the ProviderClient class has been updated to focus on a single Provider instance at a time. This is a breaking change both in the way clients are initialized, and in the way data is obtained:

Initialization before:

# get the entire provider registry
providers = get_registry(ref="master")

# configure each with custom/private data
providers = [p.configure({ "private": "data" }) for p in providers]

# create a client that tracks all of them
client = ProviderClient(providers=providers)

Initialization now:

# get the single provider instance needed
provider = Provider("ProviderA", config={ "private": "data" }, ref="master")

# create the client for this Provider
client = ProviderClient(provider)

Getting data before:

# list of Provider objects e.g from get_registry()
providers = [ProviderA, ProviderB, ProviderC]

# get status_changes/trips for this list of providers
trips = client.get_trips(providers=providers)

Resulted in

{
  ProviderA: [
    { Payload1 },
    { Payload2 },
  ],
  ProviderB: [
    { Payload1 },
    { Payload2 },
    { Payload3 },
  ],
  ProviderC: [ ... ] 
}

Getting data now:

# single Provider object
provider = Provider("ProviderB")

# get status_changes/trips for this provider
trips = client.get_trips(provider)

Results in

[
  { Payload1 },
  { Payload2 },
  { Payload3 },
]
johnclary commented 5 years ago

👍

thekaveman commented 5 years ago

Rebased on mds-0.3