Sha256: 868a6d8fc37627ae82291c648686ae1b49b80689408bf0d43f4a7848c01deb23

Contents?: true

Size: 1.68 KB

Versions: 26

Compression:

Stored size: 1.68 KB

Contents

class Zendesk2::Client
  class Real
    def update_user(params={})
      id = params.delete("id")

      request(
        :method => :put,
        :path   => "/users/#{id}.json",
        :body   => {
          "user" => params
        },
      )
    end
  end
  class Mock
    def update_user(params={})
      user_id = params.delete("id")
      path    = "/users/#{user_id}.json"

      if (email = params["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
        response(
          :method => :put,
          :path   => path,
          :status => 422,
          :body   => {
            "error"       => "RecordInvalid",
            "description" => "Record validation errors", "details" => {
            "email"       => [ {
                "description" => "Email #{params["email"]} is already being used by another user"
              } ]
            }
          }
        )
      else
        user_identity_id = self.class.new_id # ugh

        user_identity = {
          "id"         => user_identity_id,
          "url"        => url_for("/users/#{user_id}/identities/#{user_identity_id}.json"),
          "created_at" => Time.now.iso8601,
          "updated_at" => Time.now.iso8601,
          "type"       => "email",
          "value"      => params["email"],
          "verified"   => false,
          "primary"    => false,
          "user_id"    => user_id,
        }

        self.data[:identities][user_identity_id] = user_identity
        body = self.data[:users][user_id].merge!(params)
        response(
          :method => :put,
          :path   => path,
          :body   => {
            "user" => body
          },
        )
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
zendesk2-1.2.2 lib/zendesk2/client/requests/update_user.rb
zendesk2-1.2.1 lib/zendesk2/client/requests/update_user.rb
zendesk2-1.2.0 lib/zendesk2/client/requests/update_user.rb
zendesk2-1.1.3 lib/zendesk2/client/requests/update_user.rb
zendesk2-1.1.2 lib/zendesk2/client/requests/update_user.rb
zendesk2-1.0.0 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.5.4 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.5.3 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.5.2 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.5.1 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.5.0 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.5 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.4 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.3 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.2 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.1 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.4.0 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.3.2 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.3.1 lib/zendesk2/client/requests/update_user.rb
zendesk2-0.3.0 lib/zendesk2/client/requests/update_user.rb