Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openstates v3 upgrade #41

Merged
merged 10 commits into from
Dec 9, 2021
Merged

Openstates v3 upgrade #41

merged 10 commits into from
Dec 9, 2021

Conversation

wtcruft
Copy link
Collaborator

@wtcruft wtcruft commented Oct 4, 2021

Openstates v1 is expiring, and the Sunlight foundation (through which we previously accessed v1) has sunsetted.

This may also take care of issue #15.

data: {
apikey: CallPower.Config.SUNLIGHT_API_KEY,
apikey: CallPower.Config.OPENSTATES_API_KEY,
state: campaign_state,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To work with the v3 api it looks like some of these params need to change

state -- became jurisdiction

last_name -- became just name

in_office -- seems to not be supported at all anymore

chamber -- became org_classification and should be one of "legislature", "executive", "lower", "upper", or "government"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down below in the renderSearchResults function, some translation is also needed to hook the v3 api response up to the template in call_server/templates/campaign/form.html:167, which still expects the v1 attributes. This worked for me:

         } else if (person.title === 'Governor') {
           person.uid = 'us_state:governor:'+person.state
         }
 
+        if (person.given_name) {
+          person.first_name = person.given_name;
+          person.last_name = person.family_name;
+          person.title = person.current_role.title;
+          person.state = person.jurisdiction.name;
+        }
+
         // if person has multiple phones, use only the first office
         if (person.phone === undefined && person.offices) {
           if (person.offices) {
-            person.phone = person.offices[0].phone;
+            person.phone = person.offices[0].voice;
           }

@@ -54,9 +54,6 @@
<script>
window.CallPower = {
Config: {
SUNLIGHT_API_KEY: "{{SUNLIGHT_API_KEY}}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the front end to work we need to replace this config with the values for openstates.

{
  OPENSTATES_URL: "https://v3.openstates.org/people?include=offices", // need offices in the response to get phone number
  OPENSTATES_API_KEY: "..." // get from app config
}

@wioux
Copy link
Member

wioux commented Dec 8, 2021

The backend changes all look good to me. I noticed that custom target search in the campaign form no longer works, and noted some changes that at least make it render correctly for me. I'm not certain anyone actually uses this feature though, as it's also broken in prod due to loading mixed http/https content. It'd be fine with me to push ahead with the backend upgrades here and either circle back to the target search or just remove that part of the form.

Screenshot from 2021-12-08 15-42-33

@wtcruft wtcruft merged commit 397e32e into master Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants