Class: ProximityBeacon::Credentials
- Inherits:
-
Object
- Object
- ProximityBeacon::Credentials
- Defined in:
- lib/proximity_beacon/credentials.rb
Constant Summary collapse
- DEFAULT_FILE_STORE =
File.("~/.proximity_beacon_credentials.yaml")
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Credentials
constructor
A new instance of Credentials.
- #save(file = DEFAULT_FILE_STORE) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Credentials
Returns a new instance of Credentials.
14 15 16 17 18 19 20 21 |
# File 'lib/proximity_beacon/credentials.rb', line 14 def initialize(opts = {}) # convert string keys to symbols opts = opts.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} self.access_token = opts[:access_token] self.refresh_token = opts[:refresh_token] self.expires_at = opts[:expires_at] || (Time.now + opts[:expires_in].to_i) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/proximity_beacon/credentials.rb', line 7 def access_token @access_token end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
7 8 9 |
# File 'lib/proximity_beacon/credentials.rb', line 7 def expires_at @expires_at end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/proximity_beacon/credentials.rb', line 7 def refresh_token @refresh_token end |
Class Method Details
.from_file(file = DEFAULT_FILE_STORE) ⇒ Object
9 10 11 12 |
# File 'lib/proximity_beacon/credentials.rb', line 9 def self.from_file(file = DEFAULT_FILE_STORE) return nil unless File.exist?(file) self.new YAML.load_file(file) end |
Instance Method Details
#expired? ⇒ Boolean
32 33 34 |
# File 'lib/proximity_beacon/credentials.rb', line 32 def expired? self.expires_at < Time.now end |
#save(file = DEFAULT_FILE_STORE) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/proximity_beacon/credentials.rb', line 23 def save(file = DEFAULT_FILE_STORE) data = { access_token: access_token, refresh_token: refresh_token, expires_at: expires_at }.to_yaml File.open(file, 'w') {|f| f.write(data) } end |