red_socket 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in red_socket.gemspec
4
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mariusz Wyrozebski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # RedSocket client
2
+
3
+ Send notification for clients listening on HTML5 websockets. See more details on http://red-socket.com .
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile and run the `bundle` command to install it.
8
+
9
+ ```ruby
10
+ gem "red_socket"
11
+ ```
12
+
13
+ Create `config/initializers/red_socket.rb` file wit following config:
14
+
15
+ ```ruby
16
+ RedSocket::Base.configure do |config|
17
+ config.account_id = "account_name" # within host name
18
+ config.api_key = "some_api_key"
19
+ config.api_secret = "some_secret_key"
20
+ end
21
+ ```
22
+
23
+ Sign up for an account on http://red-socket.com/signup to get your key pair.
24
+
25
+
26
+ **Requires Ruby 1.9 or later.**
27
+
28
+ ## Usage
29
+
30
+ Call `RedSocket.notify('my_channel')` to send message to listening clients. By default it will send a 'notification' event which can be passed as the second argument.
31
+
32
+ ```ruby
33
+ RedSocket::Base.notify('my_channel', 'my_custom_event')
34
+ ```
35
+
36
+ Additional message can be send within third parameter
37
+
38
+ ```ruby
39
+ RedSocket::Base.notify('my_channel', 'my_custom_event', 'it can be for example a json message, so it can be parsed by the browser')
40
+ ```
41
+
42
+ ## Development
43
+
44
+ Questions or problems? Please post them on the [issue tracker](https://github.com/m4risu/red_socket/issues). You can contribute changes by forking the project and submitting a pull request. Feel free to do it.
45
+
46
+ This gem is created by Mariusz Wyrozebski and is under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module RedSocket
2
+ VERSION = "0.0.1"
3
+ end
data/lib/red_socket.rb ADDED
@@ -0,0 +1,60 @@
1
+ require "red_socket/version"
2
+ require "eventmachine"
3
+ require "em-http"
4
+
5
+ module RedSocket
6
+ class Base
7
+
8
+ def self.api_key
9
+ @@api_key
10
+ end
11
+
12
+ def self.api_key=(value)
13
+ @@api_key = value
14
+ end
15
+
16
+ def self.account_id
17
+ @@account_id
18
+ end
19
+
20
+ def self.account_id=(value)
21
+ @@account_id = value
22
+ end
23
+
24
+ def self.api_secret
25
+ @@api_secret
26
+ end
27
+
28
+ def self.api_secret=(value)
29
+ @@api_secret = value
30
+ end
31
+
32
+ def self.configure
33
+ yield self
34
+ self
35
+ end
36
+
37
+ def self.notify(channel, event="notification", message="")
38
+ ::EventMachine.run {
39
+ http = ::EventMachine::HttpRequest.
40
+ new("http://#{account_id}.subscriptions.dev/api/messages.json").
41
+ post :body =>
42
+ {
43
+ 'api_key' => api_key,
44
+ 'channel' => channel,
45
+ 'event' => event,
46
+ 'message' => message
47
+ }
48
+ http.errback { p 'Uh oh'; EM.stop }
49
+ http.callback {
50
+ p http.response_header.status
51
+ p http.response_header
52
+ p http.response
53
+
54
+ EventMachine.stop
55
+ }
56
+ }
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "red_socket/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "red_socket"
7
+ s.version = RedSocket::VERSION
8
+ s.authors = ["Mariusz Wyrozebski"]
9
+ s.email = ["mariuszwyrozebski@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Message sending wrapper for red-socket.com service.}
12
+ s.description = %q{red-socket.com is a service providing push notifications to clients listening to websockets. Gem is a wrapper for the service to allow pushing messages.}
13
+
14
+ s.rubyforge_project = "red_socket"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "em-http-request"
25
+ s.add_development_dependency "eventmachine"
26
+ # s.add_runtime_dependency "rest-client"
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedSocket do
4
+
5
+ it "has configuration items" do
6
+ RedSocket::RedSocket.respond_to?(:account_id).should be_true
7
+ RedSocket::RedSocket.respond_to?(:api_key).should be_true
8
+ RedSocket::RedSocket.respond_to?(:api_secret).should be_true
9
+ end
10
+
11
+ it "can be configured" do
12
+ RedSocket::RedSocket.respond_to?(:configure)
13
+ end
14
+
15
+ describe "notify" do
16
+ it "can have one argument for a channel" do
17
+ RedSocket::RedSocket.configure do |config|
18
+ config.account_id = "test"
19
+ config.api_key = "48g9834bf0b7fbve96v96vd97fvsadc"
20
+ config.api_secret = "fb78thg94b35g7b459gbv0438bghv73wbv803wbv80w3bv803w"
21
+ end
22
+ RedSocket::RedSocket.notify("channel")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require 'red_socket'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red_socket
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mariusz Wyrozebski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-17 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ name: rspec
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ name: rake
47
+ prerelease: false
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :development
60
+ name: em-http-request
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ name: eventmachine
75
+ prerelease: false
76
+ version_requirements: *id004
77
+ description: red-socket.com is a service providing push notifications to clients listening to websockets. Gem is a wrapper for the service to allow pushing messages.
78
+ email:
79
+ - mariuszwyrozebski@gmail.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files: []
85
+
86
+ files:
87
+ - .gitignore
88
+ - CHANGELOG.md
89
+ - Gemfile
90
+ - LICENCE
91
+ - README.md
92
+ - Rakefile
93
+ - lib/red_socket.rb
94
+ - lib/red_socket/version.rb
95
+ - red_socket.gemspec
96
+ - spec/red_socket_spec.rb
97
+ - spec/spec_helper.rb
98
+ has_rdoc: true
99
+ homepage: ""
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options: []
104
+
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project: red_socket
128
+ rubygems_version: 1.3.7
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Message sending wrapper for red-socket.com service.
132
+ test_files: []
133
+