lib/intercom/user.rb in intercom-0.1.1 vs lib/intercom/user.rb in intercom-0.1.2

- old
+ new

@@ -233,11 +233,11 @@ # @return [FlatStore] def custom_data=(custom_data) @attributes["custom_data"] = FlatStore.new(custom_data) end - # Custom attributes stored for this Intercom::User + # Company stored for this Intercom::User # # See http://docs.intercom.io/#Companies for more information # # Example: Setting a company for an existing user # user = Intercom::User.find(:email => "someone@example.com") @@ -254,9 +254,32 @@ # # @param [Hash] company # @return [FlatStore] def company=(company) @attributes["company"] = FlatStore.new(company) + end + + # Multiple companies for this Intercom::User + # + # See http://docs.intercom.io/#Companies for more information + # + # Example: Setting a company for an existing user + # user = Intercom::User.find(:email => "someone@example.com") + # user.companies = [{:id => 6, :name => "intercom"}, {:id => 9, :name => "Test Company"}] + # user.save + # + # @return [Array] + def companies + @attributes["companies"] ||= [] + end + + # Set an {Array} of {Hash} company attributes to save/update on this user + # + # @param [Array] companies + # @return [Array] + def companies=(companies) + raise ArgumentError.new("Companies requires an array of hashes of companies") unless companies.is_a?(Array) && companies.all? {|company| company.is_a?(Hash)} + @attributes["companies"] = companies.collect {|company| FlatStore.new(company) } end protected def social_profiles=(social_profiles) #:nodoc: @social_profiles = social_profiles.map { |account| SocialProfile.new(account) }.freeze