Sha256: 77d5ee1fa0b621350f186adef338116abab0bbd132eacda1bd13f0800e322542

Contents?: true

Size: 546 Bytes

Versions: 3

Compression:

Stored size: 546 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
      )

      raise Whats::Errors::RequestError.new("API request error.", response) if response.failure?

      JSON.parse(response.response_body)
    end

    private

    attr_reader :base_path
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
whatsapp-0.1.4 lib/whats/client.rb
whatsapp-0.1.3 lib/whats/client.rb
whatsapp-0.1.2 lib/whats/client.rb