vol1ura/Sat_9am_5km

View on GitHub
app/services/parkzhrun/client.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Parkzhrun
  class Client
    def self.fetch(resource, param)
      response = ::Client.get(
        "https://parkzhrun.ru/wp-json/api/v1/#{resource}/#{param}",
        'Authorization' => Rails.application.credentials.parkzhrun_auth_key,
      )
      raise "ParkZhrun request failed: #{response.message}" unless response.is_a?(Net::HTTPSuccess)

      JSON.parse(response.body, symbolize_names: true)[resource]
    end
  end
end