class Posting

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

Public Class Methods

new(*params) click to toggle source
Calls superclass method
# 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

Public Instance Methods

to_json() click to toggle source
# 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.timestamp
    posting << ",timestamp: '#{(Time.at(self.timestamp).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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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