Class: Matterhorn::Endpoint

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

Overview

Matterhorn::Endpoint ===

Direct Known Subclasses

Acl, Event, Group, Ingest, Security, Series, Staticfiles, User, Workflow

Defined Under Namespace

Classes: Acl, Event, Group, Ingest, Security, Series, Staticfiles, User, Workflow

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(org_domain = '', mh_instance = :default) ⇒ Endpoint

Returns a new instance of Endpoint.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/matterhorn/endpoint.rb', line 40

def initialize(org_domain = '', mh_instance = :default)
  @http_endpoint_client = Matterhorn::HttpClient.new(
    MatterhornWhymper.configuration.endpoint(mh_instance)[:protocol],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:domain],
    org_domain,
    MatterhornWhymper.configuration.endpoint(mh_instance)[:user],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:password],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:auth_mode],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:http_timeout],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:ssl_dont_verify_cert],
    MatterhornWhymper.configuration.endpoint(mh_instance)[:multi_tenant] 
  )
  @http_api_client = if !MatterhornWhymper.configuration.api(mh_instance).nil?
    Matterhorn::HttpClient.new(
      MatterhornWhymper.configuration.api(mh_instance)[:protocol],
      MatterhornWhymper.configuration.api(mh_instance)[:domain],
      org_domain,
      MatterhornWhymper.configuration.api(mh_instance)[:user],
      MatterhornWhymper.configuration.api(mh_instance)[:password],
      MatterhornWhymper.configuration.api(mh_instance)[:auth_mode],
      MatterhornWhymper.configuration.api(mh_instance)[:http_timeout],
      MatterhornWhymper.configuration.api(mh_instance)[:ssl_dont_verify_cert],
      MatterhornWhymper.configuration.api(mh_instance)[:multi_tenant] 
    )
  else
    nil
  end
  @response_code = 200
  @response_body = nil
  @error_msg = ''
end

Instance Attribute Details

#response_bodyObject (readonly)

——————————————————————————— attributes —



7
8
9
# File 'lib/matterhorn/endpoint.rb', line 7

def response_body
  @response_body
end

#response_codeObject (readonly)

——————————————————————————— attributes —



7
8
9
# File 'lib/matterhorn/endpoint.rb', line 7

def response_code
  @response_code
end

Class Method Details

.create(endpoint, org_domain = '', mh_instance = :default) ⇒ Object

—————————————————————————– initialization —



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/matterhorn/endpoint.rb', line 12

def self.create(endpoint, org_domain = '', mh_instance = :default)
  if endpoint.respond_to? 'to_s'
    endpoint = endpoint.to_s.capitalize
  else
    raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
                             "#{endpoint.inspect} does not respond to 'to_s'")
  end
  endpoint = Object.const_get('Matterhorn').const_get('Endpoint').
                    const_get(endpoint).new(org_domain, mh_instance)
  if endpoint.nil? || !endpoint.kind_of?(Matterhorn::Endpoint)
    raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
                             "#{endpoint ? endpoint.class.name : 'nil'} is not a sub class " +
                             "of 'Matterhorn::Endpoint'!")
  end
  endpoint
end

.open(endpoint, org_domain = '', mh_instance = :default) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/matterhorn/endpoint.rb', line 30

def self.open(endpoint, org_domain = '', mh_instance = :default)
  endpoint = create(endpoint, org_domain, mh_instance)
  begin
    yield endpoint
  ensure
    endpoint.close
  end
end

Instance Method Details

#closeObject



90
91
92
93
# File 'lib/matterhorn/endpoint.rb', line 90

def close
  http_endpoint_client.close if http_endpoint_client
  http_api_client.close if http_api_client
end

#error_codeObject



80
81
82
# File 'lib/matterhorn/endpoint.rb', line 80

def error_code
  error_occurred? ? response_code : nil
end

#error_msgObject



85
86
87
# File 'lib/matterhorn/endpoint.rb', line 85

def error_msg
  error_occurred? ? @error_msg : ''
end

#error_occurred?Boolean

———————————————————————————– methodes —

Returns:

  • (Boolean)


75
76
77
# File 'lib/matterhorn/endpoint.rb', line 75

def error_occurred?
  response_code >= 400
end