Class: Iated::BrowserTokenDB
- Inherits:
-
Object
- Object
- Iated::BrowserTokenDB
- Defined in:
- lib/iated/browser_token_db.rb
Overview
The database for storing authorized browser tokens
Instance Method Summary collapse
-
#add(user_agent) ⇒ String
Add a token to the database.
-
#has_token?(token) ⇒ Boolean
Does the token exist in the db?.
-
#initialize(fname) ⇒ BrowserTokenDB
constructor
A new instance of BrowserTokenDB.
-
#tokens ⇒ Array
List of all tokens in DB.
-
#user_agent(token) ⇒ String
What is the user_agent for the token?.
Constructor Details
#initialize(fname) ⇒ BrowserTokenDB
Returns a new instance of BrowserTokenDB.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/iated/browser_token_db.rb', line 9 def initialize fname @fname = Pathname.new fname @tokens = {} # Write an empty file. if @fname.exist? read else write end end |
Instance Method Details
#add(user_agent) ⇒ String
Add a token to the database. This stores it persistently.
24 25 26 27 28 29 |
# File 'lib/iated/browser_token_db.rb', line 24 def add user_agent token = generate_token @tokens[token] = user_agent.to_s write return token end |
#has_token?(token) ⇒ Boolean
Does the token exist in the db?
33 34 35 |
# File 'lib/iated/browser_token_db.rb', line 33 def has_token? token @tokens.key? token end |
#tokens ⇒ Array
List of all tokens in DB.
39 40 41 |
# File 'lib/iated/browser_token_db.rb', line 39 def tokens @tokens.keys end |
#user_agent(token) ⇒ String
What is the user_agent for the token?
45 46 47 |
# File 'lib/iated/browser_token_db.rb', line 45 def user_agent token @tokens[token] end |