se-realtime 0.0.0.beta0

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
+ SHA1:
3
+ metadata.gz: 712132141551c830aa22ec30a8c73bd689d860e2
4
+ data.tar.gz: b4ccff6e2106244445eb633177870e8802d8b938
5
+ SHA512:
6
+ metadata.gz: 4e591185c80ea2836d5b0a7c371c44883a81ca6328f364b1888c720b492f333d920d9b3b06e6c72dcceb3f67eaa498d5528fb06f0e3586ebe0b7629f52e6c061
7
+ data.tar.gz: 86ffbf8259c9d7ffcc4e2caea6c107f734d4da0146c3cb7d16ab7af287e9a6c55cefeef3813ad557fa9af20c49cf4f538249837424d1030a45b0a3f8c5f14cad
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in se-realtime.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ se-realtime (0.0.0.beta0)
5
+ mechanize (~> 2.7)
6
+ nokogiri (~> 1.8)
7
+ permessage_deflate (~> 0.1)
8
+ websocket-driver (~> 0.6)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ domain_name (0.5.20170404)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ http-cookie (1.0.3)
16
+ domain_name (~> 0.5)
17
+ mechanize (2.7.5)
18
+ domain_name (~> 0.5, >= 0.5.1)
19
+ http-cookie (~> 1.0)
20
+ mime-types (>= 1.17.2)
21
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
22
+ net-http-persistent (~> 2.5, >= 2.5.2)
23
+ nokogiri (~> 1.6)
24
+ ntlm-http (~> 0.1, >= 0.1.1)
25
+ webrobots (>= 0.0.9, < 0.2)
26
+ mime-types (3.1)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2016.0521)
29
+ mini_portile2 (2.3.0)
30
+ minitest (5.10.3)
31
+ net-http-digest_auth (1.4.1)
32
+ net-http-persistent (2.9.4)
33
+ nokogiri (1.8.1)
34
+ mini_portile2 (~> 2.3.0)
35
+ ntlm-http (0.1.1)
36
+ permessage_deflate (0.1.4)
37
+ rake (10.5.0)
38
+ unf (0.1.4)
39
+ unf_ext
40
+ unf_ext (0.0.7.4)
41
+ webrobots (0.1.2)
42
+ websocket-driver (0.7.0)
43
+ websocket-extensions (>= 0.1.0)
44
+ websocket-extensions (0.1.3)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.16)
51
+ minitest (~> 5.0)
52
+ rake (~> 10.0)
53
+ se-realtime!
54
+
55
+ BUNDLED WITH
56
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Isaiah Zwick-Schachter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Se::Realtime
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/se/realtime`. 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 'se-realtime'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install se-realtime
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. Then, run `rake test` to run the tests. 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 tags, 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/[USERNAME]/se-realtime.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "se/realtime"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,26 @@
1
+ require "se/realtime/version"
2
+ require "se/realtime/websocket"
3
+
4
+ module SE
5
+ module Realtime
6
+ class << self
7
+ def on_post(&handler)
8
+ WSClient.new("https://qa.sockets.stackexchange.com", cookies) do |e|
9
+ data = JSON.parse e['data']
10
+ handler.call(data)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def cookies
17
+ agent = Mechanize.new
18
+ agent.get("https://stackexchange.com/questions?realtime")
19
+ cookie_array = agent.cookies.map do |cookie|
20
+ "#{cookie.name}=#{cookie.value}" if cookie.domain.end_with? "stackexchange.com"
21
+ end
22
+ (cookie_array - [nil]).join("; ")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module SE
2
+ module Realtime
3
+ VERSION = "0.0.0.beta0".freeze
4
+ end
5
+ end
@@ -0,0 +1,75 @@
1
+ require "mechanize"
2
+ require "nokogiri"
3
+ require "websocket/driver"
4
+ require "json"
5
+ require "permessage_deflate"
6
+ require "open-uri"
7
+
8
+ module SE
9
+ module Realtime
10
+ class WSClient
11
+ attr_reader :url, :thread, :driver
12
+ attr_accessor :handler
13
+
14
+ def initialize(url, cookies, &handler)
15
+ @uri = URI.parse(url)
16
+ @url = "ws#{@uri.scheme.split("")[4]}://#{@uri.host}"
17
+ @driver = WebSocket::Driver.client(self)
18
+ @socket = TCPSocket.new(@uri.host, 80)
19
+ @handler = handler
20
+
21
+ @driver.add_extension PermessageDeflate
22
+ @driver.set_header "Cookies", cookies if cookies
23
+ @driver.set_header "Origin", "#{@uri.scheme}://#{@uri.host.split('.')[-2..-1].join('.')}"
24
+
25
+ @driver.on :connect, ->(_e) {}
26
+
27
+ @driver.on :open, ->(_e) do
28
+ send "155-questions-active"
29
+ puts "WebSocket is open!"
30
+ end
31
+
32
+ @driver.on :message do |e|
33
+ @handler.call(JSON.parse(e.data))
34
+ end
35
+
36
+ @driver.on :close, ->(_e) { puts "WebSocket is closed!"}
37
+
38
+ @driver.on :error, ->(e) { STDERR.puts e }
39
+
40
+ @driver.start
41
+
42
+ @thread = Thread.new do
43
+ trap("SIGINT") do
44
+ close
45
+ Thread.exit
46
+ end
47
+ loop do
48
+ begin
49
+ @driver.parse(@socket.recv(1))
50
+ rescue IOError, SystemCallError => e
51
+ puts "Recieved #{e} closing TCP socket. You shouldn't be worried :)"
52
+ end
53
+ end
54
+ end
55
+
56
+ at_exit { @thread.join }
57
+ end
58
+
59
+ def send(message)
60
+ @driver.text(message)
61
+ end
62
+
63
+ def write(data)
64
+ @socket.write(data)
65
+ end
66
+
67
+ def close
68
+ @driver.close
69
+ @socket.shutdown
70
+ rescue IOError, Errno::ENOTCONN => e
71
+ STDERR.puts "Recieved #{e.class} trying to close websocket. Ignoring..."
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "se/realtime/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "se-realtime"
8
+ spec.version = SE::Realtime::VERSION
9
+ spec.authors = ["thesecretmaster"]
10
+ spec.email = ["thesecretmaster@developingtechnician.com"]
11
+
12
+ spec.summary = %q{A SE realtime feed reader}
13
+ spec.homepage = "https://github.com/izwick-schachter/se-realtime"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+
36
+ [
37
+ ["mechanize", "~> 2.7"],
38
+ ["nokogiri", "~> 1.8"],
39
+ ["permessage_deflate", "~> 0.1"],
40
+ ["websocket-driver", "~> 0.6"],
41
+ ].each do |g, v|
42
+ spec.add_runtime_dependency g, v
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: se-realtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.beta0
5
+ platform: ruby
6
+ authors:
7
+ - thesecretmaster
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mechanize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: permessage_deflate
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: websocket-driver
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.6'
111
+ description:
112
+ email:
113
+ - thesecretmaster@developingtechnician.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/se/realtime.rb
128
+ - lib/se/realtime/version.rb
129
+ - lib/se/realtime/websocket.rb
130
+ - se-realtime.gemspec
131
+ homepage: https://github.com/izwick-schachter/se-realtime
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ allowed_push_host: https://rubygems.org
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">"
148
+ - !ruby/object:Gem::Version
149
+ version: 1.3.1
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.11
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A SE realtime feed reader
156
+ test_files: []