Class: OTX::Export

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

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

#get_all(limit = 20) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/otx_ruby/export.rb', line 19

def get_all(limit = 20)
  uri = '/api/v1/indicators/export'
  params = { limit: limit }
  indicators = []
  begin
    json_data = get(uri, params)
    page = json_data['next']

    params = URI::decode_www_form(URI(page).query).to_h unless page.nil?

    indicators += json_data['results']
  end while page && !json_data['results'].empty?

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

  return results
end

#get_export(limit = 10, page = 1, params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/otx_ruby/export.rb', line 3

def get_export(limit = 10, page = 1, params = {})
  uri = '/api/v1/indicators/export'

  params['limit'] = limit
  params['page'] = page
  indicators = []

  json_data = get(uri, params)

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

  return indicators
end

#get_only(list_of_types, limit = 20) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/otx_ruby/export.rb', line 61

def get_only(list_of_types, limit = 20)
  uri = '/api/v1/indicators/export'
  params = { limit: limit, types: list_of_types }
  indicators = []
  begin
    json_data = get(uri, params)
    page = json_data['next']

    params = URI::decode_www_form(URI(page).query).to_h unless page.nil?

    indicators += json_data['results']
  end while page && !json_data['results'].empty?

  results = []
  indicators.each do |indicator|
    results << OTX::Indicator.new(indicator)
  end

  return results
end

#get_only_since(list_of_types, timestamp, limit = 20) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/otx_ruby/export.rb', line 82

def get_only_since(list_of_types, timestamp, limit = 20)
  uri = '/api/v1/indicators/export'
  params = { limit: limit, types: list_of_types, modified_since: timestamp }
  indicators = []
  begin
    json_data = get(uri, params)
    page = json_data['next']

    params = URI::decode_www_form(URI(page).query).to_h unless page.nil?

    indicators += json_data['results']
  end while page && !json_data['results'].empty?

  results = []
  indicators.each do |indicator|
    results << OTX::Indicator.new(indicator)
  end

  return results
end

#get_since(timestamp, limit = 20) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/otx_ruby/export.rb', line 40

def get_since(timestamp, limit = 20)
  uri = '/api/v1/indicators/export'
  params = { limit: limit, modified_since: timestamp }
  indicators = []
  begin
    json_data = get(uri, params)
    page = json_data['next']

    params = URI::decode_www_form(URI(page).query).to_h unless page.nil?

    indicators += json_data['results']
  end while page && !json_data['results'].empty?

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

  return results
end