Sha256: 9428b7a3c8713d64cf742439b64e383ba54ccc48426619115eef3d5300b9d109

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require "whats/actions/check_contacts"
require "whats/actions/send_message"
require "whats/actions/send_hsm_message"

module Whats
  class Api
    def initialize
      @base_path = Whats.configuration.base_path
    end

    def check_contacts(numbers)
      Actions::CheckContacts.new(client, numbers).call
    end

    def check_contact(number)
      response = check_contacts([number])

      if response["errors"]
        raise Whats::Errors::RequestError.new("WhatsApp error.", response)
      end

      result = \
        response["contacts"].reduce({}) do |temp, hash|
          temp.merge(hash["input"] => hash)
        end

      result[number]
    end

    def send_message(username, body)
      Actions::SendMessage.new(client, username, body).call
    end

    def send_hsm_message(username, namespace, element_name, params)
      Actions::SendHsmMessage.new(
        client,
        username,
        namespace,
        element_name,
        params
      ).call
    end

    private

    attr_reader :base_path

    def client
      @client ||= Whats::Client.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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