Class: ZohoHub::Notifications

Inherits:
Object
  • Object
show all
Includes:
WithConnection
Defined in:
lib/zoho_hub/notifications.rb

Constant Summary collapse

DEFAULT_RECORDS_PER_PAGE =

Default number of records when fetching all.

200
DEFAULT_PAGE =

Default page number when fetching all.

1
MIN_RECORDS =

Minimum number of records to fetch when fetching all.

2

Class Method Summary collapse

Methods included from WithConnection

#delete, #get, included, #post, #put

Class Method Details

.all(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/zoho_hub/notifications.rb', line 24

def all(params = {})
  params[:page] ||= DEFAULT_PAGE
  params[:per_page] ||= DEFAULT_RECORDS_PER_PAGE
  params[:per_page] = MIN_RECORDS if params[:per_page] < MIN_RECORDS

  body = get(request_path, params)
  return [] if body.nil?

  build_response(body)
end

.build_response(body) ⇒ Object

Raises:



44
45
46
47
48
49
50
51
# File 'lib/zoho_hub/notifications.rb', line 44

def build_response(body)
  response = Response.new(body)

  raise RecordInvalid, response.msg if response.invalid_data?
  raise MandatoryNotFound, response.msg if response.mandatory_not_found?

  response.data
end

.enable(notify_url, channel_id, events, channel_expiry = nil, token = nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/zoho_hub/notifications.rb', line 35

def enable(notify_url, channel_id, events, channel_expiry = nil, token = nil)
  body = post(request_path, watch: [{ notify_url: notify_url,
                                      channel_id: channel_id,
                                      events: events,
                                      channel_expiry: channel_expiry,
                                      token: token }])
  build_response(body)
end

.request_pathObject



20
21
22
# File 'lib/zoho_hub/notifications.rb', line 20

def request_path
  @request_path = 'actions/watch'
end