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.



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

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



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 38

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



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

def __api_request
  @api_request
end

#__attr_ref(attr_name) ⇒ Object



62
63
64
65
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 62

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

#__loaded?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 58

def __loaded?
  @loaded
end

#__resultObject



54
55
56
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 54

def __result
  @result
end

#set_error(exception) ⇒ Object



33
34
35
36
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 33

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

#set_result(result) ⇒ Object



28
29
30
31
# File 'lib/facebook_ads/batch_api/batch_proxy.rb', line 28

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