novu 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Novu
4
+ class Api
5
+ # Module Novu::Api::Subscribers provides an API for managing subscribers in the Novu application.
6
+ #
7
+ # This module includes methods for creating, retrieving, updating, and deleting subscribers.
8
+ # It also includes methods for updating subscriber credentials, online status, preferences etc.
9
+ #
10
+ # For more information on the Novu API(https://api.novu.co/api#/Subscribers), see https://docs.novu.co/api/get-subscribers/.
11
+ module Subscribers
12
+ # Returns a list of subscribers, could paginated using the `page` query parameter
13
+ #
14
+ # @queryparams:
15
+ # @param `page` [Integer(optional)] Number of page for the pagination. The page to fetch, defaults to 0.
16
+ #
17
+ # @return [Hash] The list of subscribers that match the criteria of the query params are successfully returned.
18
+ # @return [number] status
19
+ # - Returns 200 if successful
20
+ def subscribers(query = {})
21
+ get("/subscribers", query: query)
22
+ end
23
+
24
+ # Creates a subscriber entity, in the Novu platform.
25
+ # The subscriber will be later used to receive notifications, and access notification feeds.
26
+ # Communication credentials such as email, phone number, and 3 rd party credentials
27
+ # i.e slack tokens could be later associated to this entity.
28
+ #
29
+ # @bodyparams:
30
+ # @param `subscriberId` [String] The internal identifier you used to create this subscriber, usually correlates to the id the user in your systems.
31
+ # @param `email` [String(optional)]
32
+ # @param `firstName` [String(optional)]
33
+ # @param `lastName` [String(optional)]
34
+ # @param `phone` [String(optional)]
35
+ # @param `avatar` [String(optional)] An http url to the profile image of your subscriber
36
+ # @param `locale` [String(optional)]
37
+ # @param `data` [Hash(optional)]
38
+ #
39
+ # @return [Hash] The hash of subscriber data is successfully returned.
40
+ # @return [number] status - The status code. Returns 201 if the susbscriber has been successfully created.
41
+ def create_subscriber(body)
42
+ post("/subscribers", body: body)
43
+ end
44
+
45
+ # Retrieves the subscriber with the given ID.
46
+ #
47
+ # @pathparams
48
+ # @param `subscribe_id` [String] The ID of the subscriber to retrieve.
49
+ #
50
+ # @return [Hash] The retrieved subscriber.
51
+ # @return [number] status
52
+ # - Returns 200 if the subscriber with the subscriber_id provided exists in the database.
53
+ def subscriber(subscriber_id)
54
+ get("/subscribers/#{subscriber_id}")
55
+ end
56
+
57
+ # Used to update the subscriber entity with new information
58
+ #
59
+ # @pathparams:
60
+ # @param `subscriber_id` [String] The ID of the subscriber to update.
61
+ #
62
+ # @bodyparams
63
+ # @param `email` [String(optional)]
64
+ # @param `firstName` [String(optional)]
65
+ # @param `lastName` [String(optional)]
66
+ # @param `phone` [String(optional)]
67
+ # @param `avatar` [String(optional)]
68
+ # @param `locale` [String(optional)]
69
+ # @param `data` [String(optional)]
70
+ #
71
+ # @return [Hash] The updated subscriber entity.
72
+ # @return [number] status
73
+ # - Returns 200 if the subscriber with the subscriber_id provided has been updated correctly.
74
+ def update_subscriber(subscriber_id, body)
75
+ put("/subscribers/#{subscriber_id}", body: body)
76
+ end
77
+
78
+ # Deletes a subscriber entity from the Novu platform
79
+ #
80
+ # @pathparams:
81
+ # @param `subscriber_id` [String] The ID of the subscriber to delete.
82
+ #
83
+ # @return [Hash] Hash of acknowledged and status.
84
+ # @return [number] status
85
+ # - Returns 200 if the subscriber has been deleted correctly.
86
+ def delete_subscriber(subscriber_id)
87
+ delete("/subscribers/#{subscriber_id}")
88
+ end
89
+
90
+ # Update subscriber credentials from the Novu platform. Subscriber credentials associated to the delivery methods such as slack and push tokens.
91
+ #
92
+ # @pathparams:
93
+ # @param `subscriber_id` [String] The ID of the subscriber to update credentials.
94
+ #
95
+ # @bodyparams:
96
+ # @param `providerId` [String] The provider identifier for the credentials
97
+ # @param `credentials` [Hash] Credentials payload for the specified provider
98
+ #
99
+ # @return [Hash] Hash of updated subscriber credentials entity
100
+ # @return [number] status
101
+ # - Returns 200 if the subscriber credentials has been updated correctly.
102
+ def update_subscriber_credentials(subscriber_id, body)
103
+ put("/subscribers/#{subscriber_id}/credentials", body: body)
104
+ end
105
+
106
+ # Used to update the subscriber isOnline flag.
107
+ #
108
+ # @pathparams:
109
+ # @param `subscriber_id` [String] The ID of the subscriber to update online status.
110
+ #
111
+ # @bodyparams:
112
+ # @param `isOnline` [Boolean]
113
+ #
114
+ # @return [Hash] The updated subscriber entity.
115
+ # @return [number] status
116
+ # - Returns 200 if the subscriber online status has been updated correctly.
117
+ def update_subscriber_online_status(subscriber_id, body)
118
+ patch("/subscribers/#{subscriber_id}/online-status", body: body)
119
+ end
120
+
121
+ # Used to get the subscriber preference
122
+ #
123
+ # @pathparams:
124
+ # @param `subscriber_id` [String] The ID of the subscriber.
125
+ #
126
+ # @return [Hash] Hash of template and preference.
127
+ # @return [number] status
128
+ # - Returns 200 if the subscriber preference has been retrieved successfully.
129
+ def subscriber_preferences(subscriber_id)
130
+ get("/subscribers/#{subscriber_id}/preferences")
131
+ end
132
+
133
+ # Used to update the subscriber preference
134
+ #
135
+ # @pathparams:
136
+ # @param `subscriber_id` [String] The ID of the subscriber to update preference.
137
+ # @param `template_id` [String] The ID of the template to update preference.
138
+ #
139
+ # @bodyparams:
140
+ # @param `channel` [Hash(optional)] The subscriber preferences for every ChannelTypeEnum for the notification template assigned.
141
+ # @param `enabled` [Boolean(optional)] Sets if the notification template is fully enabled for all channels or not for the subscriber.
142
+ #
143
+ # @return [Hash] Hash of template and preference.
144
+ # @return [number] status
145
+ # - Returns 200 if the subscriber preference has been updated correctly.
146
+ def update_subscriber_preference(subscriber_id, template_id, body)
147
+ patch("/subscribers/#{subscriber_id}/preferences/#{template_id}", body: body)
148
+ end
149
+
150
+ # Returns a notification feed for a particular subscriber
151
+ #
152
+ # @pathparams
153
+ # @param `subscriber_id` [String]
154
+ #
155
+ # @queryparams:
156
+ # @param `page` [Integer(optional)] Number of page for the pagination.
157
+ # @param `feedIdentifier` [String]
158
+ # @param `seen` [Boolean(optional)]
159
+ #
160
+ # @return [Hash] List of notification feed of a subscriber that match the criteria of the query params are successfully returned.
161
+ # @return [number] status
162
+ # - Returns 200 if successful
163
+ def subscriber_notification_feed(subscriber_id, query = {})
164
+ get("/subscribers/#{subscriber_id}/notifications/feed", query: query)
165
+ end
166
+
167
+ # Returns the unseen notification count for subscribers feed
168
+ #
169
+ # @pathparams
170
+ # @param `subscriber_id` [String]
171
+ #
172
+ # @queryparams:
173
+ # @param `seen` [Boolean]
174
+ #
175
+ # @return [Hash] the unseen notification count
176
+ # @return [number] status
177
+ # - Returns 200 if successful
178
+ def subscriber_unseen_notification_count(subscriber_id, query = {})
179
+ get("/subscribers/#{subscriber_id}/notifications/unseen", query: query)
180
+ end
181
+
182
+ # Mark a subscriber feed message as seen
183
+ #
184
+ # @pathparams
185
+ # @param `subscriber_id` [String]
186
+ #
187
+ # @bodyparams:
188
+ # @param `messageId` [Hash]
189
+ # @param `mark` [Hash]
190
+ #
191
+ # @return [Hash] the unseen notification count
192
+ # @return [number] status
193
+ # - Returns 201 if successful
194
+ def mark_subscriber_feed_seen(subscriber_id, body)
195
+ post("/subscribers/#{subscriber_id}/messages/markAs", body: body)
196
+ end
197
+
198
+ # Mark message action as seen
199
+ #
200
+ # @pathparams
201
+ # @param `message_id` [String]
202
+ # @param `type` [String]
203
+ # @param `subscriber_id` [String]
204
+ #
205
+ # @return [Hash] the unseen notification count
206
+ # @return [number] status
207
+ # - Returns 201 if successful
208
+ def mark_message_action_seen(subscriber_id, message_id, type)
209
+ post("/subscribers/#{subscriber_id}/messages/#{message_id}/actions/#{type}")
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Novu
4
+ class Api
5
+ # Module Novu::Api::Topics provides an API for managing topics in the Novu application.
6
+ #
7
+ # This module includes methods for creating and retrieving and updating topic.
8
+ # It also includes methods for subscriber addition and removal.
9
+ #
10
+ # For more information on the Novu API(https://api.novu.co/api#/Topics), see https://docs.novu.co/api/topic-creation/.
11
+ module Topics
12
+ # Create a topic
13
+ #
14
+ # @bodyparams:
15
+ # @param `key` [String] User defined custom key and provided by the user that will be an unique identifier for the Topic created.
16
+ # @param `name` [String] User defined custom name and provided by the user that will name the Topic created.
17
+ #
18
+ # @return [number] status - The status code. Returns 201 if the topic has been successfully created.
19
+ def create_topic(body)
20
+ post("/topics", body: body)
21
+ end
22
+
23
+ # Returns a list of topics that can be paginated using the `page` query parameter and
24
+ # filtered by the topic key with the `key` query parameter
25
+ #
26
+ # @queryparams:
27
+ # @param `page` [Integer(optional)] Number of page for the pagination.
28
+ # @param `pageSize` [Integer(optional)] Size of page for the pagination.
29
+ # @param `key` [String(optional)] Topic key.
30
+ #
31
+ # @return [Hash] The list of topics that match the criteria of the query params are successfully returned.
32
+ # @return [number] status
33
+ # - Returns 200 if successful
34
+ def topics(query = {})
35
+ get("/topics", query: query)
36
+ end
37
+
38
+ # Add subscribers to a topic by key
39
+ #
40
+ # @pathparams
41
+ # @param `topic_key` [String]
42
+
43
+ # @bodyparams:
44
+ # @param `subscribers` [Array] List of subscriber identifiers that will be associated to the topic
45
+ #
46
+ # @return [number] status - The status code. Returns 204 if successfully add subscribers to a topic by key.
47
+ def add_subscribers(topic_key, body)
48
+ post("/topics/#{topic_key}/subscribers", body: body)
49
+ end
50
+
51
+ # Remove subscribers from a topic
52
+ #
53
+ # @pathparams
54
+ # @param `topic_key` [String]
55
+
56
+ # @bodyparams:
57
+ # @param `subscribers` [Array] List of subscriber identifiers that will be removed to the topic
58
+ #
59
+ # @return [number] status - The status code. Returns 204 if successfully remove subscribers to a topic by key.
60
+ def remove_subscribers(topic_key, body)
61
+ post("/topics/#{topic_key}/subscribers/removal", body: body)
62
+ end
63
+
64
+ # Get a topic by its topic key
65
+ #
66
+ # @pathparams
67
+ # @param `topic_key` [String]
68
+ #
69
+ # @return [Hash] The retrieved topic.
70
+ # @return [number] status
71
+ # - Returns 200 if successful
72
+ def topic(topic_key)
73
+ get("/topics/#{topic_key}")
74
+ end
75
+
76
+ # Rename a topic by providing a new name
77
+ #
78
+ # @pathparams
79
+ # @param `topic_key` [String]
80
+ #
81
+ # @bodyparams:
82
+ # @param `name` [String] User defined custom name and provided by the user to rename the topic.
83
+ #
84
+ # @return [Hash] Updated topic enitiy.
85
+ # @return [number] status
86
+ # - Returns 200 if successful
87
+ def rename_topic(topic_key, body)
88
+ patch("/topics/#{topic_key}", body: body)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "novu/api/changes"
4
+ require "novu/api/connection"
5
+ require "novu/api/environments"
6
+ require "novu/api/events"
7
+ require "novu/api/execution_details"
8
+ require "novu/api/feeds"
9
+ require "novu/api/inbound_parse"
10
+ require "novu/api/integrations"
11
+ require "novu/api/layouts"
12
+ require "novu/api/messages"
13
+ require "novu/api/notification_groups"
14
+ require "novu/api/notification_templates"
15
+ require "novu/api/notification"
16
+ require "novu/api/subscribers"
17
+ require "novu/api/topics"
18
+
19
+ module Novu
20
+ class Client
21
+ include HTTParty
22
+ include Novu::Api::Changes
23
+ include Novu::Api::Connection
24
+ include Novu::Api::Environments
25
+ include Novu::Api::Events
26
+ include Novu::Api::ExecutionDetails
27
+ include Novu::Api::Feeds
28
+ include Novu::Api::InboundParse
29
+ include Novu::Api::Integrations
30
+ include Novu::Api::Layouts
31
+ include Novu::Api::Messages
32
+ include Novu::Api::NotificationGroups
33
+ include Novu::Api::NotificationTemplates
34
+ include Novu::Api::Notification
35
+ include Novu::Api::Subscribers
36
+ include Novu::Api::Topics
37
+
38
+ base_uri "https://api.novu.co/v1"
39
+ format :json
40
+
41
+ def initialize(access_token = nil)
42
+ raise ArgumentError, "Api Key cannot be blank or nil" if access_token.blank?
43
+
44
+ @access_token = access_token.to_s.strip
45
+ self.class.default_options.merge!(headers: { "Authorization" => "ApiKey #{@access_token}" })
46
+ rescue ArgumentError => e
47
+ puts "Error initializing Novu client: #{e.message}"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Novu
4
+ VERSION = "0.1.0"
5
+ end
data/lib/novu.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/hash"
4
+ require "httparty"
5
+ require_relative "novu/version"
6
+ require_relative "novu/client"
7
+
8
+ module Novu
9
+ # class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
data/sig/novu.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Novu
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: novu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aman Saini
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: httparty
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: activesupport
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Client library for Novu API.
42
+ email:
43
+ - amansaini0003@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - lib/novu.rb
58
+ - lib/novu/api/changes.rb
59
+ - lib/novu/api/connection.rb
60
+ - lib/novu/api/environments.rb
61
+ - lib/novu/api/events.rb
62
+ - lib/novu/api/execution_details.rb
63
+ - lib/novu/api/feeds.rb
64
+ - lib/novu/api/inbound_parse.rb
65
+ - lib/novu/api/integrations.rb
66
+ - lib/novu/api/layouts.rb
67
+ - lib/novu/api/messages.rb
68
+ - lib/novu/api/notification.rb
69
+ - lib/novu/api/notification_groups.rb
70
+ - lib/novu/api/notification_templates.rb
71
+ - lib/novu/api/subscribers.rb
72
+ - lib/novu/api/topics.rb
73
+ - lib/novu/client.rb
74
+ - lib/novu/version.rb
75
+ - sig/novu.rbs
76
+ homepage: https://github.com/amansaini0003/ruby-novu
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/amansaini0003/ruby-novu
81
+ source_code_uri: https://github.com/amansaini0003/ruby-novu
82
+ changelog_uri: https://github.com/amansaini0003/ruby-novu/blob/main/CHANGELOG.md
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.6.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.2.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Client library for Novu API.
102
+ test_files: []