Sha256: c03d402f8ad678288efb40c7b68f59068344facbc7432865e8917026f5e60965

Contents?: true

Size: 568 Bytes

Versions: 2

Compression:

Stored size: 568 Bytes

Contents

# frozen_string_literal: true

module Whats
  class Client
    def initialize(base_path)
      @base_path = base_path
    end

    def request(path, payload)
      full_path = "#{base_path}#{path}"

      response = Typhoeus.post(
        full_path,
        headers: { "Content-Type" => "application/json" },
        body: payload.to_json
      )

      unless response.success?
        raise Whats::Errors::RequestError.new("API request error.", response)
      end

      JSON.parse(response.response_body)
    end

    private

    attr_reader :base_path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whatsapp-0.1.1 lib/whats/client.rb
whatsapp-0.1.0 lib/whats/client.rb