Updated

app/models/constituency / api_client.rb

A
39 lines of codes
5 methods
3.6 complexity/method
2 churn
18.04 complexity
0 duplications
require 'faraday' require 'postcode_sanitizer' class Constituency < ActiveRecord::Base class ApiClient
  1. Constituency::ApiClient has no descriptive comment
HOST = 'http://data.parliament.uk' ENDPOINT = '/membersdataplatform/services/mnis/Constituencies/%{postcode}/' TIMEOUT = 5 def call(postcode) faraday.get(path(postcode)) do |request| request.options[:timeout] = TIMEOUT
  1. Constituency::ApiClient#call calls 'request.options' 2 times Locations: 0 1
request.options[:open_timeout] = TIMEOUT
  1. Constituency::ApiClient#call calls 'request.options' 2 times Locations: 0 1
end end private def faraday @faraday ||= Faraday.new(HOST) do |f|
  1. Constituency::ApiClient#faraday has the variable name 'f'
f.response :follow_redirects
  1. Constituency::ApiClient#faraday refers to 'f' more than self (maybe move it to another class?) Locations: 0 1 2
f.response :raise_error
  1. Constituency::ApiClient#faraday refers to 'f' more than self (maybe move it to another class?) Locations: 0 1 2
f.adapter :net_http_persistent
  1. Constituency::ApiClient#faraday refers to 'f' more than self (maybe move it to another class?) Locations: 0 1 2
end end def path(postcode) ENDPOINT % { postcode: escape_path(postcode) } end def escape_path(value) Rack::Utils.escape_path(sanitize(value)) end def sanitize(value)
  1. Constituency::ApiClient#sanitize doesn't depend on instance state (maybe move it to another class?)
PostcodeSanitizer.call(value) end end end