appilix_notifications 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd27db8d08672883c506ed63f2a4558c1ba5e7a6cf6fad9ebd112b36de9f22b3
4
- data.tar.gz: 2da58a031ee5afd246f7b5681e44e52274ba89c12152349774f1cee89ed82b01
3
+ metadata.gz: 993a291ad2f0f97f3de0cd8a6d6f86fcf1e059db62ad03a541bfdf20c2c2f7b5
4
+ data.tar.gz: acfc393b5e518aa54d0b1242bb002f2e3446157a82dffcc5e950e780c79d7b1d
5
5
  SHA512:
6
- metadata.gz: d3f940395b95c525891064db8256681ba463eaf969d43727233e7836d4f334fced4ac9f405ee20a717a39b70b7ac1a523af5acb42c64d6221dfc310560f7c947
7
- data.tar.gz: 9f227ddd7ba6817cb112fa05b295fbad1b49e9da7c000de4385e0aacfd534cc7def053951bcb9ec9d0ad0d88973c8d529deb6eeb0610715f5a4d9fe155052ec3
6
+ metadata.gz: 2f5d6d6a14ddcd7de2f784bd962b3544f0b0eb2da99c9ee58fa87d36d340c0c539b9e8579d6554ac37f64936a41f8ce0eb23959fb2eafc20da92d70b089d7638
7
+ data.tar.gz: 5fd69e72ab797f26954440566cac881a4014f68723cc65e7c0dbcf8b62babd27778d3ab9564b0f76e5460b5a18be5b382e5e815aab225baecf9de8fef412618a
data/Gemfile.lock CHANGED
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appilix_notifications (0.1.0)
4
+ appilix_notifications (0.1.1)
5
+ json (~> 2.0)
6
+ net-http (>= 0.1.1)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
@@ -11,6 +13,11 @@ GEM
11
13
  json (2.9.1)
12
14
  language_server-protocol (3.17.0.3)
13
15
  lint_roller (1.1.0)
16
+ net-http (0.10.0)
17
+ net-protocol (>= 0.3.0)
18
+ uri (>= 0.11.1)
19
+ net-protocol (0.4.0)
20
+ timeout
14
21
  parallel (1.26.3)
15
22
  parser (3.3.7.0)
16
23
  ast (~> 2.4.1)
@@ -63,9 +70,11 @@ GEM
63
70
  rubocop-performance (~> 1.23.0)
64
71
  test-unit (3.6.7)
65
72
  power_assert
73
+ timeout (0.6.1)
66
74
  unicode-display_width (3.1.4)
67
75
  unicode-emoji (~> 4.0, >= 4.0.4)
68
76
  unicode-emoji (4.0.4)
77
+ uri (1.1.2)
69
78
 
70
79
  PLATFORMS
71
80
  ruby
data/README.md CHANGED
@@ -30,8 +30,11 @@ response = AppilixNotifications.appilix_send_notifications(
30
30
  'your_api_key',
31
31
  'Your Notification Title',
32
32
  'Your Notification Body',
33
- 'optional_user_identity', # Optional
34
- 'https://example.com' # Optional
33
+ 'optional_user_identity', # Optional; use "user-1::user-2" for multiple users
34
+ 'https://example.com', # Optional
35
+ notification_image: 'https://example.com/banner.png', # Optional; Android only
36
+ secondary_app_key: 'your_ios_app_key', # Optional
37
+ secondary_api_key: 'your_ios_api_key' # Optional
35
38
  )
36
39
 
37
40
  puts response
@@ -44,6 +47,11 @@ puts response
44
47
  - `body` (String): The body content of the notification.
45
48
  - `user_identity` (String, optional): The user identifier for the notification.
46
49
  - `open_link_url` (String, optional): A URL to open when the notification is clicked.
50
+ - `notification_image` (String, optional keyword): A public image URL (Android only).
51
+ - `secondary_app_key` (String, optional keyword): The app key for a second app, such as iOS.
52
+ - `secondary_api_key` (String, optional keyword): The API key for the second app.
53
+
54
+ Notifications are submitted as a `POST` form request to the current Appilix push notification endpoint.
47
55
 
