Class: AppnexusApi::Resource

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

Instance Method Summary collapse

Constructor Details

#initialize(json, service) ⇒ Resource

Returns a new instance of Resource.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



21
22
23
24
25
26
27
28
29
# File 'lib/appnexusapi/resource.rb', line 21

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 Method Details

#deleteObject



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

def delete
  @service.delete(id)
end

#raw_jsonObject



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

def raw_json
  @json
end

#to_sObject



31
32
33
# File 'lib/appnexusapi/resource.rb', line 31

def to_s
  @json.inspect
end

#update(attributes = {}) ⇒ Object



8
9
10
11
# File 'lib/appnexusapi/resource.rb', line 8

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