Class: Session
- Inherits:
-
Object
- Object
- Session
- Defined in:
- lib/session.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .endpoint_formats(endpoint) ⇒ Object
- .endpoint_formats_as_array(endpoint) ⇒ Object
-
.unwrap(obj, methods) ⇒ Object
Class Methods.
Instance Method Summary collapse
-
#add_resource(options) ⇒ Object
Resource mgmt.
- #all_endpoints ⇒ Object
- #discovery ⇒ Object
-
#endpoint_array ⇒ Object
Endpoint mgmt.
-
#initialize(options) ⇒ Session
constructor
A new instance of Session.
- #json_endpoints ⇒ Object
- #raw_services ⇒ Object
- #resource ⇒ Object
- #resources ⇒ Object
- #run_tests ⇒ Object
-
#services ⇒ Object
Services Lookup.
- #valid? ⇒ Boolean
- #xml_endpoints ⇒ Object
Constructor Details
#initialize(options) ⇒ Session
Returns a new instance of Session.
5 6 7 8 9 10 11 |
# File 'lib/session.rb', line 5 def initialize() @resources = [] @options = { :production => false, :write => false }.merge end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/session.rb', line 3 def @options end |
Class Method Details
.endpoint_formats(endpoint) ⇒ Object
64 65 66 |
# File 'lib/session.rb', line 64 def self.endpoint_formats(endpoint) endpoint.formats.is_a?(Array) ? endpoint.formats : Array(Session.unwrap(endpoint,'formats.format')) end |
.endpoint_formats_as_array(endpoint) ⇒ Object
60 61 62 |
# File 'lib/session.rb', line 60 def self.endpoint_formats_as_array(endpoint) Session.endpoint_formats(endpoint).map{|format| format.to_s.split('/')[1]} end |
.unwrap(obj, methods) ⇒ Object
Class Methods
92 93 94 95 96 97 |
# File 'lib/session.rb', line 92 def self.unwrap(obj,methods) methods.split('.').each do |method| obj = obj.send method.to_sym end obj end |
Instance Method Details
#add_resource(options) ⇒ Object
Resource mgmt.
30 31 32 33 34 |
# File 'lib/session.rb', line 30 def add_resource() resource = Resource.new(self,@options.merge()) resource.get_next @resources << resource end |
#all_endpoints ⇒ Object
68 69 70 |
# File 'lib/session.rb', line 68 def all_endpoints json_endpoints + xml_endpoints end |
#discovery ⇒ Object
40 41 42 |
# File 'lib/session.rb', line 40 def discovery @resources.first end |
#endpoint_array ⇒ Object
Endpoint mgmt.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/session.rb', line 49 def endpoint_array t = [] all_endpoints.each do |endpoint| Session.endpoint_formats_as_array(endpoint).each do |format| next if format =~ /^.*html$/i t << [endpoint.url,format] end end t end |
#json_endpoints ⇒ Object
72 73 74 |
# File 'lib/session.rb', line 72 def json_endpoints Session.unwrap(discovery.raw.json, 'response.endpoints').select{|endpoint| production_safe?(endpoint) } end |
#raw_services ⇒ Object
87 88 89 |
# File 'lib/session.rb', line 87 def raw_services @resources[1].raw end |
#resource ⇒ Object
44 45 46 |
# File 'lib/session.rb', line 44 def resource @resources.last end |
#resources ⇒ Object
36 37 38 |
# File 'lib/session.rb', line 36 def resources @resources end |
#run_tests ⇒ Object
13 14 15 16 17 18 |
# File 'lib/session.rb', line 13 def run_tests load 'tests/discovery.rb' load 'tests/services.rb' load 'tests/service_definition.rb' load 'tests/create.rb' if @options[:write] end |
#services ⇒ Object
Services Lookup
83 84 85 |
# File 'lib/session.rb', line 83 def services @resources[1].raw.map{|r| r.response }.flatten end |
#valid? ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/session.rb', line 20 def valid? @options[:discovery_url] && !@options[:production].nil? && !@options[:write].nil? && !@options[:production].nil? && (!@options[:write] || ( @options[:write] && !@options[:address].nil? )) end |