Class: Megar::Session
- Inherits:
-
Object
- Object
- Megar::Session
- Includes:
- Connection, Crypto
- Defined in:
- lib/megar/session.rb
Constant Summary
Constants included from Connection
Connection::DEFAULT_API_ENDPOINT
Instance Attribute Summary collapse
-
#decomposed_rsa_private_key ⇒ Object
4 part array of a32.
-
#email ⇒ Object
Returns the user email (convenience method).
-
#master_key ⇒ Object
Returns the value of attribute master_key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#password ⇒ Object
Returns the user password (convenience method).
-
#rsa_private_key ⇒ Object
binary string.
Attributes included from Connection
Instance Method Summary collapse
-
#connect! ⇒ Object
Command: perform login session challenge/response.
-
#connected? ⇒ Boolean
Returns authenticated/connected status.
-
#files ⇒ Object
Returns the files collection.
-
#folders ⇒ Object
Returns the folder collection.
-
#initialize(options = {}) ⇒ Session
constructor
Start a new session, given
options
hash. - #refresh_files! ⇒ Object
- #reset_files! ⇒ Object
-
#rsa_private_key_b64 ⇒ Object
Returns the rsa_private_key base64-encoded.
-
#to_s ⇒ Object
Returns a pretty representation of the session object.
Methods included from Connection
#api_endpoint, #api_endpoint=, #api_request, #api_uri, #next_sequence_number!, #sequence_number, #sequence_number=
Methods included from Crypto
#a32_to_base64, #a32_to_str, #aes_cbc_decrypt, #aes_cbc_decrypt_a32, #aes_encrypt_a32, #base64_mpi_to_a32, #base64_mpi_to_bn, #base64_to_a32, #base64urldecode, #base64urlencode, #decompose_file_key, #decompose_rsa_private_key, #decompose_rsa_private_key_a32, #decrypt_base64_to_a32, #decrypt_base64_to_str, #decrypt_file_attributes, #decrypt_file_key, #decrypt_key, #decrypt_session_id, #hexstr_to_bstr, #mpi_to_a32, #openssl_rsa_cipher, #openssl_rsa_decrypt, #prepare_key, #prepare_key_pw, #rsa_decrypt, #str_to_a32, #stringhash
Constructor Details
#initialize(options = {}) ⇒ Session
Start a new session, given options
hash.
Required options
parameters:
email: 'your email address' -- email for authentication
password: 'your password' -- password for authentication
Optional options
parameters:
api_endpoint: 'url' -- talk to an alternative API endpoint
autoconnect: true/false -- performs immediate login if true (default)
23 24 25 26 27 28 |
# File 'lib/megar/session.rb', line 23 def initialize(={}) = { autoconnect: true } @options = .merge(.symbolize_keys) self.api_endpoint = @options[:api_endpoint] if @options[:api_endpoint] connect! if @options[:autoconnect] end |
Instance Attribute Details
#decomposed_rsa_private_key ⇒ Object
4 part array of a32
11 12 13 |
# File 'lib/megar/session.rb', line 11 def decomposed_rsa_private_key @decomposed_rsa_private_key end |
#email ⇒ Object
Returns the user email (convenience method)
52 53 54 |
# File 'lib/megar/session.rb', line 52 def email @email end |
#master_key ⇒ Object
Returns the value of attribute master_key.
9 10 11 |
# File 'lib/megar/session.rb', line 9 def master_key @master_key end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/megar/session.rb', line 6 def @options end |
#password ⇒ Object
Returns the user password (convenience method)
57 58 59 |
# File 'lib/megar/session.rb', line 57 def password @password end |
#rsa_private_key ⇒ Object
binary string
10 11 12 |
# File 'lib/megar/session.rb', line 10 def rsa_private_key @rsa_private_key end |
Instance Method Details
#connect! ⇒ Object
Command: perform login session challenge/response. Establishes a user session based on the response to a cryptographic challenge.
47 48 49 |
# File 'lib/megar/session.rb', line 47 def connect! handle_login_challenge_response(get_login_response) end |
#connected? ⇒ Boolean
Returns authenticated/connected status
31 32 33 |
# File 'lib/megar/session.rb', line 31 def connected? !sid.nil? end |
#files ⇒ Object
Returns the files collection
73 74 75 76 |
# File 'lib/megar/session.rb', line 73 def files refresh_files! if @files.nil? @files end |
#folders ⇒ Object
Returns the folder collection
67 68 69 70 |
# File 'lib/megar/session.rb', line 67 def folders refresh_files! if @folders.nil? @folders end |
#refresh_files! ⇒ Object
78 79 80 |
# File 'lib/megar/session.rb', line 78 def refresh_files! handle_files_response(get_files_response) end |
#reset_files! ⇒ Object
82 83 84 85 |
# File 'lib/megar/session.rb', line 82 def reset_files! @folders = Megar::Folders.new @files = Megar::Files.new end |
#rsa_private_key_b64 ⇒ Object
Returns the rsa_private_key base64-encoded
62 63 64 |
# File 'lib/megar/session.rb', line 62 def rsa_private_key_b64 base64urlencode(rsa_private_key) end |
#to_s ⇒ Object
Returns a pretty representation of the session object
36 37 38 39 40 41 42 |
# File 'lib/megar/session.rb', line 36 def to_s if connected? "#{self.class.name}: connected as #{email}" else "#{self.class.name}: not connected" end end |