Class: Kth::Alimtalk::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kth/alimtalk.rb

Constant Summary collapse

BASE_URL =
"http://api.apistore.co.kr".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, key) ⇒ Client

TODO. 코드 및 메세지 정의 맵핑 추가



12
13
14
15
# File 'lib/kth/alimtalk.rb', line 12

def initialize(client_id, key)
  self.client_id = client_id
  self.key = key
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



7
8
9
# File 'lib/kth/alimtalk.rb', line 7

def client_id
  @client_id
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/kth/alimtalk.rb', line 7

def key
  @key
end

Instance Method Details

#callbacks(send_phone_number = '') ⇒ Object



79
80
81
82
# File 'lib/kth/alimtalk.rb', line 79

def callbacks(send_phone_number = '')
  request_url = "/kko/1/sendnumber/list/#{client_id}?sendnumber=#{send_phone_number}"
  send_get_request request_url
end

#msg_test(phone_number, callback, msg, template_code, failed_type, options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/kth/alimtalk.rb', line 84

def msg_test(phone_number, callback, msg, template_code, failed_type, options)
  request_url = "/kko/1/msg_test/#{client_id}"
  params = {
    'phone' => phone_number,
    'callback' => callback,
    'msg' => msg,
    'template_code' => template_code,
    'failed_type' => failed_type
  }

  if options.present?
    params['reqdate'] = options['request_date'].strftime("%Y%m%d%H%M%S") if options['request_date']
    params['url'] = options['url'] if options['url']
    params['url_button_text'] = options['url_button_text'] if options['url_button_text']
    params['failed_subject'] = options['failed_subject'] if options['failed_subject']
    params['failed_msg'] = options['failed_msg']
  end

  send_post_request request_url, params
end

#register_callback(send_phone_number, comment, pin_type = 'SMS') ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kth/alimtalk.rb', line 54

def register_callback(send_phone_number, comment, pin_type = 'SMS')
  phone_number = send_phone_number.gsub("-", "")
  request_url = "/kko/1/sendnumber/save/#{client_id}"
  params = {
    'sendnumber' => phone_number,
    'comment' => comment,
    'pintype' => pin_type
  }

  send_post_request request_url, params
end

#report(cmid) ⇒ Object



38
39
40
41
42
# File 'lib/kth/alimtalk.rb', line 38

def report(cmid)
  request_url = "/kko/1/report/#{client_id}?CMID=#{cmid}"

  send_get_request request_url
end

#send_message(phone_number, callback, msg, template_code, failed_type, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kth/alimtalk.rb', line 17

def send_message(phone_number, callback, msg, template_code, failed_type, options)
  request_url = "/kko/1/msg/#{client_id}"
  params = {
    'phone' => phone_number,
    'callback' => callback,
    'msg' => msg,
    'template_code' => template_code,
    'failed_type' => failed_type
  }

  if options.present?
    params['reqdate'] = options['request_date'].strftime("%Y%m%d%H%M%S") if options['request_date']
    params['url'] = options['url'] if options['url']
    params['url_button_text'] = options['url_button_text'] if options['url_button_text']
    params['failed_subject'] = options['failed_subject'] if options['failed_subject']
    params['failed_msg'] = options['failed_msg']
  end

  send_post_request request_url, params
end

#templates(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/kth/alimtalk.rb', line 44

def templates(options = {})
  request_url = "/kko/1/template/list/#{client_id}?"
  if options.present?
    request_url += "TEMPLATE_CODE=##{options['template_code']}&" if options['template_code']
    request_url += "STATUS=#{options['status']}&" if options['status']
  end

  send_get_request request_url
end

#verify_callback(send_phone_number, comment, pin_type, pin_code) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kth/alimtalk.rb', line 66

def verify_callback(send_phone_number, comment, pin_type, pin_code)
  phone_number = send_phone_number.gsub("-", "")
  request_url = "/kko/1/sendnumber/save/#{client_id}"
  params = {
    'sendnumber' => phone_number,
    'comment' => comment,
    'pintype' => pin_type,
    'pincode' => pin_code
  }

  send_post_request request_url, params
end