Sha256: 878dad4e8e51f426e128a27f9e4cf3c135af5791d09675378c622e759b6077a8

Contents?: true

Size: 722 Bytes

Versions: 1

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

require "whats/actions/login"

module Whats
  class Client
    def initialize(login = Whats::Actions::Login.new)
      @base_path = Whats.configuration.base_path
      @login = login
    end

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

      response = Typhoeus.post(
        full_path,
        headers: {
          "Authorization" => "Bearer #{login.token}",
          "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, :login
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whatsapp-0.1.5 lib/whats/client.rb