Class: Apify::Exchange

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExchange

Returns a new instance of Exchange.



7
8
9
10
# File 'lib/apify/exchange.rb', line 7

def initialize
  @value = nil
  @args = nil
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/apify/exchange.rb', line 5

def args
  @args
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/apify/exchange.rb', line 5

def value
  @value
end

Instance Method Details

#respond(args, action) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/apify/exchange.rb', line 12

def respond(args, action)
  # hash_class = defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess : ActiveSupport::HashWithIndifferentAccess
  @args = args.stringify_keys
  validate(@args, action.schema(:args), 'Invalid request args')
  @value = instance_eval(&action.responder) || {}
  @value.stringify_keys!
  validate(@value, action.schema(:value), 'Invalid response value')
  @value
end