Class: Session

Inherits:
Object
  • Object
show all
Defined in:
lib/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options)
  @resources = []
  @options   = {
    :production => false,
    :write      => false
  }.merge options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/session.rb', line 3

def options
  @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(options)
  resource = Resource.new(self,@options.merge(options))
  resource.get_next
  @resources << resource
end

#all_endpointsObject



68
69
70
# File 'lib/session.rb', line 68

def all_endpoints
  json_endpoints + xml_endpoints
end

#discoveryObject



40
41
42
# File 'lib/session.rb', line 40

def discovery
  @resources.first
end

#endpoint_arrayObject

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_endpointsObject



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_servicesObject



87
88
89
# File 'lib/session.rb', line 87

def raw_services
  @resources[1].raw
end

#resourceObject



44
45
46
# File 'lib/session.rb', line 44

def resource
  @resources.last
end

#resourcesObject



36
37
38
# File 'lib/session.rb', line 36

def resources
  @resources
end

#run_testsObject



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

#servicesObject

Services Lookup



83
84
85
# File 'lib/session.rb', line 83

def services
  @resources[1].raw.map{|r| r.response }.flatten
end

#valid?Boolean

Returns:

  • (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

#xml_endpointsObject



76
77
78
# File 'lib/session.rb', line 76

def xml_endpoints
  Array(Session.unwrap(discovery.raw.xml,'response.discovery.endpoints.endpoint')).select{|endpoint| production_safe?(endpoint) }
end