Class: Wagon::Connection
- Inherits:
-
Object
- Object
- Wagon::Connection
- Defined in:
- lib/wagon/connection.rb
Constant Summary collapse
- HOST =
'secure.lds.org'
- LOGIN_PATH =
'/units/a/login/1,21568,779-1,00.html?URL='
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
Class Method Summary collapse
Instance Method Summary collapse
- #_dump(depth) ⇒ Object
- #expired? ⇒ Boolean
- #get(path) ⇒ Object
- #home_path ⇒ Object
-
#initialize(username, password) ⇒ Connection
constructor
A new instance of Connection.
- #ward ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Connection
Returns a new instance of Connection.
16 17 18 19 20 21 22 |
# File 'lib/wagon/connection.rb', line 16 def initialize(username, password) response = _post(LOGIN_PATH, 'username' => username, 'password' => password) @cookies = response['set-cookie'] @home_path = URI.parse(response['location']).path raise AuthenticationFailure.new("Invalid username and/or password") unless @cookies end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
14 15 16 |
# File 'lib/wagon/connection.rb', line 14 def @cookies end |
Class Method Details
._load(string) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/wagon/connection.rb', line 44 def self._load(string) attributes = Marshal.restore(string) connection = Connection.allocate() connection.instance_variable_set(:@cookies, attributes.shift) connection.instance_variable_set(:@home_path, attributes.shift) connection end |
Instance Method Details
#_dump(depth) ⇒ Object
40 41 42 |
# File 'lib/wagon/connection.rb', line 40 def _dump(depth) Marshal.dump([@cookies, @home_path]) end |
#expired? ⇒ Boolean
36 37 38 |
# File 'lib/wagon/connection.rb', line 36 def expired? _head(ward.directory_path).class != Net::HTTPOK end |
#get(path) ⇒ Object
32 33 34 |
# File 'lib/wagon/connection.rb', line 32 def get(path) _get(path).body end |
#home_path ⇒ Object
24 25 26 |
# File 'lib/wagon/connection.rb', line 24 def home_path @home_path end |