|
|
|
|
|
3class RefreshConstituencyPartyJob < ApplicationJob
|
|
4 HOST = "http://data.parliament.uk"
|
|
5 ENDPOINT = "/membersdataplatform/services/mnis/members/query/House=Commons%7CIsEligible=true/"
|
|
|
|
|
|
8 MEMBERS = "//Members/Member"
|
|
|
|
10 MP_NAME = "./FullTitle"
|
|
|
|
|
|
13 rescue_from StandardError do |exception|
|
|
14 Appsignal.send_exception exception
|
|
|
|
|
- FeatureEnvy - refers to 'constituency' more than self (maybe move it to another class?) » reek
- Complexity 3 » saikuro
|
|
|
18 Constituency.find_each do |constituency|
|
- Found = in conditional. It should probably be an == » roodi
|
19 if member = members[constituency.mp_id]
|
|
20 constituency.update!(party: member[:party])
|
|
|
|
22 constituency.update!(mp_id: nil, mp_name: nil, mp_date: nil, party: nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 @members ||= load_members
|
|
|
|
|
- TooManyStatements - has approx 6 statements » reek
- UncommunicativeVariableName - has the variable name 'e' » reek
- Complexity 3 » saikuro
|
|
|
34 response = fetch_members
|
|
|
|
|
|
37 Hash[parse(response.body)]
|
|
|
|
|
|
|
|
41 rescue Faraday::Error => e
|
|
42 Appsignal.send_exception(e)
|
|
|
|
|
|
|
- DuplicateMethodCall - calls 'node.xpath(MP_ID)' 2 times » reek
- DuplicateMethodCall - calls 'node.xpath(MP_ID).text' 2 times » reek
- TooManyStatements - has approx 6 statements » reek
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 3 » saikuro
|
|
|
47 xml = Nokogiri::XML(body)
|
|
|
|
49 xml.xpath(MEMBERS).map do |node|
|
|
|
|
51 node.xpath(MP_ID).text,
|
|
|
|
53 attrs[:id] = node.xpath(MP_ID).text
|
|
54 attrs[:name] = node.xpath(MP_NAME).text
|
|
55 attrs[:party] = node.xpath(MP_PARTY).text
|
|
|
|
|
|
|
|
|
|
|
- UncommunicativeVariableName - has the variable name 'f' » reek
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 2 » saikuro
|
|
|
62 Faraday.new(HOST) do |f|
|
|
63 f.response :follow_redirects
|
|
64 f.response :raise_error
|
|
65 f.adapter :net_http_persistent
|
|
|
|
|
|
|
- DuplicateMethodCall - calls 'request.options' 2 times » reek
- FeatureEnvy - refers to 'request' more than self (maybe move it to another class?) » reek
- Complexity 2 » saikuro
|
|
|
70 faraday.get(ENDPOINT) do |request|
|
|
71 request.options[:timeout] = TIMEOUT
|
|
72 request.options[:open_timeout] = TIMEOUT
|
|
|
|
|
|
|