Class: Karaden::RequestOptions

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequestOptions

Returns a new instance of RequestOptions.



5
6
7
8
9
10
11
12
13
# File 'lib/karaden/request_options.rb', line 5

def initialize
  @api_base = nil
  @api_key = nil
  @api_version = nil
  @tenant_id = nil
  @user_agent = nil
  @connection_timeout = nil
  @read_timeout = nil
end

Instance Attribute Details

#api_baseObject

Returns the value of attribute api_base.



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

def api_base
  @api_base
end

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



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

def api_version
  @api_version
end

#connection_timeoutObject

Returns the value of attribute connection_timeout.



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

def connection_timeout
  @connection_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.



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

def read_timeout
  @read_timeout
end

#tenant_idObject

Returns the value of attribute tenant_id.



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

def tenant_id
  @tenant_id
end

#user_agentObject

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

Class Method Details

.new_builderObject



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

def self.new_builder
  RequestOptionsBuilder.new
end

Instance Method Details

#base_uriObject



15
16
17
# File 'lib/karaden/request_options.rb', line 15

def base_uri
  "#{@api_base}/#{@tenant_id}"
end

#merge(source) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/karaden/request_options.rb', line 19

def merge(source)
  clone.tap do |obj|
    %i[api_base api_key api_version tenant_id user_agent].each do |prop|
      val = source.send(prop)
      obj.send("#{prop}=", val) unless val.nil?
    end
  end
end

#validateObject



28
29
30
31
32
33
34
35
36
37
38
39
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
# File 'lib/karaden/request_options.rb', line 28

def validate
  errors = Karaden::Model::KaradenObject.new
  has_error = false

  messages = validate_api_base
  unless messages.empty?
    errors.set_property('api_base', messages)
    has_error = true
  end

  messages = validate_api_key
  unless messages.empty?
    errors.set_property('api_key', messages)
    has_error = true
  end

  messages = validate_api_version
  unless messages.empty?
    errors.set_property('api_version', messages)
    has_error = true
  end

  messages = validate_tenant_id
  unless messages.empty?
    errors.set_property('tenant_id', messages)
    has_error = true
  end

  if has_error
    e = Karaden::Exception::InvalidRequestOptionsException.new
    error = Karaden::Model::Error.new
    error.set_property('object', Karaden::Model::Error::OBJECT_NAME)
    error.set_property('errors', errors)
    e.error = error
    raise e
  end

  self
end