Module: TMS::InstanceResource::InstanceMethods

Defined in:
lib/tms_client/instance_resource.rb

Instance Method Summary collapse

Instance Method Details

#deleteObject



123
124
125
# File 'lib/tms_client/instance_resource.rb', line 123

def delete
  process_response(client.delete(self.href), :delete)
end

#getObject



105
106
107
108
# File 'lib/tms_client/instance_resource.rb', line 105

def get
  raise TMS::Errors::InvalidGet if self.new_record?
  process_response(client.get(self.href), :get)
end

#initialize(client, href = nil, attrs = nil) ⇒ Object



98
99
100
101
102
103
# File 'lib/tms_client/instance_resource.rb', line 98

def initialize(client, href=nil, attrs=nil)
  super(client, href)
  @attributes = {}
  attrs ||= self.client.get(href).body if href
  set_attributes_from_hash(attrs) if attrs
end

#postObject



110
111
112
113
# File 'lib/tms_client/instance_resource.rb', line 110

def post
  self.errors = nil
  process_response(client.post(self), :post)
end

#post!Object



115
116
117
# File 'lib/tms_client/instance_resource.rb', line 115

def post!
  self.post or raise TMS::Errors::InvalidPost.new(self)
end

#putObject



119
120
121
# File 'lib/tms_client/instance_resource.rb', line 119

def put
  process_response(client.put(self), :put)
end

#to_jsonObject



131
132
133
134
135
136
137
138
139
140
# File 'lib/tms_client/instance_resource.rb', line 131

def to_json
  json_hash = {}
  self.class.writeable_attributes.each do |attr|
    json_hash[attr] = self.send(attr)
  end
  self.class.collection_attributes.each do |coll|
    json_hash[coll] = self.send(coll).to_json
  end
  json_hash
end

#to_sObject



127
128
129
# File 'lib/tms_client/instance_resource.rb', line 127

def to_s
  "<#{self.class.inspect}#{' href=' + self.href if self.href} attributes=#{@attributes.inspect}>"
end