Class: OTX::Pulses

Inherits:
Base
  • Object
show all
Defined in:
lib/otx_ruby/pulses.rb

Overview

Retrieve and parse into the appropriate object a pulse from the OTX System

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #patch, #post

Constructor Details

This class inherits a constructor from OTX::Base

Instance Method Details

#create(params) ⇒ Object

Create a Pulse

Parameters:

  • params (Hash)

    Parameters to create a Pulse



11
12
13
14
15
16
17
# File 'lib/otx_ruby/pulses.rb', line 11

def create(params)
  uri = '/api/v1/pulses/create'

  pulse = { body: params }

  post(uri, pulse)
end

#edit(id, params) ⇒ Object

Edit a Pulses information

Parameters:

  • id (String)

    The ID of the Pulse

  • param (Hash)

    Parameters to edit



82
83
84
85
86
# File 'lib/otx_ruby/pulses.rb', line 82

def edit(id, params)
  uri = "/api/v1/pulses/#{id}"

  patch(uri, params)
end

#get_indicator_typesArray<OTX::Indicator::IndicatorType>

GET list of Pulse Indicator Types

Returns:



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/otx_ruby/pulses.rb', line 159

def get_indicator_types
  uri = '/api/v1/pulses/indicators/types'
  types = []

  json_data = get(uri)

  json_data['detail'].each do |type|
    types << OTX::Indicator::IndicatorType.new(type)
  end

  return types
end

#get_indicators(id, limit = 10, page = 1) ⇒ Array<OTX::Pulse>

GET a Pulses Indicators

Parameters:

  • id (String)

    ID of the Pulse to retrieve Indicators from

  • limit (Integer) (defaults to: 10)

    Limit results per page to this number

  • page (Integer) (defaults to: 1)

    Return results for this page

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/otx_ruby/pulses.rb', line 140

def get_indicators(id, limit = 10, page = 1)
  uri = "/api/v1/pulses/#{id}/indicators"
  params = { limit: limit, page: page }
  results = []

  json_data = get(uri, params)

  json_data['results'].each do |indicator|
    results << OTX::Indicators.new(indicator)
  end

  return results
end

#get_pulse(id) ⇒ OTX::Pulse

Download an individually identified pulse and parse the output

Parameters:

  • id (String)

    The id value for the pulse to Download

Returns:



36
37
38
39
40
41
42
43
44
# File 'lib/otx_ruby/pulses.rb', line 36

def get_pulse(id)
    uri = "/api/v1/pulses/#{id}"

    json_data = get(uri)

    pulse = OTX::Pulse.new(json_data)

    return pulse
end

GET Pulses that share indicators with a Pulse

Parameters:

  • id (String)

    ID of the Pulse to retrieve related Pulses from

  • limit (Integer) (defaults to: 10)

    Limit results per page to this number

  • page (Integer) (defaults to: 1)

    Return results for this page

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/otx_ruby/pulses.rb', line 118

def get_related(id, limit = 10, page = 1)
  uri = "/api/v1/pulses/#{id}/related"
  params = { limit: limit, page: page }
  results = []

  json_data = get(uri, params)

  json_data['results'].each do |pulse|
    results << OTX::Pulse.new(pulse)
  end

  return results
end

#get_user_pulses(username, limit = 10, page = 1) ⇒ Array<OTX::Pulse>

GET Pulses from a user

Parameters:

  • username (String)

    Name of the User to retrieve pulses from

  • limit (Integer) (defaults to: 10)

    Limit results per page to this number

  • page (Integer) (defaults to: 1)

    Return results for this page

Returns:



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/otx_ruby/pulses.rb', line 96

def get_user_pulses(username, limit = 10, page = 1)
  uri = "/api/v1/pulses/user/#{username}"
  params = { limit: limit, page: page }
  results = []

  json_data = get(uri, params)

  json_data['results'].each do |pulse|
    results << OTX::Pulse.new(pulse)
  end

  return results
end

#search(query, limit = 10, page = 1, sort = :created) ⇒ Array<OTX::Pulse>

Search for Pulses including the query in their datafields

Parameters:

  • query (String)

    Query to search

  • limit (Integer) (defaults to: 10)

    Limit results per page to this number

  • page (Integer) (defaults to: 1)

    Return results for this page

  • sort (Symbol) (defaults to: :created)

    Sort results by modified, created or subscriber_count

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/otx_ruby/pulses.rb', line 55

def search(query, limit = 10, page = 1, sort = :created)
  uri = '/api/v1/search/users'

  if sort == :modified || sort == :subscriber_count
    sort_by = sort.to_s
  else
    sort_by = 'created'
  end

  params = { q: query, limit: limit, page: page, sort: sort_by }
  results = []

  json_data = get(uri, params)

  json_data['results'].each do |pulse|
    results << OTX::Pulse.new(pulse)
  end

  return results
end

#validate_indicator(indicator) ⇒ Object

Validate a Pulse indicator

Parameters:

  • indicator (Hash)

    An indicator key value pair



24
25
26
27
28
# File 'lib/otx_ruby/pulses.rb', line 24

def validate_indicator(indicator)
  uri = '/api/v1/pulses/indicators/validate'

  post(uri, indicator)
end