Sha256: 88b1176b9d6914afeb9041765530169af09bc93e5aac18e6abfa7150d6e0dcb5

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

module Eco
  module API
    class MicroCases
      # It updates an idividual person.
      # @note if it succeeds the update, it calls `person.consolidate!`
      # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
      # @param context [String] main part of the message.
      # @param reason [String] why are we updating now.
      # @return [Boolean] `true` if it succeded to update, and `false` otherwise
      def person_update!(person, context: "Session", reason: "")
        log(:debug) {
          "#{context}, going to \"#{reason}\".\nPerson: #{person_ref(person)}"
        }

        if (response = api.people.update(person))
          if response.success?
            person.consolidate!
            true
          else
            msg  = "#{context} Error #{response.status}: #{response.body}\n"
            msg += " -- Failed to \"#{reason}\".\n"
            msg += "  • Person: #{person_ref(person)}"
            log(:error) { msg }
            false
          end
        else
          msg  = "#{context} Error (connection error)\n"
          msg += " -- Failed to \"#{reason}\".\n"
          msg += "  • Person: #{person_ref(person)}"

          log(:error) { msg }
          false
        end
      end

      private

      def person_ref(person)
        Eco::API::Session::Batch::Feedback.person_ref(person)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.20 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.19 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.18 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.17 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.16 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.15 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.14 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.13 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.12 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.11 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.10 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.9 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.8 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.7 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.6 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.5 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.4 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.3 lib/eco/api/microcases/person_update.rb
eco-helpers-3.0.2 lib/eco/api/microcases/person_update.rb