Class: Cetustek::PhoneBarcode
- Inherits:
-
Object
- Object
- Cetustek::PhoneBarcode
- 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
-
#initialize(phone_code) ⇒ PhoneBarcode
constructor
A new instance of PhoneBarcode.
-
#response ⇒ Object
Full parsed JSON response: { "isExist", "code", "msg", "TxID", "version" }.
-
#valid? ⇒ Boolean
true when the barcode exists (isExist == 'Y').
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
14 15 16 |
# File 'lib/cetustek/phone_barcode.rb', line 14 def self.valid?(phone_code) new(phone_code).valid? end |
Instance Method Details
#response ⇒ Object
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').
23 24 25 |
# File 'lib/cetustek/phone_barcode.rb', line 23 def valid? response['isExist'] == 'Y' end |