Sha256: d45e44a8ee3932285e06f021a4bc3bdb611f8624df1164e00d19dc650bf9c0a7

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

class Quaderno::Account < Quaderno::Base
  class << self
    undef :delete
  end

  api_model Quaderno::Account
  api_path 'accounts'

  def self.activate(id, options = {})
    setup_account('activate', id, options)
  end

  def self.deactivate(id, options = {})
    setup_account('deactivate', id, options)
  end

  private_class_method def self.setup_account(mode, id, options)
    authentication = get_authentication(options.merge(api_model: api_model))

    response = put("#{authentication[:url]}#{api_model.api_path}/#{id}/#{mode}.json", {
      basic_auth: authentication[:basic_auth],
      headers: default_headers.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
    })

    check_exception_for(response, { rate_limit: true, required_fields: true, subdomain_or_token: true, id: true })

    hash = response.parsed_response
    hash[:authentication_data] = authentication

    object = new hash
    object.rate_limit_info = response

    object
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quaderno-3.0.1 lib/quaderno-ruby/account.rb
quaderno-3.0.0 lib/quaderno-ruby/account.rb