Class: OTX::Subscribed

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

Overview

Within the OTX system you are able to subscribe to pulses from other users, this class allows the retreival of the currently subscribed pulse feeds and the associated pulses

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) ⇒ Array

Get all subscribed pulses from the API, get all events in chunks defined by limit

Parameters:

  • limit (Integer) (defaults to: 20)

    Size of chunk of data to be Returned (default = 20)

Returns:

  • (Array)

    Array of OTX::Pulse records



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/otx_ruby/subscribed.rb', line 29

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

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

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

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

  return results
end

#get_since(timestamp, limit = 20) ⇒ Array

Get all subscribed pulses from the API, get all events in chunks defined by limit and since timestamp

Parameters:

  • timestamp (Time)

    Timestamp of point in time to get records since in ISO Format

  • limit (Integer) (defaults to: 20)

    Size of chunk of data to be Returned (default = 20)

Returns:

  • (Array)

    Array of OTX::Pulse records



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/otx_ruby/subscribed.rb', line 58

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

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

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

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

  return results
end

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/otx_ruby/subscribed.rb', line 8

def get_subscribed(limit = 10, page = 1, params = {})
  uri = '/api/v1/pulses/subscribed'
  params['limit'] = limit
  params['page'] = page
  results = []

  json_data = get(uri, params)

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

  return results
end