Class: Resourceful::Model::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/resourceful/model/json.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

agent, #attributes, #data, #destroy, find, #new_record?, #save, #update_attributes

Constructor Details

#initialize(json = nil) ⇒ Json

Returns a new instance of Json.



31
32
33
34
# File 'lib/resourceful/model/json.rb', line 31

def initialize(json=nil)
  raise Resourceful::Exceptions::ModelError, "trying to initialize a Resourceful::Model::Json model with '#{json.class.name}' data" unless json.nil? || json.kind_of?(::Hash)
  @data = json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



8
9
10
# File 'lib/resourceful/model/json.rb', line 8

def json
  @json
end

Class Method Details

.get(path, params, force = false, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/resourceful/model/json.rb', line 10

def self.get(path, params, force=false, &block)
  opts = {
    :format => 'json',
    :params => params || {},
    :force => force,
    :on_response => block
  }
  new(super(path, opts))
end

.get_collection(path, params, force = false, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/resourceful/model/json.rb', line 19

def self.get_collection(path, params, force=false, &block)
  opts = {
    :format => 'json',
    :params => params || {},
    :force => force,
    :on_response => block
  }
  super(path, opts) do |data|
    data
  end
end