Class: SonyCameraRemoteAPI::CameraAPIGroupManager::APIGroup

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

Overview

APIGroup class. One API group object represents one camera parameter.

Instance Method Summary collapse

Constructor Details

#initialize(param_symbol, supported_accessor, available_accessor, get_accessor, set_accessor, start_condition: nil, preprocess_value: nil, check_equality: method(:default_check_equality), check_availability: method(:default_check_availability), end_condition: nil) ⇒ APIGroup

Create API group object.

Parameters:

  • param_symbol (Symbol)

    API Group name

  • supported_accessor (Proc)

    Get the supported values from getSupportedXXX raw response.

  • available_accessor (Proc)

    Get the available values from getAvailableXXX raw response.

  • get_accessor (Proc)

    Get the current value from getXXX raw response.

  • set_accessor (Proc)

    Set given value to setXXX request.

  • start_condition (Proc)

    Wait until given condition before accessing parameter.

  • preprocess_value (Proc)

    Convert given value and arguments into the internal format to be compared.

  • check_equality (Proc)

    Compare given value and current one to judge whether new value should be set or not.

  • check_availability (Proc)

    Compare given value and avialable ones to judge whether new value is available.

  • end_condition (Proc)

    Wait until given condition after changing parameter.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 25

def initialize(param_symbol, supported_accessor, available_accessor, get_accessor, set_accessor,
               start_condition: nil,
               preprocess_value: nil,
               check_equality: method(:default_check_equality),
               check_availability: method(:default_check_availability),
               end_condition: nil
               )
  @param_str = param_symbol.to_s
  @supported = ('getSupported' + @param_str).to_sym
  @supported_accessor = supported_accessor
  @available = ('getAvailable' + @param_str).to_sym
  @available_accessor = available_accessor
  @get = ('get' + @param_str).to_sym
  @get_accessor = get_accessor
  @set = ('set' + @param_str).to_sym
  @set_accessor = set_accessor
  @start_condition = start_condition
  @preprocess_value = preprocess_value
  @check_equality = check_equality
  @check_availability = check_availability
  @end_condition = end_condition
end

Instance Method Details

#available_values(api_manager, condition, **opts) ⇒ Object

Get available values of this parameter through the defined accessor

Parameters:


59
60
61
62
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 59

def available_values(api_manager, condition, **opts)
  raw_result = api_manager.send(@available, **opts)['result']
  { available: @available_accessor.call(raw_result, condition) }
end

#current_value(api_manager, condition, **opts) ⇒ Object

Get current values of this parameter through the defined accessor


65
66
67
68
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 65

def current_value(api_manager, condition, **opts)
  raw_result = api_manager.send(@get, **opts)['result']
  { current: @get_accessor.call(raw_result, condition) }
end

#eq_current?(value, current_value, condition) ⇒ Boolean

Returns:

  • (Boolean)

95
96
97
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 95

def eq_current?(value, current_value, condition)
  @check_equality.call(value, current_value, condition)
end

#is_available?(value, available_values, condition) ⇒ Boolean

Returns:

  • (Boolean)

90
91
92
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 90

def is_available?(value, available_values, condition)
  @check_availability.call(value, available_values, condition)
end

#preprocess_value(value, args, condition) ⇒ Object

Preprocess given value and arguments to the value which can be compared.

Parameters:

  • value (Object)
  • args (Array)
  • condition (Array<Hash>)

82
83
84
85
86
87
88
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 82

def preprocess_value(value, args, condition)
  if @preprocess_value
    @preprocess_value.call(value, args, condition)
  else
    value
  end
end

#set_value(api_manager, value, availables, condition) ⇒ Object

Parameters:


103
104
105
106
107
108
109
110
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 103

def set_value(api_manager, value, availables, condition)
  api_manager.send(@set, @set_accessor.call(value, availables, condition))
  if @end_condition
    condition_block = (@end_condition.curry)[value]
    api_manager.wait_event &condition_block
  end
  { current: value }
end

#start_condition(api_manager, **opts) ⇒ Object

If start_condition is defined, wait until the condition satisfies.

Parameters:


72
73
74
75
76
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 72

def start_condition(api_manager, **opts)
  if @start_condition
    api_manager.wait_event { |r| @start_condition.call(r) }
  end
end

#supported_values(api_manager, condition, **opts) ⇒ Object

Get suported values of this parameter through the defined accessor

Parameters:


51
52
53
54
# File 'lib/sony_camera_remote_api/camera_api_group.rb', line 51

def supported_values(api_manager, condition, **opts)
  raw_result = api_manager.send(@supported, **opts)['result']
  { supported: @supported_accessor.call(raw_result, condition) }
end