Sha256: 6633f24148d58c6dcb32fd6a304a64e3e38f93adffb47bf46228308b87e27c37

Contents?: true

Size: 1.94 KB

Versions: 33

Compression:

Stored size: 1.94 KB

Contents

require "seatsio/exception"
require "base64"
require "seatsio/httpClient"
require "seatsio/domain"
require "json"
require "cgi"
require "seatsio/domain"

module Seatsio
  class SubaccountsClient
    def initialize(http_client)
      @http_client = http_client
    end

    def create(name: nil)
      body = {}
      body['name'] = name if name

      response = @http_client.post("subaccounts", body)
      Subaccount.new(response)
    end

    def update(id:, name: nil)
      body = {}
      body['name'] = name if name
      @http_client.post("subaccounts/#{id}", body)
    end

    def list(filter: nil)
      extended_cursor = cursor
      extended_cursor.set_query_param('filter', filter)
      extended_cursor
    end

    def active
      cursor status: 'active'
    end

    def inactive
      cursor status: 'inactive'
    end

    def activate(id:)
      @http_client.post("/subaccounts/#{id}/actions/activate")
    end

    def deactivate(id:)
      @http_client.post("/subaccounts/#{id}/actions/deactivate")
    end

    def retrieve(id:)
      response = @http_client.get("/subaccounts/#{id}")
      Subaccount.new(response)
    end

    def copy_chart_to_parent(id: nil, chart_key: nil)
      response = @http_client.post("/subaccounts/#{id}/charts/#{chart_key}/actions/copy-to/parent")
      Chart.new(response)
    end

    def copy_chart_to_subaccount(from_id: nil, to_id: nil, chart_key: nil)
      response = @http_client.post("/subaccounts/#{from_id}/charts/#{chart_key}/actions/copy-to/#{to_id}")
      Chart.new(response)
    end

    def regenerate_secret_key(id:)
      @http_client.post("/subaccounts/#{id}/secret-key/actions/regenerate")
    end

    def regenerate_designer_key(id:)
      @http_client.post("/subaccounts/#{id}/designer-key/actions/regenerate")
    end

    private

    def cursor(status: nil)
      endpoint = status ? "subaccounts/#{status}" : 'subaccounts'
      Pagination::Cursor.new(Subaccount, endpoint, @http_client)
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
seatsio-45.2.0 lib/seatsio/subaccounts.rb
seatsio-45.1.0 lib/seatsio/subaccounts.rb
seatsio-45.0.0 lib/seatsio/subaccounts.rb
seatsio-44.2.0 lib/seatsio/subaccounts.rb
seatsio-44.1.0 lib/seatsio/subaccounts.rb
seatsio-44.0.0 lib/seatsio/subaccounts.rb
seatsio-43.3.0 lib/seatsio/subaccounts.rb
seatsio-43.2.0 lib/seatsio/subaccounts.rb
seatsio-43.1.0 lib/seatsio/subaccounts.rb
seatsio-42.3.0 lib/seatsio/subaccounts.rb
seatsio-42.2.0 lib/seatsio/subaccounts.rb
seatsio-42.1.0 lib/seatsio/subaccounts.rb
seatsio-42.0.0 lib/seatsio/subaccounts.rb
seatsio-41.1.0 lib/seatsio/subaccounts.rb
seatsio-40.1.0 lib/seatsio/subaccounts.rb
seatsio-40.0.0 lib/seatsio/subaccounts.rb
seatsio-39.0.0 lib/seatsio/subaccounts.rb
seatsio-38.0.0 lib/seatsio/subaccounts.rb
seatsio-37.1.0 lib/seatsio/subaccounts.rb
seatsio-37.0.0 lib/seatsio/subaccounts.rb