Sha256: 15c8797a167f33c22cfeb86540bbd28c0cc6f4ad4c6394140f233609750ec007

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

require_relative 'connect_token'
require_relative 'api/resource_collection'

class ContextIO
  # Represents a collection of connect tokens for your account. You can use this
  # to create a new token, fetch a specific one or iterate over them.
  #
  # @example You can iterate over them with `each`:
  #   contextio.connect_tokens.each do |connect_token|
  #     puts connect_token.email
  #   end
  #
  # @example You can lazily access a specific one with square brackets:
  #   connect_token = contextio.connect_tokens['some_token']
  class ConnectTokenCollection
    include ContextIO::API::ResourceCollection

    self.resource_class = ContextIO::ConnectToken
    self.association_name = :connect_tokens

    belongs_to :account

    # Creates a new connect token for your account.
    #
    # @param [String] callback_url The url that the user will be redirected to
    #   after OAuthing their account with Context.IO.
    # @param [Hash{String, Symbol => String}] options Optional information you
    #   can provide at creation: email, service level, first_name and/or
    #   last_name.
    #
    # @return [ConnectToken] A new token instance based on the data you input.
    def create(callback_url, options={})
      result_hash = api.request(
        :post,
        resource_url,
        options.merge(callback_url: callback_url)
      )

      result_hash.delete('success')

      resource_class.new(api, result_hash)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contextio-2.0.0 lib/contextio/connect_token_collection.rb
contextio-1.8.1 lib/contextio/connect_token_collection.rb
contextio-1.8.0 lib/contextio/connect_token_collection.rb
contextio-1.7.2 lib/contextio/connect_token_collection.rb
contextio-1.7.1 lib/contextio/connect_token_collection.rb
contextio-1.7.0 lib/contextio/connect_token_collection.rb
contextio-1.6.0 lib/contextio/connect_token_collection.rb
contextio-1.5.0 lib/contextio/connect_token_collection.rb
contextio-1.4.0 lib/contextio/connect_token_collection.rb
contextio-1.3.0 lib/contextio/connect_token_collection.rb
contextio-1.2.4 lib/contextio/connect_token_collection.rb
contextio-1.2.3 lib/contextio/connect_token_collection.rb
contextio-1.2.2 lib/contextio/connect_token_collection.rb
contextio-1.2.1 lib/contextio/connect_token_collection.rb
contextio-1.2.0 lib/contextio/connect_token_collection.rb
contextio-1.1.0 lib/contextio/connect_token_collection.rb
contextio-1.0.1 lib/contextio/connect_token_collection.rb
contextio-1.0.0 lib/contextio/connect_token_collection.rb