Skip to content

Commit 5e7c613

Browse files
authored
initial implementation of SSE gem based on code from LD Ruby SDK (#1)
1 parent 0981daf commit 5e7c613

23 files changed

+1832
-1
lines changed

.circleci/config.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
version: 2
2+
3+
workflows:
4+
version: 2
5+
test:
6+
jobs:
7+
- test-misc-rubies
8+
- test-2.2
9+
- test-2.3
10+
- test-2.4
11+
- test-2.5
12+
- test-jruby-9.2
13+
14+
ruby-docker-template: &ruby-docker-template
15+
steps:
16+
- checkout
17+
- run: |
18+
if [[ $CIRCLE_JOB == test-jruby* ]]; then
19+
gem install jruby-openssl; # required by bundler, no effect on Ruby MRI
20+
fi
21+
- run: ruby -v
22+
- run: gem install bundler -v "~> 1.17"
23+
- run: bundle install
24+
- run: mkdir ./rspec
25+
- run: bundle exec rspec --format progress --format RspecJunitFormatter -o ./rspec/rspec.xml spec
26+
- store_test_results:
27+
path: ./rspec
28+
- store_artifacts:
29+
path: ./rspec
30+
31+
jobs:
32+
test-2.2:
33+
<<: *ruby-docker-template
34+
docker:
35+
- image: circleci/ruby:2.2.10-jessie
36+
test-2.3:
37+
<<: *ruby-docker-template
38+
docker:
39+
- image: circleci/ruby:2.3.7-jessie
40+
test-2.4:
41+
<<: *ruby-docker-template
42+
docker:
43+
- image: circleci/ruby:2.4.5-stretch
44+
test-2.5:
45+
<<: *ruby-docker-template
46+
docker:
47+
- image: circleci/ruby:2.5.3-stretch
48+
test-jruby-9.2:
49+
<<: *ruby-docker-template
50+
docker:
51+
- image: circleci/jruby:9-jdk
52+
53+
# The following very slow job uses an Ubuntu container to run the Ruby versions that
54+
# CircleCI doesn't provide Docker images for.
55+
test-misc-rubies:
56+
machine:
57+
image: circleci/classic:latest
58+
environment:
59+
- RUBIES: "jruby-9.1.17.0"
60+
steps:
61+
- checkout
62+
- run:
63+
name: install all Ruby versions
64+
command: "parallel rvm install ::: $RUBIES"
65+
- run:
66+
name: bundle install for all versions
67+
shell: /bin/bash -leo pipefail # need -l in order for "rvm use" to work
68+
command: |
69+
set -e;
70+
for i in $RUBIES;
71+
do
72+
rvm use $i;
73+
if [[ $i == jruby* ]]; then
74+
gem install jruby-openssl; # required by bundler, no effect on Ruby MRI
75+
fi
76+
gem install bundler -v "~> 1.17";
77+
bundle install;
78+
mv Gemfile.lock "Gemfile.lock.$i"
79+
done
80+
- run:
81+
name: run tests for all versions
82+
shell: /bin/bash -leo pipefail
83+
command: |
84+
set -e;
85+
for i in $RUBIES;
86+
do
87+
rvm use $i;
88+
cp "Gemfile.lock.$i" Gemfile.lock;
89+
bundle exec rspec spec;
90+
done

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@
1212
*.a
1313
mkmf.log
1414
*.gem
15-
Gemfile.lock
1615
.DS_Store

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change log
2+
3+
All notable changes to the LaunchDarkly SSE Client for Ruby will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4+
5+
## [1.0.0] - 2019-01-03
6+
7+
Initial release.

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gemspec

Gemfile.lock

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PATH
2+
remote: .
3+
specs:
4+
ld-eventsource (1.0.0)
5+
concurrent-ruby (~> 1.0)
6+
http_tools (~> 0.4.5)
7+
socketry (~> 0.5.1)
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
concurrent-ruby (1.0.5)
13+
diff-lcs (1.3)
14+
hitimes (1.3.0)
15+
http_tools (0.4.5)
16+
rake (10.5.0)
17+
rspec (3.7.0)
18+
rspec-core (~> 3.7.0)
19+
rspec-expectations (~> 3.7.0)
20+
rspec-mocks (~> 3.7.0)
21+
rspec-core (3.7.1)
22+
rspec-support (~> 3.7.0)
23+
rspec-expectations (3.7.0)
24+
diff-lcs (>= 1.2.0, < 2.0)
25+
rspec-support (~> 3.7.0)
26+
rspec-mocks (3.7.0)
27+
diff-lcs (>= 1.2.0, < 2.0)
28+
rspec-support (~> 3.7.0)
29+
rspec-support (3.7.0)
30+
rspec_junit_formatter (0.3.0)
31+
rspec-core (>= 2, < 4, != 2.12.0)
32+
socketry (0.5.1)
33+
hitimes (~> 1.2)
34+
35+
PLATFORMS
36+
java
37+
ruby
38+
39+
DEPENDENCIES
40+
bundler (~> 1.7)
41+
ld-eventsource!
42+
rake (~> 10.0)
43+
rspec (~> 3.2)
44+
rspec_junit_formatter (~> 0.3.0)
45+
46+
BUNDLED WITH
47+
1.17.3

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2018 Catamorphic, Co.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
LaunchDarkly SSE Client for Ruby
2+
================================
3+
4+
[![Gem Version](https://badge.fury.io/rb/ld-eventsource.svg)](http://badge.fury.io/rb/ld-eventsource) [![Circle CI](https://circleci.com/gh/launchdarkly/ruby-eventsource/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/ruby-eventsource/tree/master)
5+
6+
A client for the [Server-Sent Events](https://www.w3.org/TR/eventsource/) protocol. This implementation runs on a worker thread, and uses the [`socketry`](https://rubygems.org/gems/socketry) gem to manage a persistent connection. Its primary purpose is to support the [LaunchDarkly SDK for Ruby](https://github.com/launchdarkly/ruby-client), but it can be used independently.
7+
8+
Parts of this code are based on https://github.com/Tonkpils/celluloid-eventsource, but it does not use Celluloid.
9+
10+
Supported Ruby versions
11+
-----------------------
12+
13+
This gem has a minimum Ruby version of 2.2.6, or 9.1.6 for JRuby.
14+
15+
Quick setup
16+
-----------
17+
18+
1. Install the Ruby SDK with `gem`:
19+
20+
```shell
21+
gem install ld-eventsource
22+
```
23+
24+
2. Import the code:
25+
26+
```ruby
27+
require 'ld-eventsource'
28+
```
29+
30+
3. Create a new SSE client instance and register your event handler:
31+
32+
```ruby
33+
sse_client = SSE::Client.new("http://hostname/resource/path") do |client|
34+
client.on_event do |event|
35+
puts "I received an event: #{event.type}, #{event.data}"
36+
end
37+
end
38+
```
39+
40+
For other options available with the `Client` constructor, see the [API documentation](https://www.rubydoc.info/gems/ld-eventsource).
41+
42+
Contributing
43+
------------
44+
45+
We welcome questions, suggestions, and pull requests at our [Github repository](https://github.com/launchdarkly/ruby-eventsource). Pull requests should be done from a fork.

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "bundler/gem_tasks"
2+
3+
require "rspec/core/rake_task"
4+
RSpec::Core::RakeTask.new(:spec)
5+
task default: :spec

ld-eventsource.gemspec

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding: utf-8
2+
3+
lib = File.expand_path("../lib", __FILE__)
4+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5+
require "ld-eventsource/version"
6+
7+
# rubocop:disable Metrics/BlockLength
8+
Gem::Specification.new do |spec|
9+
spec.name = "ld-eventsource"
10+
spec.version = SSE::VERSION
11+
spec.authors = ["LaunchDarkly"]
12+
spec.email = ["team@launchdarkly.com"]
13+
spec.summary = "LaunchDarkly SSE client"
14+
spec.description = "LaunchDarkly SSE client for Ruby"
15+
spec.homepage = "https://github.com/launchdarkly/ruby-eventsource"
16+
spec.license = "Apache-2.0"
17+
18+
spec.files = `git ls-files -z`.split("\x0")
19+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21+
spec.require_paths = ["lib"]
22+
23+
spec.add_development_dependency "bundler", "~> 1.7"
24+
spec.add_development_dependency "rspec", "~> 3.2"
25+
spec.add_development_dependency "rake", "~> 10.0"
26+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.3.0"
27+
28+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
29+
spec.add_runtime_dependency "http_tools", '~> 0.4.5'
30+
spec.add_runtime_dependency "socketry", "~> 0.5.1"
31+
end

lib/ld-eventsource.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "ld-eventsource/client"
2+
require "ld-eventsource/version"
3+
4+
#
5+
# A client for the Server-Sent Events protocol.
6+
#
7+
module SSE
8+
#
9+
# Internal components of the SSE implementation. All classes in this module should be
10+
# considered unsupported and subject to change.
11+
#
12+
module Impl
13+
end
14+
end

0 commit comments

Comments
 (0)