Class: BooticCli::Session
- Inherits:
-
Object
- Object
- BooticCli::Session
- Defined in:
- lib/bootic_cli/session.rb
Instance Method Summary collapse
- #client ⇒ Object
- #config ⇒ Object
- #erase! ⇒ Object
-
#initialize(store) ⇒ Session
constructor
A new instance of Session.
- #logged_in? ⇒ Boolean
- #login(username, pwd, scope) ⇒ Object
- #logout! ⇒ Object
- #ready? ⇒ Boolean
- #setup(client_id, client_secret) ⇒ Object
- #setup? ⇒ Boolean
Constructor Details
#initialize(store) ⇒ Session
Returns a new instance of Session.
7 8 9 |
# File 'lib/bootic_cli/session.rb', line 7 def initialize(store) @store = store end |
Instance Method Details
#client ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bootic_cli/session.rb', line 60 def client @client ||= begin raise "First setup credentials and log in" unless ready? BooticClient.configure do |c| c.client_id = config[:client_id] c.client_secret = config[:client_secret] c.logger = Logger.new(STDOUT) c.logging = false end BooticClient.client(:authorized, access_token: config[:access_token]) do |new_token| store.transaction{ store['access_token'] = new_token } end end end |
#config ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/bootic_cli/session.rb', line 50 def config @config ||= store.transaction do { client_id: store['client_id'], client_secret: store['client_secret'], access_token: store['access_token'] } end end |
#erase! ⇒ Object
40 41 42 |
# File 'lib/bootic_cli/session.rb', line 40 def erase! store.erase end |
#logged_in? ⇒ Boolean
17 18 19 |
# File 'lib/bootic_cli/session.rb', line 17 def logged_in? store.transaction{ store['access_token'] } end |
#login(username, pwd, scope) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bootic_cli/session.rb', line 32 def login(username, pwd, scope) token = oauth_client.password.get_token(username, pwd, 'scope' => scope) store.transaction do store['access_token'] = token.token end end |
#logout! ⇒ Object
44 45 46 47 48 |
# File 'lib/bootic_cli/session.rb', line 44 def logout! store.transaction do store['access_token'] = nil end end |
#ready? ⇒ Boolean
21 22 23 |
# File 'lib/bootic_cli/session.rb', line 21 def ready? setup? && logged_in? end |
#setup(client_id, client_secret) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bootic_cli/session.rb', line 25 def setup(client_id, client_secret) store.transaction do store['client_id'] = client_id store['client_secret'] = client_secret end end |
#setup? ⇒ Boolean
11 12 13 14 15 |
# File 'lib/bootic_cli/session.rb', line 11 def setup? store.transaction do store['client_id'] && store['client_secret'] end end |