Sha256: e03ef1019ffa645edfc6bc55ac1682b118c26cf89b3ac577ca7e33fb0665ebec
Contents?: true
Size: 1.13 KB
Versions: 13
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true require 'json' require 'net/http' require_relative 'api_client/query' require_relative 'api_client/control' require_relative 'api_client/settings' require_relative 'api_client/api_object' module Renstar # The actual client that handles getting, posting, and parsing API responses # module APIClient def get(endpoint) uri = URI(location + endpoint) response = Net::HTTP.get(uri) JSON.parse(response) end def post(endpoint, options = {}) uri = URI(location + endpoint) response = Net::HTTP.post_form(uri, options) JSON.parse(response.body) end include Query include Control include Settings @api_ref = JSON.parse(File.read(File.join(__dir__, './api_client/api.json'))) def self.key_to_description(type, key) @api_ref.dig(type, key, 'description') || key end def self.value_to_formatted(type, key, value) case @api_ref.dig(type, key, 'values') when 'raw' value when 'epoch' Time.at(value) else @api_ref.dig(type, key, 'values', value.to_s) || value end end end end
Version data entries
13 entries across 13 versions & 1 rubygems