Sha256: 6892fe902edc5dfdc483edff35a527808c1b76650a805839c4fff4920d9bbc77

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

require 'contextio/api/resource'

class ContextIO
  class Source
    include ContextIO::API::Resource

    self.primary_key = :label
    self.association_name = :source

    belongs_to :account
    has_many :folders

    lazy_attributes :server, :label, :username, :port, :authentication_type,
                    :status, :service_level, :sync_period, :use_ssl, :type
    private :use_ssl

    # @!attribute [r] use_ssl?
    #   @return [Boolean] Whether or not this source uses SSL.
    def use_ssl?
      use_ssl
    end

    # Updates the source.
    #
    # @params [Hash{String, Symbol => String}] options You can update the
    #   following: status, sync_period, service_level, password, provider_token,
    #   provider_token_secret, provider_consumer_key. See the Context.IO docs
    #   for more details on these fields.
    def update(options={})
      updatable_attrs = %w(status sync_period service_level password
                           provider_token provider_token_secret
                           provider_consumer_key)

      options.keep_if do |key, value|
        updatable_attrs.include?(key.to_s)
      end

      return nil if options.empty?

      it_worked = api.request(:post, resource_url, options)['success']

      if it_worked
        options.each do |key, value|
          instance_variable_set("@#{key}", value)
        end
      end

      it_worked
    end

    def delete
      api.request(:delete, resource_url)['success']
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contextio-1.2.1 lib/contextio/source.rb
contextio-1.2.0 lib/contextio/source.rb
contextio-1.1.0 lib/contextio/source.rb
contextio-1.0.1 lib/contextio/source.rb
contextio-1.0.0 lib/contextio/source.rb