Class: Kirimi::Client

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

Constant Summary collapse

DEFAULT_BASE_URL =
'https://api.kirimi.id'
DEFAULT_TIMEOUT =
30

Instance Method Summary collapse

Constructor Details

#initialize(user_code:, secret:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
# File 'lib/kirimi/client.rb', line 12

def initialize(user_code:, secret:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT)
  @user_code = user_code
  @secret    = secret
  @base_url  = base_url.chomp('/')
  @timeout   = timeout
end

Instance Method Details

#broadcast_message(device_id:, phones:, message:, delay: nil) ⇒ Object

— Broadcast —



114
115
116
117
118
119
# File 'lib/kirimi/client.rb', line 114

def broadcast_message(device_id:, phones:, message:, delay: nil)
  phones_str = phones.is_a?(Array) ? phones.join(',') : phones
  body = { device_id: device_id, phones: phones_str, message: message }
  body[:delay] = delay if delay
  post('/v1/broadcast-message', body)
end

#device_status(device_id:) ⇒ Object



60
61
62
# File 'lib/kirimi/client.rb', line 60

def device_status(device_id:)
  post('/v1/device-status', { device_id: device_id })
end

#device_status_enhanced(device_id:) ⇒ Object



64
65
66
# File 'lib/kirimi/client.rb', line 64

def device_status_enhanced(device_id:)
  post('/v1/device-status-enhanced', { device_id: device_id })
end

#generate_otp(device_id:, phone:, otp_length: nil, otp_type: nil, custom_otp_message: nil) ⇒ Object

— OTP —



85
86
87
88
89
90
91
# File 'lib/kirimi/client.rb', line 85

def generate_otp(device_id:, phone:, otp_length: nil, otp_type: nil, custom_otp_message: nil)
  body = { device_id: device_id, phone: phone }
  body[:otp_length]       = otp_length        if otp_length
  body[:otp_type]         = otp_type           if otp_type
  body[:customOtpMessage] = custom_otp_message if custom_otp_message
  post('/v1/generate-otp', body)
end

#list_deposits(status: nil) ⇒ Object

— Deposits —



123
124
125
126
127
# File 'lib/kirimi/client.rb', line 123

def list_deposits(status: nil)
  body = {}
  body[:status] = status if status
  post('/v1/list-deposits', body)
end

#list_devicesObject

— Devices —



56
57
58
# File 'lib/kirimi/client.rb', line 56

def list_devices
  post('/v1/list-devices', {})
end

#list_packagesObject



129
130
131
# File 'lib/kirimi/client.rb', line 129

def list_packages
  post('/v1/list-packages', {})
end

#save_contact(phone:, name: nil, email: nil) ⇒ Object

— Contacts —



76
77
78
79
80
81
# File 'lib/kirimi/client.rb', line 76

def save_contact(phone:, name: nil, email: nil)
  body = { phone: phone }
  body[:name]  = name  if name
  body[:email] = email if email
  post('/v1/save-contact', body)
end

#send_message(device_id:, phone:, message:, media_url: nil) ⇒ Object

— WhatsApp Unofficial —



21
22
23
24
25
# File 'lib/kirimi/client.rb', line 21

def send_message(device_id:, phone:, message:, media_url: nil)
  body = { device_id: device_id, phone: phone, message: message }
  body[:media_url] = media_url if media_url
  post('/v1/send-message', body)
end

#send_message_fast(device_id:, phone:, message:, media_url: nil) ⇒ Object



42
43
44
45
46
# File 'lib/kirimi/client.rb', line 42

def send_message_fast(device_id:, phone:, message:, media_url: nil)
  body = { device_id: device_id, phone: phone, message: message }
  body[:media_url] = media_url if media_url
  post('/v1/send-message-fast', body)
end

#send_message_file(device_id:, phone:, file:, file_name:, message: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kirimi/client.rb', line 27

def send_message_file(device_id:, phone:, file:, file_name:, message: nil)
  file_io = file.is_a?(String) ? File.open(file, 'rb') : file
  fields = {
    'user_code' => @user_code,
    'secret'    => @secret,
    'device_id' => device_id,
    'phone'     => phone,
    'fileName'  => file_name
  }
  fields['message'] = message if message
  post_multipart('/v1/send-message-file', fields, file_io, file_name)
ensure
  file_io&.close if file.is_a?(String)
end

#send_otp_v2(phone:, device_id:, method: nil, app_name: nil, template_code: nil, custom_message: nil) ⇒ Object

— OTP V2 —



99
100
101
102
103
104
105
106
# File 'lib/kirimi/client.rb', line 99

def send_otp_v2(phone:, device_id:, method: nil, app_name: nil, template_code: nil, custom_message: nil)
  body = { phone: phone, device_id: device_id }
  body[:method]        = method        if method
  body[:app_name]      = app_name      if app_name
  body[:template_code] = template_code if template_code
  body[:custom_message] = custom_message if custom_message
  post('/v2/otp/send', body)
end

#send_waba_message(device_id:, phone:, message:) ⇒ Object

— WABA —



50
51
52
# File 'lib/kirimi/client.rb', line 50

def send_waba_message(device_id:, phone:, message:)
  post('/v1/waba/send-message', { device_id: device_id, phone: phone, message: message })
end

#user_infoObject

— User —



70
71
72
# File 'lib/kirimi/client.rb', line 70

def 
  post('/v1/user-info', {})
end

#validate_otp(device_id:, phone:, otp:) ⇒ Object



93
94
95
# File 'lib/kirimi/client.rb', line 93

def validate_otp(device_id:, phone:, otp:)
  post('/v1/validate-otp', { device_id: device_id, phone: phone, otp: otp })
end

#verify_otp_v2(phone:, otp_code:) ⇒ Object



108
109
110
# File 'lib/kirimi/client.rb', line 108

def verify_otp_v2(phone:, otp_code:)
  post('/v2/otp/verify', { phone: phone, otp_code: otp_code })
end