Class: Posting
- Inherits:
-
SuperModel::Base
- Object
- SuperModel::Base
- Posting
- Defined in:
- lib/models/posting.rb
Overview
posting.to_json # => Array of JSON objects
posting.to_json_for_update # => Array of JSON objects
posting.to_json_for_status_client # => Array of JSON objects
posting.to_json_for_status # => Array of JSON objects
Instance Method Summary collapse
-
#initialize(*params) ⇒ Posting
constructor
A new instance of Posting.
- #to_json ⇒ Object
- #to_json_for_status ⇒ Object
- #to_json_for_status_client ⇒ Object
- #to_json_for_update ⇒ Object
Constructor Details
#initialize(*params) ⇒ Posting
Returns a new instance of Posting.
40 41 42 43 44 45 |
# File 'lib/models/posting.rb', line 40 def initialize(*params) super(*params) @attributes[:images] ||= [] @attributes[:annotations] ||= {} @attributes[:status] ||= StatusUpdateRequest.from_hash(:event => '', :timestump => nil, :attributes => {}, :errors => []) end |
Instance Method Details
#to_json ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/models/posting.rb', line 47 def to_json posting = "{"+'source:'+"'#{self.source}'" + ',category:' + "'#{self.category}'" + ',location:' + "'#{self.location}'" + ',heading:' + "'#{ActiveSupport::JSON.encode(self.heading).to_s[0,254]}'" if self. posting << ",timestamp: '#{(Time.at(self.).utc.to_s(:db)).gsub("-","/")}'" else posting << ",timestamp: '#{(Time.now.utc.to_s(:db)).gsub("-","/")}'" end posting << ',images:' + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]" unless self.body.blank? self.body.gsub!(/[&']/,"") #self.body.gsub!(/\s*<[^>]*>/,"") posting << ',body:' + "'#{ActiveSupport::JSON.encode(self.body)}'" end posting << ',price:' + "#{self.price.to_f}" posting << ',currency:' + "'#{self.currency}'" posting << ',accountName:' + "'#{self.accountName}'" posting << ',accountID:' + "'#{self.accountID}'" posting << ',externalURL:' + "'#{self.externalURL}'" posting << ',externalID:' + "'#{self.externalID}'" if self.annotations annotations = [] self.annotations.each{|k,v| annotations << "#{k}:" + "'#{v}'"} posting << ',annotations:' + "{#{annotations.join(',')}}" end posting + "}" end |
#to_json_for_status ⇒ Object
97 98 99 100 101 102 |
# File 'lib/models/posting.rb', line 97 def to_json_for_status # {source: 'CRAIG', externalID: 3434399120} data = "source:'#{self.source}', " unless self.source.blank? data << "externalID: '#{self.externalID}'" unless self.externalID.blank? data end |
#to_json_for_status_client ⇒ Object
103 104 105 106 107 108 |
# File 'lib/models/posting.rb', line 103 def to_json_for_status_client # source: 'CRAIG', externalID: 3434399120 data = "source:'#{self.source}', " unless self.source.blank? data << "externalID: '#{self.externalID}'" unless self.externalID.blank? data end |
#to_json_for_update ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/models/posting.rb', line 74 def to_json_for_update data = "['#{self.postKey}'," data << "{heading:"+ "'#{ActiveSupport::JSON.encode(self.heading).to_s[0,254]}'" unless self.heading.blank? data << ",images:" + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]" data << ",source:'#{self.source}'" unless self.source.blank? data << ",category:'#{self.category}'" unless self.category.blank? data << ",location:'#{self.location}'" unless self.location.blank? data << ",body:" + "'#{ActiveSupport::JSON.encode self.body}'" unless self.body.blank? data << ',price:' + "'#{self.price}'" data << ',currency:' + "'#{self.currency}'" data << ',accountName:' + "'#{self.accountName}'" data << ',accountID:' + "'#{self.accountID}'" data << ',externalURL:' + "'#{self.externalURL}'" data << ',externalID:' + "'#{self.externalID}'" if self.annotations annotations = [] self.annotations.each{|k,v| annotations << "#{k}:" + "'#{v}'"} data << ",annotations:" + "{#{annotations.join(',')}}" end data << "}" data << "]" end |