Sha256: 2997530a57e166ca0f0e121ffe55a86fa5823c9efc1aef812d3391576bbb5397

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

class Zendesk2::Client::UpdateOrganization < Zendesk2::Client::Request
  request_method :put
  request_path { |r| "/organizations/#{r.organization_id}.json" }
  request_body { |r| { "organization" => r.organization_params } }

  def organization_params
    @_organization_params ||= Cistern::Hash.slice(organization, *Zendesk2::Client::CreateOrganization.accepted_attributes)
  end

  def organization
    params.fetch("organization")
  end

  def organization_id
    organization.fetch("id").to_i
  end

  def mock
    record = self.find!(:organizations, organization_id)

    other_organizations = service.data[:organizations].dup
    other_organizations.delete(organization_id)

    if organization["name"] && other_organizations.values.find { |o| o["name"].downcase == organization["name"].downcase }
      error!(:invalid, details: {"name" => [ { "description" => "Name: has already been taken" } ]})
    end

    if organization["external_id"] && other_organizations.values.find { |o| o["external_id"].to_s.downcase == organization["external_id"].to_s.downcase }
      error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
    end

    record.merge!(organization_params)

    mock_response("organization" => record)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zendesk2-1.7.5 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.7.4 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.7.2 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.7.1 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.7.0 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.6.1 lib/zendesk2/client/requests/update_organization.rb
zendesk2-1.5.17 lib/zendesk2/client/requests/update_organization.rb