Class: Moceansdk::Modules::AbstractClient

Inherits:
Object
  • Object
show all
Defined in:
lib/moceansdk/modules/abstact_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj_auth, transmitter) ⇒ AbstractClient

Returns a new instance of AbstractClient.



7
8
9
10
# File 'lib/moceansdk/modules/abstact_client.rb', line 7

def initialize(obj_auth, transmitter)
  @params = obj_auth.params
  @transmitter = transmitter
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/moceansdk/modules/abstact_client.rb', line 5

def params
  @params
end

Instance Method Details

#create(params = {}) ⇒ Object



12
13
14
# File 'lib/moceansdk/modules/abstact_client.rb', line 12

def create(params = {})
  @params = @params.merge(params) if params.is_a? Hash
end

#create_final_paramsObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/moceansdk/modules/abstact_client.rb', line 16

def create_final_params
  final_params = {}
  @params.each do |key, value|
    unless value.nil?
      param_prefix_set?(key) ? final_params[key] = value : final_params["mocean-#{key}"] = value
    end
  end

  # convert string hash to symbol hash
  @params = Moceansdk::Utils.convert_to_symbol_hash(final_params)
end

#param_prefix_set?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moceansdk/modules/abstact_client.rb', line 28

def param_prefix_set?(key)
  cloned_key = if key.is_a? String
                 key
               else
                 key.to_s
               end

  return false if cloned_key.scan(/^mocean-/i).empty?

  true
end

#required_field_set?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/moceansdk/modules/abstact_client.rb', line 40

def required_field_set?
  if @required_fields.is_a?(Array) && !@required_fields.empty?
    @required_fields.each do |field|
      if @params[:"#{field}"].nil?
        raise Moceansdk::Exceptions::RequiredFieldException, "#{field} is mandatory field, can't leave empty"
      end
    end
  end

  true
end