Class: Busibe::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/busibe/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#get, #post

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
# File 'lib/busibe/client.rb', line 13

def initialize(options = {})
  merged_options = Busibe::Jusibe.options.merge(options)

  Configuration::VALID_CONFIG_KEYS.each do |key|
    send("#{key}=", merged_options[key])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &_block) ⇒ Object (private)



50
51
52
53
54
# File 'lib/busibe/client.rb', line 50

def method_missing(method_sym, *args, &_block)
  result = method_sym.to_s =~ /^(.*)_with_response$/
  super unless result
  send($1, *args).get_response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/busibe/client.rb', line 11

def response
  @response
end

Instance Method Details

#check_available_creditsObject



30
31
32
33
# File 'lib/busibe/client.rb', line 30

def check_available_credits
  get("/smsapi/get_credits")
  self
end

#check_delivery_status(message_id = nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/busibe/client.rb', line 35

def check_delivery_status(message_id = nil)
  if message_id.nil?
    raise ArgumentError.new("A message ID is required")
  end

  post("/smsapi/delivery_status?message_id=#{message_id}")
  self
end

#get_responseObject



44
45
46
# File 'lib/busibe/client.rb', line 44

def get_response
  JSON.load @response.body
end

#send_sms(payload = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/busibe/client.rb', line 21

def send_sms(payload = {})
  if payload.empty?
    raise ArgumentError.new("A payload is required in order to send an sms")
  end

  post("/smsapi/send_sms", payload)
  self
end