Class: Purest::Rest
- Inherits:
-
CustomExceptions
- Object
- CustomExceptions
- Purest::Rest
- Defined in:
- lib/purest/rest.rb
Overview
Base class for interacting with PURE storage REST API
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Check if session exists, and whether or not it’s expired.
-
#concat_url(parts) ⇒ String
Assemble a url from an array of parts.
-
#initialize ⇒ Rest
constructor
Initialize the fadaray connection, create session unless one exists.
-
#logout ⇒ Object
Logout current session.
-
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly.
Constructor Details
#initialize ⇒ Rest
Initialize the fadaray connection, create session unless one exists
10 11 12 13 |
# File 'lib/purest/rest.rb', line 10 def initialize establish_connection create_session unless authenticated? end |
Class Method Details
.access_method?(meth_id) ⇒ Boolean
60 61 62 |
# File 'lib/purest/rest.rb', line 60 def access_method?(meth_id) @access_methods.include? meth_id end |
.method_missing(meth_id, *args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/purest/rest.rb', line 64 def method_missing(meth_id, *args) if access_method?(meth_id) new.send(meth_id, *args) else # See https://bugs.ruby-lang.org/issues/10969 begin super rescue NameError => err raise NoMethodError, err end end end |
Instance Method Details
#authenticated? ⇒ Boolean
Check if session exists, and whether or not it’s expired
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/purest/rest.rb', line 16 def authenticated? if defined? @session_expire if Time.now.utc < @session_expire true else false end else false end end |
#concat_url(parts) ⇒ String
Assemble a url from an array of parts.
31 32 33 34 35 36 37 |
# File 'lib/purest/rest.rb', line 31 def concat_url(parts) if parts.length > 1 parts.first + '?' + parts.drop(1).join('&') else parts.first end end |
#logout ⇒ Object
Logout current session
52 53 54 55 56 57 |
# File 'lib/purest/rest.rb', line 52 def logout raw_resp = @conn.delete do |req| req.url "/api/#{Purest.configuration.api_version}/auth/session" end remove_instance_variable(:@session_expire) end |
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly
43 44 45 46 47 48 49 |
# File 'lib/purest/rest.rb', line 43 def use_named_parameter(name, value) if value.is_a? Array ["#{name}=#{value.join(',')}"] else value ? ["#{name}=#{value}"] : [] end end |