faye-publisher 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzY5Y2JhODhmMDA3YTU1MGJmMzlkYzJiZjkyZDhmMWJmMDdjMzc0Zg==
5
+ data.tar.gz: !binary |-
6
+ ZDk5NGVlNTdkODJlNTZjNTI5MGViMzU0YTI5ZmFjMjU0NjBkNWQ4Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTM1MzY3NjEwOWRmYmI2ZjViOTFiYmY1NmRiM2IxY2EyYzA5YTUzZTg5ZTdh
10
+ NTI5YThhMGY3NzdlNGVmYTM2YmMxYzJhZDExZWU0NDMyMDEzYzQ4NmVhMmRi
11
+ ODllMjA0YmY0YmEzNzIxNjQyNmNlODAyNTdiYTY4OWQ4ZGQ3Mzc=
12
+ data.tar.gz: !binary |-
13
+ NTk1M2RkYjNkMmRmNjhkNGM0ZDNlMzBmMDZhMWMzNWFmYzI4YzhmYTg4OWUw
14
+ Y2Y1M2U5YTVjYmM1N2ZjZjJhNjc5MDNjNzZiOGQzMGZjNzAzZDgyMTQ2NWI4
15
+ ODBjY2MwNGFkZDRlZWFhNzQ2MWU1MjVhNWE0OGQ5MjM2NGUzNGE=
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angus-remote.gemspec
4
+ gemspec
5
+
6
+ gem 'picasso-remote', :git => 'ssh://git@intranet.moove-it.com:8082/picasso-remote-client',
7
+ :branch => :legacy
8
+
9
+ gem 'picasso-sdoc', :git => 'ssh://git@intranet.moove-it.com:8082/picasso-sdoc',
10
+ :branch => :legacy
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 adrian-gomez
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ faye-publisher
2
+ ==============
3
+ Simple publisher for faye
4
+
5
+ Installing
6
+ ==============
7
+ Add this to your Gemfile:
8
+ ```ruby
9
+ gem 'faye-publisher'
10
+ ```
11
+
12
+ Usage
13
+ ==============
14
+ ```ruby
15
+ publisher = Faye::Publisher.new('http://localhost:9292/faye')
16
+ publisher.publish('/messages', 'Hello world!')
17
+ ```
18
+
19
+ Contributing
20
+ ==============
21
+
22
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
23
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
24
+ - Fork the project.
25
+ - Start a feature/bugfix branch.
26
+ - Commit and push until you are happy with your contribution.
27
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
28
+ - Please try not to mess with the version, or history. If you want to have your own version, or is
29
+ otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
30
+
31
+ Copyright
32
+ ==============
33
+
34
+ Copyright © 2014 Adrian Gomez. See LICENSE.txt for further details.
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'faye/publisher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = 'faye-publisher'
9
+ spec.version = Faye::Publisher::VERSION
10
+ spec.authors = ['Adrian Gomez']
11
+ spec.date = '2014-04-25'
12
+ spec.summary = 'Simple faye publisher'
13
+ spec.description = <<-DESCRIPTION
14
+ Allows to publish messages to a faye server, the main difference with the default faye client
15
+ is that it does not need to run inside a EventMachine loop as it only opens a http connection
16
+ with the server to send the event.
17
+ Because of this is best to publish events from a separate thread using sidekiq for example.
18
+ DESCRIPTION
19
+ spec.email = 'adrian_g171@hotmail.com'
20
+ spec.extra_rdoc_files = %w[LICENSE README.md]
21
+ spec.files = %w[
22
+ Gemfile
23
+ LICENSE
24
+ README.md
25
+ faye-publisher.gemspec
26
+ lib/faye-publisher.rb
27
+ lib/faye/publisher.rb
28
+ lib/faye/publisher/testing.rb
29
+ ]
30
+ spec.homepage = 'https://github.com/adrian-gomez/faye-publisher'
31
+ spec.licenses = %w[MIT]
32
+ spec.require_paths = %w[lib]
33
+
34
+ end
@@ -0,0 +1 @@
1
+ require_relative 'faye/publisher'
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Faye
5
+ class Publisher
6
+
7
+ class PublicationError < StandardError; end
8
+
9
+ def initialize(faye_endpoint)
10
+ @faye_uri = URI.parse(faye_endpoint)
11
+ end
12
+
13
+ # Sends an event to given chanel with the given data.
14
+ #
15
+ # @raise [PublicationError] if the publication fails.
16
+ def publish(channel, data)
17
+ http = Net::HTTP.new(@faye_uri.host, @faye_uri.port)
18
+
19
+ path = if @faye_uri.path.empty?
20
+ '/'
21
+ else
22
+ @faye_uri.path
23
+ end
24
+ headers = { 'Content-Type' => 'application/json' }
25
+ message = { :channel => channel, :data => data }
26
+
27
+ response, _ = http.post(path, JSON(message), headers)
28
+
29
+ unless response.kind_of?(Net::HTTPSuccess)
30
+ raise PublicationError
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'faye-publisher'
2
+
3
+ module Faye
4
+ class Publisher
5
+
6
+ def publish(channel, data)
7
+ self.class.channels[channel] << data
8
+ end
9
+
10
+ def self.channels
11
+ @channels ||= Hash.new { |hash, key| hash[key] = [] }
12
+ end
13
+
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faye-publisher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Gomez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! " Allows to publish messages to a faye server, the main difference
14
+ with the default faye client\n is that it does not need to run inside a EventMachine
15
+ loop as it only opens a http connection\n with the server to send the event.\n
16
+ \ Because of this is best to publish events from a separate thread using sidekiq
17
+ for example.\n"
18
+ email: adrian_g171@hotmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files:
22
+ - LICENSE
23
+ - README.md
24
+ files:
25
+ - Gemfile
26
+ - LICENSE
27
+ - README.md
28
+ - faye-publisher.gemspec
29
+ - lib/faye-publisher.rb
30
+ - lib/faye/publisher.rb
31
+ - lib/faye/publisher/testing.rb
32
+ homepage: https://github.com/adrian-gomez/faye-publisher
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.2.0
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Simple faye publisher
56
+ test_files: []