Module: Meteoservice::ParserXml

Includes:
Constants
Included in:
TownsData
Defined in:
lib/meteoservice/parser_xml.rb

Constant Summary

Constants included from Constants

Constants::BASE_URL, Constants::CLOUDINESS, Constants::DAYS_OF_WEEK, Constants::KEYS_DATA, Constants::KEYS_LIMIT, Constants::KEYS_PHENOMENA, Constants::PRECIPITATION, Constants::RPOWER, Constants::SPOWER, Constants::WIND_DIRECTION

Instance Method Summary collapse

Instance Method Details

#connection(path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/meteoservice/parser_xml.rb', line 7

def connection(path)
  connection = Faraday.new(url: BASE_URL) do |faraday|
    faraday.request :xml, content_type: /\bxml$/
    faraday.adapter Faraday.default_adapter
    faraday.response :xml
  end

  response ||= connection.get(path)
rescue Faraday::Error => e
  puts "Ошибка соединения с сервером: #{e.message}"
  abort e.message
else
  begin
    body = response.body
  rescue StandardError => e
    puts e.class.name
    abort e.message
  else
    respond_with_error(response.status, body) unless response.success?
    body
  end
end