Class: Nzbn::Api::Watchlists

Inherits:
Object
  • Object
show all
Defined in:
lib/nzbn/api/watchlists.rb

Overview

Watchlists API - Manage change notification watchlists

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Watchlists

Returns a new instance of Watchlists.



7
8
9
# File 'lib/nzbn/api/watchlists.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#add_nzbns(watchlist_id:, nzbns:) ⇒ Boolean

Add NZBNs to a watchlist

Parameters:

  • watchlist_id (String)

    Watchlist ID

  • nzbns (Array<String>)

    NZBNs to add

Returns:

  • (Boolean)

    True if successful



103
104
105
106
# File 'lib/nzbn/api/watchlists.rb', line 103

def add_nzbns(watchlist_id:, nzbns:)
  @client.post("/watchlists/#{watchlist_id}/nzbns", { nzbns: nzbns })
  true
end

#create(watchlist:) ⇒ Models::Watchlist

Create a new watchlist

Examples:

client.watchlists.create(watchlist: {
  name: 'My Watchlist',
  channel: 'EMAIL',
  frequency: 'DAILY',
  changeEventTypes: 'ALL',
  adminEmailAddress: 'admin@example.com'
})

Parameters:

  • watchlist (Hash)

    Watchlist attributes

Returns:



61
62
63
64
# File 'lib/nzbn/api/watchlists.rb', line 61

def create(watchlist:)
  response = @client.post('/watchlists', watchlist)
  Models::Watchlist.new(response)
end

#delete(watchlist_id:) ⇒ Boolean

Delete a watchlist

Parameters:

  • watchlist_id (String)

    Watchlist ID

Returns:

  • (Boolean)

    True if successful



82
83
84
85
# File 'lib/nzbn/api/watchlists.rb', line 82

def delete(watchlist_id:)
  @client.delete("/watchlists/#{watchlist_id}")
  true
end

#get(watchlist_id:) ⇒ Models::Watchlist

Get a watchlist by ID

Parameters:

  • watchlist_id (String)

    Watchlist ID

Returns:



42
43
44
45
# File 'lib/nzbn/api/watchlists.rb', line 42

def get(watchlist_id:)
  response = @client.get("/watchlists/#{watchlist_id}")
  Models::Watchlist.new(response)
end

#list(name: nil, organisation_id: nil, page: nil, page_size: nil, sort_by: nil, sort_order: nil, change_event_types: nil) ⇒ Models::SearchResponse

List watchlists

Parameters:

  • name (String) (defaults to: nil)

    Filter by name (partial match)

  • organisation_id (String) (defaults to: nil)

    Filter by organisation ID

  • page (Integer) (defaults to: nil)

    Page number

  • page_size (Integer) (defaults to: nil)

    Results per page

  • sort_by (String) (defaults to: nil)

    Sort field

  • sort_order (String) (defaults to: nil)

    ASC or DESC

  • change_event_types (String) (defaults to: nil)

    Filter by change event types

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nzbn/api/watchlists.rb', line 22

def list(name: nil, organisation_id: nil, page: nil, page_size: nil,
         sort_by: nil, sort_order: nil, change_event_types: nil)
  params = {}
  params['name'] = name if name
  params['organisation-id'] = organisation_id if organisation_id
  params['page'] = page if page
  params['page-size'] = page_size if page_size
  params['sort-by'] = sort_by if sort_by
  params['sortorder'] = sort_order if sort_order
  params['change-event-types'] = change_event_types if change_event_types

  response = @client.get('/watchlists', params)
  Models::SearchResponse.new(response, item_class: Models::Watchlist)
end

#list_nzbns(watchlist_id:) ⇒ Array<String>

List NZBNs in a watchlist

Parameters:

  • watchlist_id (String)

    Watchlist ID

Returns:

  • (Array<String>)

    List of NZBNs



92
93
94
95
# File 'lib/nzbn/api/watchlists.rb', line 92

def list_nzbns(watchlist_id:)
  response = @client.get("/watchlists/#{watchlist_id}/nzbns")
  response['nzbns'] || []
end

#remove_nzbns(watchlist_id:, nzbns:) ⇒ Boolean

Remove NZBNs from a watchlist

Parameters:

  • watchlist_id (String)

    Watchlist ID

  • nzbns (Array<String>)

    NZBNs to remove

Returns:

  • (Boolean)

    True if successful



114
115
116
117
# File 'lib/nzbn/api/watchlists.rb', line 114

def remove_nzbns(watchlist_id:, nzbns:)
  @client.delete("/watchlists/#{watchlist_id}/nzbns", { nzbns: nzbns })
  true
end

#update(watchlist_id:, watchlist:) ⇒ Models::Watchlist

Update a watchlist

Parameters:

  • watchlist_id (String)

    Watchlist ID

  • watchlist (Hash)

    Updated watchlist attributes

Returns:



72
73
74
75
# File 'lib/nzbn/api/watchlists.rb', line 72

def update(watchlist_id:, watchlist:)
  response = @client.put("/watchlists/#{watchlist_id}", watchlist)
  Models::Watchlist.new(response)
end