Class: MitakeSms::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mitake_sms/response.rb

Constant Summary collapse

STATUS_MESSAGES =

附錄一 / 附錄二:statuscode 對應說明

{
  '0' => '預約傳送中',
  '1' => '已送達業者',
  '2' => '已送達業者',
  '4' => '已送達手機',
  '5' => '內容有錯誤',
  '6' => '門號有錯誤',
  '7' => '簡訊已停用',
  '8' => '逾時無送達',
  '9' => '預約已取消',
  '*' => '系統發生錯誤,請聯絡三竹資訊窗口人員',
  'a' => '簡訊發送功能暫時停止服務,請稍候再試',
  'b' => '簡訊發送功能暫時停止服務,請稍候再試',
  'c' => '請輸入帳號',
  'd' => '請輸入密碼',
  'e' => '帳號、密碼錯誤',
  'f' => '帳號已過期',
  'h' => '帳號已被停用',
  'k' => '無效的連線位址',
  'l' => '帳號已達到同時連線數上限',
  'm' => '必須變更密碼,在變更密碼前,無法使用簡訊發送服務',
  'n' => '密碼已逾期,在變更密碼前,將無法使用簡訊發送服務',
  'p' => '沒有權限使用外部Http程式',
  'r' => '系統暫停服務,請稍後再試',
  's' => '帳務處理失敗,無法發送簡訊',
  't' => '簡訊已過期',
  'u' => '簡訊內容不得為空白',
  'v' => '無效的手機號碼',
  'w' => '查詢筆數超過上限',
  'x' => '發送檔案過大,無法發送簡訊',
  'y' => '參數錯誤',
  'z' => '查無資料'
}.freeze
ACCEPTED_STATUS_CODES =

簡訊已被三竹收下或已送達。其餘 statuscode 皆視為失敗。

%w[0 1 2 4].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



45
46
47
48
49
50
# File 'lib/mitake_sms/response.rb', line 45

def initialize(raw_response)
  @raw_response = raw_response
  @records = []
  @account_point = nil
  parse(raw_response)
end

Instance Attribute Details

#account_pointObject (readonly)

Returns the value of attribute account_point.



43
44
45
# File 'lib/mitake_sms/response.rb', line 43

def 
  @account_point
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



43
44
45
# File 'lib/mitake_sms/response.rb', line 43

def raw_response
  @raw_response
end

#recordsObject (readonly)

Returns the value of attribute records.



43
44
45
# File 'lib/mitake_sms/response.rb', line 43

def records
  @records
end

Instance Method Details

#client_idObject



60
61
62
# File 'lib/mitake_sms/response.rb', line 60

def client_id
  first_record['clientid']
end

#codeObject



52
53
54
# File 'lib/mitake_sms/response.rb', line 52

def code
  first_record['statuscode']
end

#duplicate?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/mitake_sms/response.rb', line 68

def duplicate?
  first_record['Duplicate'] == 'Y'
end

#errorObject



86
87
88
89
90
91
92
93
# File 'lib/mitake_sms/response.rb', line 86

def error
  return nil if success?

  failures = @records.reject { |record| accepted?(record) }
  return 'Empty or unparseable response' if failures.empty?

  failures.map { |record| describe(record) }.join('; ')
end

#error?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/mitake_sms/response.rb', line 82

def error?
  !success?
end

#message_idObject



56
57
58
# File 'lib/mitake_sms/response.rb', line 56

def message_id
  first_record['msgid']
end

#message_idsObject



72
73
74
# File 'lib/mitake_sms/response.rb', line 72

def message_ids
  @records.map { |record| record['msgid'] }.compact
end

#sms_pointObject



64
65
66
# File 'lib/mitake_sms/response.rb', line 64

def sms_point
  first_record['smsPoint']
end

#success?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'lib/mitake_sms/response.rb', line 76

def success?
  return false if @records.empty?

  @records.all? { |record| accepted?(record) }
end