Sha256: d8ce9952be661516ed7d5aba72758a5849c0a3facbdcec94d0475608448a3e7c
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true require "net/http" require "json" module Mergent class Client def self.post(resource, params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength uri = URI("https://api.mergent.co/v1/#{resource}") headers = { Authorization: "Bearer #{Mergent.api_key}", "Content-Type": "application/json" } request = Net::HTTP::Post.new(uri, headers) request.body = params.to_json https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true response = https.request(request) case response when Net::HTTPSuccess JSON.parse(response.read_body, object_class: Mergent::Object) else begin body = JSON.parse(response.read_body) rescue JSON::ParserError body = {} end raise Mergent::Error, body["message"] end rescue EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError raise Mergent::ConnectionError end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mergent-0.1.1 | lib/mergent/client.rb |