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

Add person memberships class #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ondenman
Copy link
Contributor

@ondenman ondenman commented Mar 17, 2017

In addition to the membership profile:
screen shot 2017-03-17 at 15 29 58

…members have a list of memberships reached via the 'Todas las legislaturas' link.

screen shot 2017-03-17 at 15 31 15

PersonMemberships returns a collection of MembershipRow objects. Each of these contains the legislature id, url and name of deputy. The url points to a separate profile page for each of the memberships. (That is, if a member has sat it terms 9,10, and 11, there will be a separate profile page for the member for these three terms.)

@ondenman ondenman force-pushed the add-person-memberships-class branch 5 times, most recently from d8b5e9f to 0f0c020 Compare March 17, 2017 18:13
let(:profile_page_response) { open(profile_url) }
let(:cookie) { Cookie.new(profile_page_response.meta['set-cookie'])}
# We can now send a request to the memberships page with correct cookie.
let(:header){ { 'Cookie' => cookie.to_s } }
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need the Cookie class at all. You can just pass the cookie back exactly as you received it:

let(:header){ { 'Cookie' => profile_page_response.meta['set-cookie'] } }

However in my experimenting it seemed that there wasn't always a cookie in the response, so we should probably only be sending this when there's a cookie in the response.

Here's the script I've been using to experiment with the cookies that are being returned:

require 'open-uri'

def error?(res)
  if res.read.include?('missing string: error')
    warn "! Error"
  else
    warn "OK"
  end
end

memberships_url = 'http://www.congreso.es/portal/page/portal/Congreso/Congreso/Diputados/BusqForm?next_page=/wc/listadoFichas?idDiputado=338&idLegislatura=12'

warn "Requesting member page"
membership_page = open('http://www.congreso.es/portal/page/portal/Congreso/Congreso/Diputados/BusqForm?next_page=/wc/fichaDiputado?idDiputado=338&idLegislatura=12')

if membership_page.meta['set-cookie'].to_s.empty?
  warn "No Set-Cookie response header from membership page"
  warn "Requesting person memberships without Cookie"
  res = open(memberships_url)
  error?(res)
else
  warn "Requesting person memberships with Cookie"
  res = open(memberships_url, 'Cookie' => membership_page.meta['set-cookie'])
  error?(res)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'd somehow convinced myself that it wouldn't work. Works every time!

@ondenman ondenman force-pushed the add-person-memberships-class branch 4 times, most recently from c197b9d to 6d34f72 Compare March 21, 2017 11:27
@ondenman ondenman changed the title WIP: Add person memberships class Add person memberships class Mar 21, 2017
@ondenman ondenman requested a review from tmtmtmtm March 21, 2017 11:30
@ondenman ondenman force-pushed the add-person-memberships-class branch 2 times, most recently from 39433af to ed44549 Compare March 21, 2017 11:40
@ondenman ondenman assigned tmtmtmtm and unassigned tmtmtmtm Mar 21, 2017
@ondenman ondenman changed the title Add person memberships class WIP: Add person memberships class Mar 21, 2017
@ondenman ondenman force-pushed the add-person-memberships-class branch 3 times, most recently from d0e8f54 to b836de2 Compare March 21, 2017 15:38
@ondenman ondenman assigned tmtmtmtm and unassigned tmtmtmtm Mar 21, 2017
@ondenman ondenman changed the title WIP: Add person memberships class Add person memberships class Mar 21, 2017
@ondenman ondenman assigned tmtmtmtm and unassigned tmtmtmtm Mar 21, 2017
@ondenman ondenman changed the title Add person memberships class WIP: Add person memberships class Mar 21, 2017
@ondenman ondenman force-pushed the add-person-memberships-class branch from 15469a7 to 9f40ca4 Compare March 21, 2017 16:41
Oliver Denman added 4 commits April 19, 2017 15:41
Represent a single row on the page that lists all memberships of a person
:memberships returns a fragment MembershipRow fragment for each listed membership.
The latest version allows custom headers to be added to requests
Tests that correct number of memberships is captured and membership row contains expected data.
@ondenman ondenman force-pushed the add-person-memberships-class branch from 9f40ca4 to b577c5a Compare April 19, 2017 14:55
@ondenman ondenman requested a review from chrismytton April 19, 2017 17:18
@ondenman ondenman changed the title WIP: Add person memberships class Add person memberships class Apr 19, 2017
@chrismytton chrismytton removed their assignment Nov 27, 2017
@chrismytton chrismytton removed their request for review September 24, 2018 10:09
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.

3 participants