Module: GovDelivery::TMS::InstanceResource::InstanceMethods
- Defined in:
- lib/govdelivery/tms/instance_resource.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Instance Method Summary collapse
- #delete ⇒ Object
- #delete! ⇒ Object
- #get(params = {}) ⇒ Object (also: #get!)
- #initialize(client, href = nil, attrs = nil) ⇒ Object
- #post ⇒ Object
- #post! ⇒ Object
- #put ⇒ Object
- #put! ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
131 132 133 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 131 def attributes @attributes end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
122 123 124 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 122 def links @links end |
Instance Method Details
#delete ⇒ Object
156 157 158 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 156 def delete process_response(client.delete(href), :delete) end |
#delete! ⇒ Object
160 161 162 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 160 def delete! process_response(client.delete(href), :delete) || fail(GovDelivery::TMS::Errors::InvalidDelete.new(self)) end |
#get(params = {}) ⇒ Object Also known as: get!
133 134 135 136 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 133 def get(params={}) fail GovDelivery::TMS::Errors::InvalidGet if self.new_record? process_response(client.get(href, params), :get) && self end |
#initialize(client, href = nil, attrs = nil) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 124 def initialize(client, href = nil, attrs = nil) super(client, href) @attributes = {} @links = {} set_attributes_from_hash(attrs) if attrs end |
#post ⇒ Object
139 140 141 142 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 139 def post self.errors = nil process_response(client.post(self), :post) end |
#post! ⇒ Object
144 145 146 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 144 def post! post || fail(GovDelivery::TMS::Errors::InvalidPost.new(self)) end |
#put ⇒ Object
148 149 150 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 148 def put process_response(client.put(self), :put) end |
#put! ⇒ Object
152 153 154 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 152 def put! process_response(client.put(self), :put) || fail(GovDelivery::TMS::Errors::InvalidPut.new(self)) end |
#to_json ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 168 def to_json json_hash = {} self.class.writeable_attributes.each do |attr| json_hash[attr] = send(attr) end self.class.collection_attributes.each do |coll| json_hash[coll] = send(coll).to_json end self.class.linkable_attributes.reject { |attr| @links[attr].nil? }.each do |attr| json_hash[:_links] ||= {} json_hash[:_links][attr] = @links[attr] end json_hash.reject do |key, value| value.nil? && !self.class.nullable_attributes.include?(key) end end |
#to_s ⇒ Object
164 165 166 |
# File 'lib/govdelivery/tms/instance_resource.rb', line 164 def to_s "<#{self.class.inspect}#{' href=' + href if href} attributes=#{@attributes.inspect}>" end |