Sha256: f3194b43763b8468487f7bde1c9cfaf832372cd033bf6fccc83eba966b42d029

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module Calendly
  class Collection
    attr_reader :data, :count, :next_page, :next_page_token, :client

    def self.from_response(response, key:, type:, client:)
      new(
        data: response[key].map { |attrs| type.new(attrs.merge(client: client)) },
        count: response.dig("pagination", "count"),
        next_page: response.dig("pagination", "next_page"),
        client: client
      )
    end

    def initialize(data:, count:, next_page:, client:)
      @data = data
      @count = count
      @next_page = next_page
      @next_page_token = get_params(next_page)["page_token"]&.first
      @client = client
    end

    private

    def get_params(url)
      return {} unless url

      uri = URI.parse(url)
      CGI.parse(uri.query)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
calendlyr-0.3.3 lib/calendly/collection.rb