expo-push-middleware 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 34b721c02143e82ff7eaf2340735c458d69a6b06f552af318349f7828c0f829a
4
+ data.tar.gz: 5d9066a914577b4df6650c8c043e0643743840805688c58631ae20d12cc3f5f4
5
+ SHA512:
6
+ metadata.gz: 1d6de7bfeda5150fdd55793cc61f50e2a16b77faa406a75f49b18114c7c7576462983e890d17613288519b6a3faba47c158ad6b5fe132ec8bf490d29a7c05032
7
+ data.tar.gz: 16c5d3b1886170aca4b7bc949ef25ea13b423f5510cc3b00f6bd85a853801395f28c743d10954183b455f5f71087ccc88d4a5511813c7100421f912af872dd28
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7.0
3
+ SuggestExtensions: false
4
+ NewCops: enable
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 180
16
+
17
+ Style/Documentation:
18
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-03-28
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in expo-push-monitoring-sdk.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
11
+ gem "typhoeus"
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ expo-push-middleware (0.1.0)
5
+ typhoeus
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ ethon (0.16.0)
12
+ ffi (>= 1.15.0)
13
+ ffi (1.15.5)
14
+ json (2.6.3)
15
+ parallel (1.22.1)
16
+ parser (3.2.1.1)
17
+ ast (~> 2.4.1)
18
+ rainbow (3.1.1)
19
+ rake (13.0.6)
20
+ regexp_parser (2.7.0)
21
+ rexml (3.2.5)
22
+ rubocop (1.48.1)
23
+ json (~> 2.3)
24
+ parallel (~> 1.10)
25
+ parser (>= 3.2.0.0)
26
+ rainbow (>= 2.2.2, < 4.0)
27
+ regexp_parser (>= 1.8, < 3.0)
28
+ rexml (>= 3.2.5, < 4.0)
29
+ rubocop-ast (>= 1.26.0, < 2.0)
30
+ ruby-progressbar (~> 1.7)
31
+ unicode-display_width (>= 2.4.0, < 3.0)
32
+ rubocop-ast (1.28.0)
33
+ parser (>= 3.2.1.0)
34
+ ruby-progressbar (1.13.0)
35
+ typhoeus (1.4.0)
36
+ ethon (>= 0.9.0)
37
+ unicode-display_width (2.4.2)
38
+
39
+ PLATFORMS
40
+ arm64-darwin-20
41
+
42
+ DEPENDENCIES
43
+ expo-push-middleware!
44
+ rake (~> 13.0)
45
+ rubocop (~> 1.21)
46
+ typhoeus
47
+
48
+ BUNDLED WITH
49
+ 2.2.32
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Expo::Push::Monitoring::Sdk
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/expo_push_middleware`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'expo-push-middleware'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install expo-push-middleware
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tymate/expo-push-middleware.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "expo-push-middleware"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expo
4
+ module Push
5
+ module Middleware
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "expo_push_middleware/version"
4
+
5
+ module Expo
6
+ module Push
7
+ module Middleware
8
+ Configuration = Struct.new(:api_url, :client_id, :client_secret)
9
+
10
+ class << self
11
+ attr_accessor :config
12
+ end
13
+
14
+ def self.configure
15
+ self.config ||= Expo::Push::Middleware::Configuration.new
16
+ yield(config)
17
+ end
18
+
19
+ class Client
20
+ class Error < StandardError; end
21
+
22
+ def initialize(**args)
23
+ @http_client = args[:http_client] || Typhoeus
24
+ end
25
+
26
+ def send_messages(messages, **_)
27
+ # https://docs.expo.io/versions/latest/guides/push-notifications/#message-format
28
+ raise TooManyMessagesError, "Only 100 message objects at a time allowed." if messages.length > 100
29
+
30
+ @http_client.post(
31
+ "#{Expo::Push::Middleware.config.api_url}/api/v1/push_requests",
32
+ body: { push_request: { messages: messages } }.to_json,
33
+ headers: headers
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def headers
40
+ {
41
+ "Content-Type" => "application/json",
42
+ "Accept" => "application/json",
43
+ "Authorization" => "Bearer #{access_token}"
44
+ }
45
+ end
46
+
47
+ def access_token # rubocop:disable Metrics/MethodLength
48
+ response = @http_client.post(
49
+ "#{Expo::Push::Middleware.config.api_url}/oauth/token",
50
+ body: {
51
+ grant_type: "client_credentials",
52
+ client_id: Expo::Push::Middleware.config.client_id,
53
+ client_secret: Expo::Push::Middleware.config.client_secret
54
+ }.to_json,
55
+ headers: { "Content-Type" => "application/json" }
56
+ )
57
+
58
+ raise Error, "Error while getting access token: #{response.body}" unless response.success?
59
+
60
+ JSON.parse(response.body)["access_token"]
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: expo-push-middleware
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien Camblan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Middleware that intercepts push notifications, sends them to Expo Push
28
+ API with monitoring as bonus.
29
+ email:
30
+ - julien.camblan@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - lib/expo-push-middleware/version.rb
44
+ - lib/expo_push_middleware.rb
45
+ homepage: https://github.com/tymate/expo-push-middleware
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/tymate/expo-push-middleware
50
+ source_code_uri: https://github.com/tymate/expo-push-middleware
51
+ changelog_uri: https://github.com/tymate/expo-push-middleware/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.7.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.2.32
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Monitor your push notifications with Expo Push API
71
+ test_files: []