48
56
 
49
57
  On success, the method returns a parsed JSON response:
@@ -77,7 +85,7 @@ If the server response contains invalid JSON, you will receive:
77
85
 
78
86
  ### Fetching Registered User Tokens
79
87
 
80
- To fetch registered user tokens, use the `appilix_get_registered_user` method. The `page` parameter is mandatory:
88
+ To fetch registered user tokens, use the `appilix_get_registered_user` method:
81
89
 
82
90
  ```ruby
83
91
  require 'appilix_notifications'
@@ -85,7 +93,11 @@ require 'appilix_notifications'
85
93
  response = AppilixNotifications.appilix_get_registered_user(
86
94
  'your_app_key',
87
95
  'your_api_key',
88
- 1 # Page number
96
+ 1, # Optional page number; defaults to 1
97
+ user_identity: 'optional_user_identity',
98
+ items_per_page: 50,
99
+ secondary_app_key: 'your_ios_app_key',
100
+ secondary_api_key: 'your_ios_api_key'
89
101
  )
90
102
 
91
103
  puts response
@@ -95,15 +107,27 @@ puts response
95
107
 
96
108
  - `app_key` (String): Your application's key from Appilix.
97
109
  - `api_key` (String): Your API key from Appilix.
98
- - `page` (Integer): The page number to fetch tokens from (mandatory).
110
+ - `page` (Integer, optional): The page number, defaulting to `1`.
111
+ - `user_identity` (String, optional keyword): Return tokens for a specific user.
112
+ - `items_per_page` (Integer, optional keyword): Results per page, defaulting to `100`.
113
+ - `secondary_app_key` (String, optional keyword): The app key for a second app.
114
+ - `secondary_api_key` (String, optional keyword): The API key for the second app.
99
115
 
100
116
 
101
117
  On success, the method returns a parsed JSON response containing the tokens:
102
118
 
103
119
  ```json
104
120
  {
105
- "tokens": ["token1", "token2", "token3"],
106
- "status": "true"
121
+ "status": true,
122
+ "current_page": 1,
123
+ "has_next_page": false,
124
+ "tokens": [
125
+ {
126
+ "token": "fcm-device-token-string",
127
+ "user_identity": "user@example.com",
128
+ "modified_at": "2026-05-22 10:30:00"
129
+ }
130
+ ]
107
131
  }
