Class: FreshchatWhatsapp::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/freshchat_whatsapp/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_path = nil, token = nil, token_type = :bearer) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
# File 'lib/freshchat_whatsapp/client.rb', line 5

def initialize(base_path=nil, token=nil, token_type = :bearer)
  @base_path = base_path ||  FreshchatWhatsapp.configuration.base_path
  @token = token || FreshchatWhatsapp.configuration.api_key
  @token_type = token_type
end

Instance Method Details

#get_request(path, payload = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/freshchat_whatsapp/client.rb', line 18

def get_request(path, payload = nil)
  full_path = "#{base_path}#{path}"
  conn = Faraday.new(url: full_path, headers: headers)
  response = conn.get { |request| request.body = body(payload) }
  JSON.parse(response.body)
end

#request(path, payload = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/freshchat_whatsapp/client.rb', line 11

def request(path, payload = nil)
  full_path = "#{base_path}#{path}"
  conn = Faraday.new(url: full_path, headers: headers)
  response = conn.post { |request| request.body = body(payload) }
  JSON.parse(response.body)
end