Class: ServiceTicket
- Inherits:
-
Object
- Object
- ServiceTicket
- Defined in:
- lib/service_ticket.rb
Instance Attribute Summary collapse
-
#service_url ⇒ Object
readonly
Returns the value of attribute service_url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(service_url, username) ⇒ ServiceTicket
constructor
A new instance of ServiceTicket.
- #remaining_time(store) ⇒ Object
- #save!(store) ⇒ Object
- #ticket ⇒ Object
- #valid_for_service?(url) ⇒ Boolean
Constructor Details
#initialize(service_url, username) ⇒ ServiceTicket
Returns a new instance of ServiceTicket.
20 21 22 23 |
# File 'lib/service_ticket.rb', line 20 def initialize(service_url, username) @service_url = service_url @username = username end |
Instance Attribute Details
#service_url ⇒ Object (readonly)
Returns the value of attribute service_url.
18 19 20 |
# File 'lib/service_ticket.rb', line 18 def service_url @service_url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
18 19 20 |
# File 'lib/service_ticket.rb', line 18 def username @username end |
Class Method Details
.expire_time ⇒ Object
13 14 15 |
# File 'lib/service_ticket.rb', line 13 def expire_time 300 end |
.find!(ticket, store) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/service_ticket.rb', line 3 def find!(ticket, store) username = store.hget(ticket, :username) service_url = store.hget(ticket, :service_url) if service_url && username store.del ticket new(service_url, username) end end |
Instance Method Details
#remaining_time(store) ⇒ Object
33 34 35 |
# File 'lib/service_ticket.rb', line 33 def remaining_time(store) store.ttl ticket end |
#save!(store) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/service_ticket.rb', line 37 def save!(store) store.pipelined do store.hset ticket, :service_url, self.service_url store.hset ticket, :username, self.username store.expire ticket, self.class.expire_time end end |
#ticket ⇒ Object
29 30 31 |
# File 'lib/service_ticket.rb', line 29 def ticket @ticket ||= "ST-#{rand(100000000000000000)}".to_s end |
#valid_for_service?(url) ⇒ Boolean
25 26 27 |
# File 'lib/service_ticket.rb', line 25 def valid_for_service?(url) service_url == url end |