Class: Tokenex::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/tokenex/environment.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_base_url, tokenex_id, api_key, options = {}) ⇒ Environment

Returns a new instance of Environment.



8
9
10
11
12
# File 'lib/tokenex/environment.rb', line 8

def initialize(api_base_url, tokenex_id, api_key, options={})
    @api_base_url = api_base_url
    @tokenex_id = tokenex_id
    @api_key = api_key
end

Instance Method Details

#delete_token(token) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tokenex/environment.rb', line 58

def delete_token(token)
    action = "DeleteToken"
    data = {
        "Token" => token
    }
    
    response = send_request(action, data)
    throw :tokenex_invalid_token unless is_valid_response(response) 
    
    return response['Success']
end

#detokenize(token) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tokenex/environment.rb', line 34

def detokenize(token)
    action = "Detokenize"
    data = {
        "Token" => token
    }
    
    response = send_request(action, data)
    throw :tokenex_invalid_token unless is_valid_response(response) 
    
    return response['Value']
end

#token_from_ccnum(ccNum) ⇒ Object



14
15
16
17
18
19
# File 'lib/tokenex/environment.rb', line 14

def token_from_ccnum(ccNum)
    catch (:tokenex_cannot_tokenize_data) do
        return tokenize(ccNum, 3)
    end
    throw :tokenex_invalid_ccnum
end

#tokenize(data_to_tokenize, token_scheme = 4) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tokenex/environment.rb', line 21

def tokenize(data_to_tokenize, token_scheme = 4)
    action = "Tokenize"
    data = {
        "Data" => data_to_tokenize,
        "TokenScheme" => token_scheme
    }
    
    response = send_request(action, data)
    throw :tokenex_cannot_tokenize_data unless is_valid_response(response)
    
    return response['Token']
end

#validate_token(token) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tokenex/environment.rb', line 46

def validate_token(token)
    action = "ValidateToken"
    data = {
        "Token" => token
    }
    
    response = send_request(action, data)
    throw :tokenex_invalid_token unless is_valid_response(response) 
    
    return response['Valid']
end