Class: AppnexusApi::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/appnexusapi/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, service, dbg_info = nil) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
# File 'lib/appnexusapi/resource.rb', line 5

def initialize(json, service, dbg_info = nil)
  @json = json
  @service = service
  @dbg_info = dbg_info
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



25
26
27
28
29
30
31
32
33
# File 'lib/appnexusapi/resource.rb', line 25

def method_missing(sym, *args, &block)
  if @json.respond_to?(sym)
    @json.send(sym, *args, &block)
  elsif @json.has_key?(sym.to_s)
    return @json[sym.to_s]
  else
    super(sym, *args, &block)
  end
end

Instance Attribute Details

#dbg_infoObject (readonly)

Returns the value of attribute dbg_info.



3
4
5
# File 'lib/appnexusapi/resource.rb', line 3

def dbg_info
  @dbg_info
end

Instance Method Details

#delete(route_params = {}) ⇒ Object



17
18
19
# File 'lib/appnexusapi/resource.rb', line 17

def delete(route_params={})
  @service.delete(id, route_params)
end

#raw_jsonObject



21
22
23
# File 'lib/appnexusapi/resource.rb', line 21

def raw_json
  @json
end

#to_sObject



35
36
37
# File 'lib/appnexusapi/resource.rb', line 35

def to_s
  @json.inspect
end

#update(route_params = {}, body_params = {}) ⇒ Object



11
12
13
14
15
# File 'lib/appnexusapi/resource.rb', line 11

def update(route_params={}, body_params={})
  resource = @service.update(id, route_params, body_params)
  @json = resource.raw_json
  self
end