everypolitician / webhook-manager

Notifies other apps whenever EveryPolitician data changes, in style of GitHub's webhooks
https://everypolitician-app-manager.herokuapp.com/
1 stars 2 forks source link

include list of affected legislatures in webhook #67

Closed struan closed 8 years ago

struan commented 8 years ago

The webhook JSON now includes an legislatures_affected key which is an array with a list of $country/$legislature strings for all the legislatures affected by the change

Fixes everypolitician/everypolitician#452

chrismytton commented 8 years ago

The slight problem with this approach is that the $country/$legislature that you're including in the webhook body is actually the path of the legislature within everypolitician-data's data/ directory, not the legislature slug. This makes it harder to lookup a legislature by slug in countries.json.

An example of this being a problem is Wallis and Futuna, which has the following in countries.json:

{
    "name": "Wallis and Futuna",
    "country": "Wallis and Futuna",
    "code": "WF",
    "slug": "Wallis-and-Futuna",
    "legislatures": [
      {
        "name": "Territorial Assembly",
        "slug": "Territorial-Assembly",
        "sources_directory": "data/Wallis_and_Futuna/Territorial_Assembly/sources",
        "popolo": "data/Wallis_and_Futuna/Territorial_Assembly/ep-popolo-v1.0.json",
        "popolo_url": "https://cdn.rawgit.com/everypolitician/everypolitician-data/75b7651/data/Wallis_and_Futuna/Territorial_Assembly/ep-popolo-v1.0.json",
        "names": "data/Wallis_and_Futuna/Territorial_Assembly/names.csv",
        "lastmod": "1465812521",
        "person_count": 20,
        "sha": "75b7651",
        "legislative_periods": [
          {
            "id": "term/2012",
            "name": "2012–",
            "start_date": "2012",
            "slug": "2012",
            "csv": "data/Wallis_and_Futuna/Territorial_Assembly/term-2012.csv",
            "csv_url": "https://cdn.rawgit.com/everypolitician/everypolitician-data/75b7651/data/Wallis_and_Futuna/Territorial_Assembly/term-2012.csv"
          }
        ],
        "statement_count": 470
      }
    ]
  }

In this case the webhook body would contain Wallis_and_Futuna/Territorial_Assembly, but the slug for the country is actually Wallis-and-Futuna and the slug for the legislature is actually Territorial-Assembly. I think there might be some cases where the slug is completely different to the directory path as well.

Perhaps it would be more useful if the webhook body included a data structure for each legislature, rather than just a string?

So something like:

{
  "legislatures_affected": [
    {
      "country_slug": "Wallis-and-Futuna",
      "legislature_slug": "Territorial-Assembly"
    }
  ]
}

This also has the nice side benefit of allowing more information to be added about the changed in the future if we want, e.g. a list of files.

chrismytton commented 8 years ago

A couple of stylistic comments, but the implementation looks solid. 👍