108
132
  ```
109
133
 
@@ -5,7 +5,7 @@
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "appilix_notifications"
7
7
  #spec.version = AppilixNotifications::VERSION
8
- spec.version = "0.1.1"
8
+ spec.version = "0.1.2"
9
9
  spec.authors = ["RoaaAlqaisi"]
10
10
  spec.email = ["rowaalqaisi@gmail.com"]
11
11
  spec.license = "NGPL"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppilixNotifications
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -2,29 +2,34 @@
2
2
 
3
3
  require_relative "appilix_notifications/version"
4
4
 
5
- require 'net/http'
6
- require 'uri'
7
- require 'json'
5
+ require "net/http"
6
+ require "uri"
7
+ require "json"
8
8
 
9
9
  module AppilixNotifications
10
10
  BASE_URL = "https://appilix.com/api"
11
11
  PUSH_NOTIFICATION_URL = "push-notification"
12
- TOKEN_LIST_URL = "push_notification_token_list.php"
12
+ TOKEN_LIST_URL = "push-notification-token"
13
13
 
14
14
  module_function
15
15
 
16
- def appilix_send_notifications(app_key, api_key, title, body, user_identity = nil, open_link_url = nil)
16
+ def appilix_send_notifications(app_key, api_key, title, body, user_identity = nil, open_link_url = nil,
17
+ notification_image: nil, secondary_app_key: nil, secondary_api_key: nil)
17
18
  uri = URI("#{BASE_URL}/#{PUSH_NOTIFICATION_URL}")
18
- uri.query = URI.encode_www_form(
19
- 'app_key' => app_key,
20
- 'api_key' => api_key,
21
- 'notification_title' => title,
22
- 'notification_body' => body,
23
- 'user_identity' => user_identity,
24
- 'open_link_url' => open_link_url
19
+ form_data = compact_parameters(
20
+ "app_key" => app_key,
21
+ "api_key" => api_key,
22
+ "notification_title" => title,
23
+ "notification_body" => body,
24
+ "user_identity" => user_identity,
25
+ "open_link_url" => open_link_url,
26
+ "notification_image" => notification_image,
27
+ "secondary_app_key" => secondary_app_key,
28
+ "secondary_api_key" => secondary_api_key
25
29
  )
26
30
 
27
- request = Net::HTTP::Get.new(uri)
31
+ request = Net::HTTP::Post.new(uri)
32
+ request.set_form_data(form_data)
28
33
 
29
34
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
30
35
  http.request(request)
@@ -33,15 +38,18 @@ module AppilixNotifications
33
38
  handle_response(response)
34
39
  end
35
40
 
36
- def appilix_get_registered_user(app_key, api_key, page)
37
- raise ArgumentError, "Page parameter is mandatory" unless page
38
-
41
+ def appilix_get_registered_user(app_key, api_key, page = 1, user_identity: nil, items_per_page: 100,
42
+ secondary_app_key: nil, secondary_api_key: nil)
39
43
  uri = URI("#{BASE_URL}/#{TOKEN_LIST_URL}")
40
- uri.query = URI.encode_www_form(
41
- 'app_key' => app_key,
42
- 'api_key' => api_key,
43
- 'page' => page
44
- )
44
+ uri.query = URI.encode_www_form(compact_parameters(
45
+ "app_key" => app_key,
46
+ "api_key" => api_key,
47
+ "page" => page,
48
+ "items_per_page" => items_per_page,
49
+ "user_identity" => user_identity,
50
+ "secondary_app_key" => secondary_app_key,
51
+ "secondary_api_key" => secondary_api_key
52
+ ))
45
53
 
46
54
  request = Net::HTTP::Get.new(uri)
47
55
 
@@ -57,10 +65,10 @@ module AppilixNotifications
57
65
  when Net::HTTPSuccess
58
66
  JSON.parse(response.body)
59
67
  else
60
- { 'error' => response.message, 'code' => response.code, 'body' => parse_body_safe(response.body) }
68
+ {"error" => response.message, "code" => response.code, "body" => parse_body_safe(response.body)}
61
69
  end
62
70
  rescue JSON::ParserError
63
- { 'error' => 'Invalid JSON response', 'body' => response.body }
71
+ {"error" => "Invalid JSON response", "body" => response.body}
64
72
  end
65
73
 
66
74
  def parse_body_safe(body)
@@ -68,4 +76,8 @@ module AppilixNotifications
68
76
  rescue JSON::ParserError
69
77
  body
70
78
  end
79
+
80
+ def compact_parameters(parameters)
81
+ parameters.reject { |_key, value| value.nil? }
82
+ end
71
83
  end
@@ -1,35 +1,69 @@
1
- require_relative '../lib/appilix_notifications'
1
+ require_relative "../lib/appilix_notifications"
2
2
 
3
3
  RSpec.describe AppilixNotifications do
4
- app_key = "key1"
5
- api_key = "apikey1"
4
+ let(:app_key) { "key1" }
5
+ let(:api_key) { "apikey1" }
6
+ let(:http) { instance_double(Net::HTTP) }
6
7
 
7
- it 'sends a notification successfully using GET' do
8
- allow(AppilixNotifications).to receive(:appilix_send_notifications)
9
- .with(app_key, api_key, 'Hello', 'This is a test notification', nil, nil).and_return({ 'status' => 'true' })
8
+ before { allow(Net::HTTP).to receive(:start).and_yield(http) }
10
9
 
11
- response = AppilixNotifications.appilix_send_notifications(
12
- app_key, api_key, 'Hello', 'This is a test notification', nil, nil
10
+ def successful_response(body)
11
+ response = Net::HTTPOK.new("1.1", "200", "OK")
12
+ allow(response).to receive(:body).and_return(JSON.generate(body))
13
+ response
14
+ end
15
+
16
+ it "sends a notification using a POST form request" do
17
+ allow(http).to receive(:request).and_return(successful_response("status" => true))
18
+
19
+ response = described_class.appilix_send_notifications(
20
+ app_key, api_key, "Hello", "Notification body", "user@example.com", "https://example.com",
21
+ notification_image: "https://example.com/image.png",
22
+ secondary_app_key: "ios-key", secondary_api_key: "ios-api-key"
13
23
  )
14
24
 
15
- expect(response).to be_a(Hash)
16
- expect(response['status']).to eq('true')
25
+ expect(response).to eq("status" => true)
26
+ expect(http).to have_received(:request) do |request|
27
+ expect(request).to be_a(Net::HTTP::Post)
28
+ expect(request.uri.to_s).to eq("https://appilix.com/api/push-notification")
29
+ expect(URI.decode_www_form(request.body).to_h).to eq(
30
+ "app_key" => app_key, "api_key" => api_key,
31
+ "notification_title" => "Hello", "notification_body" => "Notification body",
32
+ "user_identity" => "user@example.com", "open_link_url" => "https://example.com",
33
+ "notification_image" => "https://example.com/image.png",
34
+ "secondary_app_key" => "ios-key", "secondary_api_key" => "ios-api-key"
35
+ )
36
+ end
17
37
  end
18
38
 
19
- it 'fetches registered user tokens successfully with a valid page' do
20
- allow(AppilixNotifications).to receive(:appilix_get_registered_user)
21
- .with(app_key, api_key, 1).and_return({ 'tokens' => ['token1', 'token2'] })
39
+ it "fetches FCM tokens from the current endpoint with documented parameters" do
40
+ body = {"status" => true, "current_page" => 2, "has_next_page" => false, "tokens" => []}
41
+ allow(http).to receive(:request).and_return(successful_response(body))
22
42
 
23
- response = AppilixNotifications.appilix_get_registered_user(app_key, api_key, 1)
43
+ response = described_class.appilix_get_registered_user(
44
+ app_key, api_key, 2, user_identity: "user@example.com", items_per_page: 50,
45
+ secondary_app_key: "ios-key", secondary_api_key: "ios-api-key"
46
+ )
24
47
 
25
- expect(response).to be_a(Hash)
26
- expect(response).to have_key('tokens')
27
- puts response
48
+ expect(response).to eq(body)
49
+ expect(http).to have_received(:request) do |request|
50
+ expect(request).to be_a(Net::HTTP::Get)
51
+ expect(request.uri.path).to eq("/api/push-notification-token")
52
+ expect(URI.decode_www_form(request.uri.query).to_h).to eq(
53
+ "app_key" => app_key, "api_key" => api_key, "page" => "2", "items_per_page" => "50",
54
+ "user_identity" => "user@example.com", "secondary_app_key" => "ios-key",
55
+ "secondary_api_key" => "ios-api-key"
56
+ )
57
+ end
28
58
  end
29
59
 
30
- it 'raises an error when page is missing for registered user tokens' do
31
- expect {
32
- AppilixNotifications.appilix_get_registered_user(app_key, api_key, nil)
33
- }.to raise_error(ArgumentError, 'Page parameter is mandatory')
60
+ it "uses the API pagination defaults when token options are omitted" do
61
+ allow(http).to receive(:request).and_return(successful_response("status" => true, "tokens" => []))
62
+
63
+ described_class.appilix_get_registered_user(app_key, api_key)
64
+
65
+ expect(http).to have_received(:request) do |request|
66
+ expect(URI.decode_www_form(request.uri.query).to_h).to include("page" => "1", "items_per_page" => "100")
67
+ end
34
68
  end
35
69
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appilix_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - RoaaAlqaisi
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: json
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.6.3
92
+ rubygems_version: 4.0.10
93
93
  specification_version: 4
94
94
  summary: A Ruby gem to send notifications using the appilix API.
95
95
  test_files: []