Module: Solve360::Item
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#created ⇒ Object
Base Item fields.
-
#fields ⇒ Object
Base item collections.
-
#flagged ⇒ Object
Base Item fields.
-
#id ⇒ Object
Base Item fields.
-
#name ⇒ Object
Base Item fields.
-
#ownership ⇒ Object
Base Item fields.
-
#related_items ⇒ Object
Base item collections.
-
#related_items_to_add ⇒ Object
Base item collections.
-
#typeid ⇒ Object
Base Item fields.
-
#updated ⇒ Object
Base Item fields.
-
#viewed ⇒ Object
Base Item fields.
Class Method Summary collapse
Instance Method Summary collapse
- #add_related_item(item) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #map_human_fields ⇒ Object
- #new_record? ⇒ Boolean
-
#save ⇒ Hash
Save the attributes for the current record to the CRM.
- #to_request ⇒ Object
Instance Attribute Details
#created ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def created @created end |
#fields ⇒ Object
Base item collections
14 15 16 |
# File 'lib/solve360/item.rb', line 14 def fields @fields end |
#flagged ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def flagged @flagged end |
#id ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def id @id end |
#name ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def name @name end |
#ownership ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def ownership @ownership end |
#related_items ⇒ Object
Base item collections
14 15 16 |
# File 'lib/solve360/item.rb', line 14 def @related_items end |
#related_items_to_add ⇒ Object
Base item collections
14 15 16 |
# File 'lib/solve360/item.rb', line 14 def @related_items_to_add end |
#typeid ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def typeid @typeid end |
#updated ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def updated @updated end |
#viewed ⇒ Object
Base Item fields
11 12 13 |
# File 'lib/solve360/item.rb', line 11 def viewed @viewed end |
Class Method Details
.included(model) ⇒ Object
4 5 6 7 8 |
# File 'lib/solve360/item.rb', line 4 def self.included(model) model.extend ClassMethods model.send(:include, HTTParty) model.instance_variable_set(:@field_mapping, {}) end |
Instance Method Details
#add_related_item(item) ⇒ Object
96 97 98 |
# File 'lib/solve360/item.rb', line 96 def (item) << item end |
#initialize(attributes = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/solve360/item.rb', line 16 def initialize(attributes = {}) attributes.symbolize_keys! self.fields = {} self. = [] self. = [] [:fields, :related_items].each do |collection| self.send("#{collection}=", attributes[collection]) if attributes[collection] attributes.delete collection end attributes.each do |key, value| self.send("#{key}=", value) end end |
#map_human_fields ⇒ Object
34 35 36 |
# File 'lib/solve360/item.rb', line 34 def map_human_fields self.class.map_human_fields(self.fields) end |
#new_record? ⇒ Boolean
71 72 73 |
# File 'lib/solve360/item.rb', line 71 def new_record? self.id == nil end |
#save ⇒ Hash
Save the attributes for the current record to the CRM
If the record is new it will be created on the CRM
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solve360/item.rb', line 43 def save response = [] if self.ownership.blank? self.ownership = Solve360::Config.config.default_ownership end if new_record? response = self.class.request(:post, "/#{self.class.resource_name}", to_request) if !response["response"]["errors"] self.id = response["response"]["item"]["id"] end else response = self.class.request(:put, "/#{self.class.resource_name}/#{id}", to_request) end if response["response"]["errors"] = response["response"]["errors"].map {|k,v| "#{k}: #{v}" }.join("\n") raise Solve360::SaveFailure, else .concat() response end end |
#to_request ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/solve360/item.rb', line 75 def to_request xml = "<request>" xml << map_human_fields.collect {|key, value| "<#{key}>#{CGI.escapeHTML(value.to_s)}</#{key}>"}.join("") if .size > 0 xml << "<relateditems>" .each do || xml << %Q{<add><relatedto><id>#{["id"]}</id></relatedto></add>} end xml << "</relateditems>" end xml << "<ownership>#{ownership}</ownership>" xml << "</request>" xml end |