Class: Fourjawaly::SMSGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/fourjawaly/sms_gateway.rb

Constant Summary collapse

BASE_URL =
'https://api-sms.4jawaly.com/api/v1/'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, sender) ⇒ SMSGateway

Returns a new instance of SMSGateway.



9
10
11
12
13
14
# File 'lib/fourjawaly/sms_gateway.rb', line 9

def initialize(api_key, api_secret, sender)
  @api_key = api_key
  @sender = sender
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = true
end

Instance Method Details

#get_balance(is_active: nil, order_by: nil, order_by_type: nil) ⇒ Hash

Get account balance and package information

Parameters:

  • is_active (Integer) (defaults to: nil)

    Filter by active packages (0 or 1)

  • order_by (String) (defaults to: nil)

    Sort field

  • order_by_type (String) (defaults to: nil)

    Sort direction (asc or desc)

Returns:

  • (Hash)

    Balance information and packages



40
41
42
43
44
45
46
47
# File 'lib/fourjawaly/sms_gateway.rb', line 40

def get_balance(is_active: nil, order_by: nil, order_by_type: nil)
  params = {}
  params[:is_active] = is_active unless is_active.nil?
  params[:order_by] = order_by if order_by
  params[:order_by_type] = order_by_type if order_by_type

  get_request('balance', params)
end

#send_sms(numbers, message, sender = nil) ⇒ Hash

Send SMS to one or multiple recipients

Parameters:

  • numbers (Array<String>)

    List of phone numbers

  • message (String)

    Message content

  • sender (String) (defaults to: nil)

    Optional sender name (if different from default)

Returns:

  • (Hash)

    API response containing status and job IDs



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fourjawaly/sms_gateway.rb', line 22

def send_sms(numbers, message, sender = nil)
  numbers = [numbers] unless numbers.is_a?(Array)
  
  payload = {
    numbers: numbers,
    message: message,
    sender: sender || @sender
  }

  post_request('send', payload)
end