Sha256: d500b5c257ed92f1a093ec0fab495393b36b12991c5858c20f2f6d9ac0d402b3

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "uri"
require "net/http"
require "json"

require_relative "configuration"
require_relative "request"
require_relative "response"
require_relative "resources"
require_relative "util"

module Monday
  # Client executes requests against the Monday.com API and
  # allows a user to mutate and retrieve resources.
  class Client
    include Resources

    JSON_CONTENT_TYPE = "application/json"
    private_constant :JSON_CONTENT_TYPE

    Monday::Configuration::CONFIGURATION_FIELDS.each do |config_key|
      define_method(config_key) do
        @config.public_send(config_key)
      end
    end

    def initialize(config_args = {})
      @config = Monday::Configuration.new(**config_args)
      yield(@config) if block_given?
    end

    private

    def uri
      URI(@config.host)
    end

    def request_headers
      {
        "Content-Type": "application/json",
        Authorization: @config.token
      }
    end

    def make_request(body)
      response = Monday::Request.post(uri, body, request_headers)
      Monday::Response.new(response)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
monday_ruby-0.1.0 lib/monday/client.rb