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



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

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

#deleteObject



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

def delete
  @service.delete(id)
end

#raw_jsonObject



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

def raw_json
  @json
end

#to_sObject



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

def to_s
  @json.inspect
end

#update(attributes = {}) ⇒ Object



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

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