Class: Uid2::Client
- Inherits:
-
Object
- Object
- Uid2::Client
- Defined in:
- lib/uid2/client.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #generate_identifier(email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
- #generate_token(email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
- #get_salt_buckets(since: Time.now) ⇒ Object
-
#initialize(_options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #refresh_token(refresh_token:, refresh_response_key:) ⇒ Object
- #validate_token(token:, email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
Constructor Details
#initialize(_options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/uid2/client.rb', line 13 def initialize( = {}) yield(self) if block_given? self.base_url ||= "https://prod.uidapi.com/v2/" end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
11 12 13 |
# File 'lib/uid2/client.rb', line 11 def base_url @base_url end |
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
11 12 13 |
# File 'lib/uid2/client.rb', line 11 def bearer_token @bearer_token end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
11 12 13 |
# File 'lib/uid2/client.rb', line 11 def secret_key @secret_key end |
Instance Method Details
#generate_identifier(email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/uid2/client.rb', line 42 def generate_identifier(email: nil, email_hash: nil, phone: nil, phone_hash: nil) params = {email: Array(email), email_hash: Array(email_hash), phone: Array(phone), phone_hash: Array(phone_hash)}.reject { |_, v| v.empty? } raise ArgumentError, "One of the argument needs to be provided" if params.empty? http.post("identity/map", params).body end |
#generate_token(email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/uid2/client.rb', line 19 def generate_token(email: nil, email_hash: nil, phone: nil, phone_hash: nil) params = {email: email, email_hash: email_hash, phone: phone, phone_hash: phone_hash}.reject { |_, v| v.nil? } raise ArgumentError, "One of the argument needs to be provided" if params.empty? http.post("token/generate", params).body end |
#get_salt_buckets(since: Time.now) ⇒ Object
36 37 38 39 40 |
# File 'lib/uid2/client.rb', line 36 def get_salt_buckets(since: Time.now) # By default, Ruby's iso8601 generates timezone parts (`T`) # which needs to be removed for UID2 APIs http.post("identity/buckets", since_timestamp: since.utc.iso8601[0..-2]).body end |
#refresh_token(refresh_token:, refresh_response_key:) ⇒ Object
32 33 34 |
# File 'lib/uid2/client.rb', line 32 def refresh_token(refresh_token:, refresh_response_key:) http(refresh_response_key: refresh_response_key).post("token/refresh", refresh_token).body end |
#validate_token(token:, email: nil, email_hash: nil, phone: nil, phone_hash: nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/uid2/client.rb', line 25 def validate_token(token:, email: nil, email_hash: nil, phone: nil, phone_hash: nil) params = {email: email, email_hash: email_hash, phone: phone, phone_hash: phone_hash}.reject { |_, v| v.nil? } raise ArgumentError, "One of the argument needs to be provided" if params.empty? http.post("token/validate", params.merge(token: token)).body end |