Class: WCC::Arena::Session
- Inherits:
-
Object
- Object
- WCC::Arena::Session
- Defined in:
- lib/wcc/arena/session.rb
Defined Under Namespace
Classes: NullNode
Constant Summary collapse
- DEFAULT_POST_HEADERS =
{ content_type: "text/xml", }
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #expires ⇒ Object
- #get(path, query = {}) ⇒ Object
- #id ⇒ Object
-
#initialize(args = {}) ⇒ Session
constructor
A new instance of Session.
- #post(path, query = {}, body = nil) ⇒ Object
- #reset ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 16 |
# File 'lib/wcc/arena/session.rb', line 10 def initialize(args={}) @connection = args.fetch(:connection) { WCC::Arena.config.connection } @username = args.fetch(:username) @password = args.fetch(:password) @api_key = args.fetch(:api_key) @api_secret = args.fetch(:api_secret) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/wcc/arena/session.rb', line 4 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
4 5 6 |
# File 'lib/wcc/arena/session.rb', line 4 def api_secret @api_secret end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/wcc/arena/session.rb', line 4 def connection @connection end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/wcc/arena/session.rb', line 4 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
4 5 6 |
# File 'lib/wcc/arena/session.rb', line 4 def username @username end |
Instance Method Details
#expires ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/wcc/arena/session.rb', line 22 def expires if !date_expires_node.text.empty? Time.parse(date_expires_node.text) else Time.new(0) end end |
#get(path, query = {}) ⇒ Object
30 31 32 33 |
# File 'lib/wcc/arena/session.rb', line 30 def get(path, query={}) reset unless valid? build_response(connection.get(signed_path(path, query))) end |
#id ⇒ Object
18 19 20 |
# File 'lib/wcc/arena/session.rb', line 18 def id session_id_node.text end |
#post(path, query = {}, body = nil) ⇒ Object
35 36 37 38 |
# File 'lib/wcc/arena/session.rb', line 35 def post(path, query={}, body=nil) reset unless valid? build_response(connection.post(signed_path(path, query), body, DEFAULT_POST_HEADERS)) end |
#reset ⇒ Object
46 47 48 |
# File 'lib/wcc/arena/session.rb', line 46 def reset @login_response = nil end |
#valid? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/wcc/arena/session.rb', line 40 def valid? login_response.status == 200 && expires > Time.now && !id.empty? end |