Sha256: e445cc047493241723dd94aa8b6251eaffe2e4d5618a2eeff39b956594cd2fd1

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

module FlexmlsApi
  module Models
    class Contact < Base
      extend Finders
      self.element_name="contacts"
      
      def save(arguments={})
        self.errors = [] # clear the errors hash
        begin
          return save!(arguments)
        rescue BadResourceRequest => e
          self.errors << {:code => e.code, :message => e.message}
          FlexmlsApi.logger.error("Failed to save resource #{self}: #{e.message}")
        rescue NotFound => e
          FlexmlsApi.logger.error("Failed to save resource #{self}: #{e.message}")
        end
        false
      end
      def save!(arguments={})
        results = connection.post self.class.path, {"Contacts" => [ attributes ], "Notify" => notify? }, arguments
        result = results.first
        attributes['ResourceUri'] = result['ResourceUri']
        attributes['Id'] = parse_id(result['ResourceUri'])
        true
      end
      
      def self.by_tag(tag_name, arguments={})
        collect(connection.get("#{path}/tags/#{tag_name}", arguments))
      end

      def self.tags(arguments={})
        connection.get("#{path}/tags", arguments)
      end

      def self.my(arguments={})
        new(connection.get('/my/contact', arguments).first)
      end
            
      # Notify the agent of contact creation via a flexmls message.
      def notify?
        @notify == true
      end
      def notify=(notify_me=true)
        @notify = notify_me
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
spark_api-1.0.2 lib/spark_api/models/contact.rb~
spark_api-1.0.1 lib/spark_api/models/contact.rb~
spark_api-1.0.0 lib/spark_api/models/contact.rb~
flexmls_api-0.7.3 lib/flexmls_api/models/contact.rb
flexmls_api-0.7.5 lib/flexmls_api/models/contact.rb