Class: OneSignal::Notification

Inherits:
OneSignal show all
Defined in:
lib/one_signal/notification.rb

Class Method Summary collapse

Methods inherited from OneSignal

api_key, api_key=, http_object, open_timeout, open_timeout=, read_timeout, read_timeout=, send_delete_request, send_get_request, send_post_request, send_put_request, user_auth_key, user_auth_key=

Class Method Details

.all(params: {}, opts: {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/one_signal/notification.rb', line 5

def self.all(params: {}, opts: {})
  opts[:auth_key] ||= @@api_key

  uri_string = @@base_uri
  uri_string += "/notifications"
  uri = URI.parse(uri_string)

  response = send_get_request(uri: uri, params: params, opts: opts)

  ensure_http_status(response: response,
                     status: '200',
                     method_name: 'All',
                     uri: uri,
                     params: params)

  return response
end

.create(params: {}, opts: {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/one_signal/notification.rb', line 42

def self.create(params: {}, opts: {})
  opts[:auth_key] ||= @@api_key
  
  uri_string = @@base_uri
  uri_string += "/notifications"
  uri = URI.parse(uri_string)

  response = send_post_request(uri: uri, body: params, opts: opts)

  if response.code != '200'
    handle_error(uri: uri, params: params, response: response)
  end

  return response
end

.delete(id: "", params: {}, opts: {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/one_signal/notification.rb', line 77

def self.delete(id: "", params: {}, opts: {})
  opts[:auth_key] ||= @@api_key

  uri_string = @@base_uri
  uri_string += "/notifications"
  uri_string += "/#{id}"
  uri = URI.parse(uri_string)

  response = send_delete_request(uri: uri, params: params, opts: opts)

  ensure_http_status(response: response,
                     status: '200',
                     method_name: 'Delete',
                     uri: uri,
                     params: nil)

  return response
end

.get(id: "", params: {}, opts: {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/one_signal/notification.rb', line 23

def self.get(id: "", params: {}, opts: {})
  opts[:auth_key] ||= @@api_key

  uri_string = @@base_uri
  uri_string += "/notifications"
  uri_string += "/#{id}"
  uri = URI.parse(uri_string)

  response = send_get_request(uri: uri, params: params, opts: opts)

  ensure_http_status(response: response,
                     status: '200',
                     method_name: 'Get',
                     uri: uri,
                     params: nil)

  return response
end

.update(id: "", params: {}, opts: {}) ⇒ Object



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

def self.update(id: "", params: {}, opts: {})
  opts[:auth_key] ||= @@api_key

  uri_string = @@base_uri
  uri_string += "/notifications"
  uri_string += "/#{id}"
  uri = URI.parse(uri_string)

  response = send_put_request(uri: uri, body: params, opts: opts)

  ensure_http_status(response: response,
                     status: '200',
                     method_name: 'Update',
                     uri: uri,
                     params: params)

  return response
end