Class: DataSift::ManagedSource

Inherits:
ApiResource show all
Defined in:
lib/managed_source.rb

Overview

Methods for using href="http://dev.datasift.com/docs/sources/managed-sources">dev.datasift.com/docs/sources/managed-sources

DataSift Managed Sources

Constant Summary

Constants inherited from ApiResource

ApiResource::TLSv1, ApiResource::TLSv1_2

Constants included from DataSift

APPLICATION_JSON, DELETE, DETECT_DEAD_SOCKETS, GET, HEAD, IS_WINDOWS, KNOWN_SOCKETS, SOCKET_DETECTOR_TIMEOUT, VERSION, X_ANALYSIS_TASKS_QUEUED, X_ANALYSIS_TASKS_QUEUE_LIMIT, X_INSIGHT_TASKS_QUEUED, X_INSIGHT_TASKS_QUEUE_LIMIT, X_RATELIMIT_COST, X_RATELIMIT_LIMIT, X_RATELIMIT_REMAINING, X_TASKS_QUEUED, X_TASKS_QUEUE_LIMIT

Instance Method Summary collapse

Methods inherited from ApiResource

#initialize, #requires

Methods included from DataSift

#build_path, request

Constructor Details

This class inherits a constructor from DataSift::ApiResource

Instance Method Details

#create(source_type, name, parameters = {}, resources = [], auth = [], options = {}) ⇒ Object

Creates a new managed source

Parameters:

  • source_type (String)

    Type of Managed Source you are creating. e.g. facebook_page, instagram, etc

  • name (String)

    Name of this Managed Source

  • parameters (Hash) (defaults to: {})

    Source-specific configuration parameters

  • resources (Array) (defaults to: [])

    Array of source-specific resources

  • auth (Array) (defaults to: [])

    Array of source-specific auth credentials



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/managed_source.rb', line 13

def create(source_type, name, parameters = {}, resources = [], auth = [], options = {})
  fail BadParametersError, 'source_type and name are required' if source_type.nil? || name.nil?
  params = {
    :source_type => source_type,
    :name => name
  }
  params.merge!(options) unless options.empty?
  params.merge!(
    { :auth => auth.is_a?(String) ? auth : MultiJson.dump(auth) }
  ) unless auth.empty?
  params.merge!(
    { :parameters => parameters.is_a?(String) ? parameters : MultiJson.dump(parameters) }
  ) unless parameters.empty?
  params.merge!(
    { :resources => resources.is_a?(String) ? resources : MultiJson.dump(resources) }
  ) if resources.length > 0
  DataSift.request(:POST, 'source/create', @config, params)
end

#delete(id) ⇒ Object

Delete a Managed Source

Parameters:

  • id (String)

    ID of the Managed Source you are deleting



58
59
60
61
# File 'lib/managed_source.rb', line 58

def delete(id)
  fail BadParametersError, 'ID is required' if id.nil?
  DataSift.request(:DELETE, 'source/delete', @config, { :id => id })
end

#get(id = nil, source_type = nil, page = 1, per_page = 20) ⇒ Object

Retrieve details of a Managed Source

Parameters:

  • id (String) (defaults to: nil)

    ID of the Managed Source you are getting. Omitting the ID will return a list of Managed Sources

  • source_type (String) (defaults to: nil)

    Limits the list of Managed Sources returned to only sources of a specific source type if specified

  • page (Integer) (defaults to: 1)

    Number of Managed Sources to return on one page of results

  • per_page (Integer) (defaults to: 20)

    Number of Managed Sources to return per page



88
89
90
91
92
93
94
# File 'lib/managed_source.rb', line 88

def get(id = nil, source_type = nil, page = 1, per_page = 20)
  params = { :page => page, :per_page => per_page }
  params.merge!({ :id => id }) if !id.nil?
  params.merge!({ :source_type => source_type }) if !source_type.nil?

  DataSift.request(:GET, 'source/get', @config, params)
end

#log(id, page = 1, per_page = 20) ⇒ Object

Retrieve log details of Managed Sources

Parameters:

  • id (String)

    ID of the Managed Source for which you are collecting logs

  • page (Integer) (defaults to: 1)

    Number of Managed Source logs to return on one page of results

  • per_page (Integer) (defaults to: 20)

    Number of Managed Source logs to return per page



103
104
105
106
# File 'lib/managed_source.rb', line 103

def log(id, page = 1, per_page = 20)
  fail BadParametersError, 'ID is required' if id.nil?
  DataSift.request(:POST, 'source/log', @config, { :id => id, :page => page, :per_page => per_page })
end

#start(id) ⇒ Object

Start a Managed Source

Parameters:

  • id (String)

    ID of the Managed Source you are starting



74
75
76
77
# File 'lib/managed_source.rb', line 74

def start(id)
  fail BadParametersError, 'ID is required' if id.nil?
  DataSift.request(:POST, 'source/start', @config, { :id => id })
end

#stop(id) ⇒ Object

Stop a Managed Source

Parameters:

  • id (String)

    ID of the Managed Source you are stopping



66
67
68
69
# File 'lib/managed_source.rb', line 66

def stop(id)
  fail BadParametersError, 'ID is required' if id.nil?
  DataSift.request(:POST, 'source/stop', @config, { :id => id })
end

#update(id, source_type, name, parameters = {}, resources = [], auth = [], options = {}) ⇒ Object

Update a Managed Source

Parameters:

  • id (String)

    ID of the Managed Source you are updating

  • source_type (String)

    Type of Managed Source you are updating

  • name (String)

    Name (or new name) of the Managed Source

  • parameters (Hash) (defaults to: {})

    Source-specific configuration parameters

  • resources (Array) (defaults to: [])

    Array of source-specific resources

  • auth (Array) (defaults to: [])

    Array of source-specific auth credentials



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/managed_source.rb', line 40

def update(id, source_type, name, parameters = {}, resources = [], auth = [], options = {})
  fail BadParametersError, 'ID, source_type and name are required' if id.nil? || source_type.nil? || name.nil?
  params = {
    :id => id,
    :source_type => source_type,
    :name => name
  }
  params.merge!(options) unless options.empty?
  params.merge!({:auth => MultiJson.dump(auth)}) if !auth.empty?
  params.merge!({:parameters => MultiJson.dump(parameters)}) if !parameters.empty?
  params.merge!({:resources => MultiJson.dump(resources)}) if resources.length > 0

  DataSift.request(:POST, 'source/update', @config, params)
end