Class: Cetustek::PhoneBarcode

Inherits:
Object
  • Object
show all
Defined in:
lib/cetustek/phone_barcode.rb

Overview

3.1 手機條碼 API — validates a mobile barcode (手機條碼) against the 財政部 platform. Plain HTTP GET returning JSON, NOT the SOAP service.

Constant Summary collapse

ENDPOINT =
'https://api.cetustek.com.tw/PhoneBar.php'
AUTH_KEY =

spec: fixed for now, may become per-account

'Cetus9Phone1API7'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phone_code) ⇒ PhoneBarcode

Returns a new instance of PhoneBarcode.



18
19
20
# File 'lib/cetustek/phone_barcode.rb', line 18

def initialize(phone_code)
  @phone_code = phone_code
end

Class Method Details

.valid?(phone_code) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/cetustek/phone_barcode.rb', line 14

def self.valid?(phone_code)
  new(phone_code).valid?
end

Instance Method Details

#responseObject

Full parsed JSON response: { "isExist", "code", "msg", "TxID", "version" }.



28
29
30
31
32
33
34
35
36
# File 'lib/cetustek/phone_barcode.rb', line 28

def response
  uri = URI(ENDPOINT)
  uri.query = URI.encode_www_form(
    rentid: Cetustek.config.username,
    authkey: AUTH_KEY,
    phonecode: @phone_code
  )
  JSON.parse(Net::HTTP.get_response(uri).body)
end

#valid?Boolean

true when the barcode exists (isExist == 'Y').

Returns:

  • (Boolean)


23
24
25
# File 'lib/cetustek/phone_barcode.rb', line 23

def valid?
  response['isExist'] == 'Y'
end