Class: FacebookAds::BatchProxy

Inherits:
BasicObject
Defined in:
lib/facebook_ads/batch_api/batch_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_request) ⇒ BatchProxy

Returns a new instance of BatchProxy.



9
10
11
12
13
14
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 9

def initialize(api_request)
  @api_request = api_request
  @loaded = false
  @result = nil
  @exception = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 26

def method_missing(method_name, *args, &block)
  if @loaded
    if @result
      @result.__send__(method_name, *args, &block)
    else
      ::Object.send(:raise, @exception)
    end
  else
    __attr_ref(method_name)
  end
end

Instance Method Details

#__api_requestObject



38
39
40
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 38

def __api_request
  @api_request
end

#__attr_ref(attr_name) ⇒ Object



50
51
52
53
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 50

def __attr_ref(attr_name)
  # generate JSONPath of the attribute
  "{result=#{__api_request.batch_name}:$.#{attr_name}}"
end

#__loaded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 46

def __loaded?
  @loaded
end

#__resultObject



42
43
44
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 42

def __result
  @result
end

#set_error(exception) ⇒ Object



21
22
23
24
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 21

def set_error(exception)
  @exception = exception
  @loaded = true
end

#set_result(result) ⇒ Object



16
17
18
19
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 16

def set_result(result)
  @result = result
  @loaded = true
end