Class: Purest::Rest
- Inherits:
-
Object
- Object
- 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
9 10 11 12 |
# File 'lib/purest/rest.rb', line 9 def initialize establish_connection create_session unless authenticated? end |
Class Method Details
.access_method?(meth_id) ⇒ Boolean
55 56 57 |
# File 'lib/purest/rest.rb', line 55 def access_method?(meth_id) @access_methods.include? meth_id end |
.method_missing(meth_id, *args) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/purest/rest.rb', line 59 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
15 16 17 18 19 20 21 |
# File 'lib/purest/rest.rb', line 15 def authenticated? if defined? @session_expire Time.now.utc < @session_expire else false end end |
#concat_url(parts) ⇒ String
Assemble a url from an array of parts.
26 27 28 29 30 31 32 |
# File 'lib/purest/rest.rb', line 26 def concat_url(parts) if parts.length > 1 parts.first + '?' + parts.drop(1).join('&') else parts.first end end |
#logout ⇒ Object
Logout current session
47 48 49 50 51 52 |
# File 'lib/purest/rest.rb', line 47 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
38 39 40 41 42 43 44 |
# File 'lib/purest/rest.rb', line 38 def use_named_parameter(name, value) if value.is_a? Array ["#{name}=#{value.join(',')}"] else value ? ["#{name}=#{value}"] : [] end end |