Created
May 12, 2020 03:13
-
-
Save jackcallister/f649e183619873031c36b9b2a23c3b36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EMI::ICPConnectionDataClient.new.find(id) | |
module EMI | |
class ICPConnectionDataClient | |
include HTTParty | |
class ICP < OpenStruct; end; | |
base_uri 'https://emi.azure-api.net/ICPConnectionData' | |
def find id | |
response = self.class.get "/single?id=#{id}", | |
headers: { 'Ocp-Apim-Subscription-Key': api_key: "XXXXXXXXXX" }, | |
timeout: 5, | |
format: :json | |
clean(response.parsed_response[0]) | |
end | |
private | |
def clean icp | |
metering = icp.dig('Metering', 'InstallationInformation').try(:map, &method(:clean_meter_config)) | |
ICP.new\ | |
id: icp['ICPIdentifier'], | |
trader: icp.dig('Trader', 'Trader'), | |
smart_meter_enabled: metering.nil? ? false : metering.flatten.select{ |m| m[:ami_flag] } | |
.map{ |m| m[:type] }.include?("HHR"), | |
end | |
def clean_meter_config meter | |
meter['ComponentInformation'].try(:map) do |component| | |
{ | |
type: component['MeterType'], | |
ami_flag: component['AMIFlag'] | |
} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment