Module: Zendesk::RestObject::InstanceMethods
- Defined in:
- lib/zendesk/lib/rest_object.rb
Instance Method Summary collapse
Instance Method Details
#load(id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/zendesk/lib/rest_object.rb', line 47 def load(id) begin data = load_data(Zendesk.resource["#{model_name}s/#{id}.xml"].get)[model_name.to_sym] load_attributes(data) load_protected_attributes(data) load_field_entries(data) if respond_to?(:load_field_entries) load_comments(data) if respond_to?(:load_comments) self rescue Exception => e puts e. nil end end |
#model_name ⇒ Object
14 15 16 |
# File 'lib/zendesk/lib/rest_object.rb', line 14 def model_name self.class.to_s.gsub(/^.*::/, '').downcase end |
#reload ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/zendesk/lib/rest_object.rb', line 37 def reload return false unless id begin load(id) rescue Exception => e puts e. nil end end |
#save ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/zendesk/lib/rest_object.rb', line 18 def save begin response = if self.id Zendesk.resource["#{model_name}s/#{id}.xml"].put self.to_xml, :content_type => 'application/xml' else Zendesk.resource["#{model_name}s.xml"].post self.to_xml, :content_type => 'application/xml' end if (200..300).include?(response.headers[:status].to_i) load(id || response.headers[:location].scan(/\d+/).first.to_i) return true else return false end rescue Exception => e puts e. return false end end |