Class: Whats::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/whats/api.rb

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



9
10
11
# File 'lib/whats/api.rb', line 9

def initialize
  @base_path = Whats.configuration.base_path
end

Instance Method Details

#check_contact(number) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/whats/api.rb', line 17

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

#check_contacts(numbers) ⇒ Object



13
14
15
# File 'lib/whats/api.rb', line 13

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

#send_hsm_message(username, namespace, element_name, language, params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/whats/api.rb', line 36

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

#send_message(username, body) ⇒ Object



32
33
34
# File 'lib/whats/api.rb', line 32

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