realpush 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ describe RealPush::Client do
4
+
5
+ before do
6
+ @client1 = RealPush::Client.new
7
+
8
+ @client2 = RealPush::Client.new
9
+ @client2.app_id = '123456'
10
+ @client2.privatekey = 'privatekey'
11
+ @client2.hostname = 'localhost'
12
+ @client2.scheme = 'https'
13
+ @client2.port = 1123
14
+ end
15
+
16
+ it 'should return the url without app_id and private key informations' do
17
+ @client1.url = 'http://123456:private@127.0.0.1:5678'
18
+ expect(@client1.url.to_s).to eq 'http://127.0.0.1:5678/v1/'
19
+ end
20
+
21
+ it 'should return net/http object from sync_http_client' do
22
+ expect(@client1.sync_http_client).to be_kind_of HTTPClient
23
+ end
24
+
25
+ it 'should be able configure from config and block' do
26
+ expect { @client1.config }.to raise_error RealPush::ConfigurationError
27
+ old_port = @client1.port
28
+ @client1.config do |config|
29
+ config.port = 111
30
+ end
31
+ expect(@client1.port).not_to eq old_port
32
+ end
33
+
34
+ describe 'different instances' do
35
+ it 'should send scheme messages to different objects' do
36
+ expect(@client1.scheme).not_to eq @client2.scheme
37
+ end
38
+
39
+ it 'should send app_id messages to different objects' do
40
+ expect(@client1.app_id).not_to eq @client2.app_id
41
+ end
42
+
43
+ it 'should send privatekey messages to different objects' do
44
+ expect(@client1.privatekey).not_to eq @client2.privatekey
45
+ end
46
+
47
+ it 'should send hostname messages to different objects' do
48
+ expect(@client1.hostname).not_to eq @client2.hostname
49
+ end
50
+
51
+ it 'should send port messages to different objects' do
52
+ expect(@client1.port).not_to eq @client2.port
53
+ end
54
+
55
+ it 'should send encrypted messages to different objects' do
56
+ @client1.encrypted = false
57
+ @client2.encrypted = true
58
+ expect(@client1.scheme).not_to eq @client2.scheme
59
+ expect(@client1.port).not_to eq @client2.port
60
+ end
61
+ end
62
+
63
+ describe 'default configuration' do
64
+ it 'should be preconfigured for api host' do
65
+ expect(@client1.hostname).to eq '127.0.0.1'
66
+ end
67
+
68
+ it 'should be preconfigured for port 80' do
69
+ expect(@client1.port).to eq 443
70
+ end
71
+
72
+ it 'should use standard logger if no other logger if defined' do
73
+ RealPush.logger.debug('foo')
74
+ expect(RealPush.logger).to be_kind_of(Logger)
75
+ end
76
+ end
77
+
78
+ describe 'logging configuration' do
79
+ it "can be configured to use any logger" do
80
+ logger = double("ALogger")
81
+ expect(logger).to receive(:debug).with('foo')
82
+ RealPush.logger = logger
83
+ RealPush.logger.debug('foo')
84
+ RealPush.logger = nil
85
+ end
86
+ end
87
+
88
+ describe 'configuration using url' do
89
+ it 'should be possible to configure everything by setting the url' do
90
+ @client1.url = 'http://123456789:private@127.0.0.1:5678'
91
+ expect(@client1.scheme).to eq 'http'
92
+ expect(@client1.app_id).to eq '123456789'
93
+ expect(@client1.privatekey).to eq 'private'
94
+ expect(@client1.hostname).to eq '127.0.0.1'
95
+ expect(@client1.port).to eq 5678
96
+ end
97
+
98
+ it 'should override scheme and port when setting encrypted=true after url' do
99
+ @client1.url = 'http://secret@127.0.0.1:5678'
100
+ @client1.encrypted = true
101
+
102
+ expect(@client1.scheme).to eq 'https'
103
+ expect(@client1.port).to eq 443
104
+ end
105
+
106
+ it "should fail on bad urls" do
107
+ expect { @client1.url = "gopher/somekey:somesecret@://127.0.0.1://m:8080" }.to raise_error
108
+ end
109
+ end
110
+
111
+ describe 'trigger events do server' do
112
+
113
+ it 'should be able trigger a event to RealPush server' do
114
+ @client1.authenticate 'api_id', 'apisecret'
115
+ api_path = %r{/api_id/events/event-name/}
116
+
117
+ stub_request(:post, api_path).
118
+ with({
119
+ :headers => { 'X-RealPush-Secret-Key' => 'apisecret' }
120
+ }).
121
+ to_return({
122
+ :status => 202
123
+ })
124
+ @client1.trigger ['channel-name'], 'event-name', {data: 'content'}
125
+ end
126
+
127
+ end
128
+
129
+ describe 'Private commands' do
130
+ expect_hash = {auth:'70bb4f429346ba2287bca93b4c9cd9cc1d29c00c76d0ecf6b5bc44c7cc0f67f7'}
131
+
132
+ it 'authentication token to private subscribe from string' do
133
+ @client1.authenticate 'apikey', 'apisecret'
134
+ body = MultiJson.encode({data:{}, channel: 'private-channel'})
135
+ expect(@client1.authentication_string body).to eq expect_hash
136
+ end
137
+
138
+ it 'authentication token to private subscribe from hash' do
139
+ @client1.authenticate 'apikey', 'apisecret'
140
+ body = {data:{}, channel: 'private-channel'}
141
+ expect(@client1.authentication_string body).to eq expect_hash
142
+ end
143
+
144
+ end
145
+
146
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe RealPush::Request do
4
+ before do
5
+ @client = RealPush.default_client
6
+ @client.authenticate 'key', 'secret'
7
+ end
8
+
9
+ describe 'parameters in initializer' do
10
+ it 'should give error when client parameter is not RealPush::Client' do
11
+ expect { RealPush::Request.new(@client, 'GET', @client.url, {}) }.not_to raise_error
12
+ expect { RealPush::Request.new('client', 'GET', @client.url, {}) }.to raise_error(RealPush::ConfigurationError)
13
+ end
14
+
15
+ it 'should receive GET or POST parameter in the verb' do
16
+ expect { RealPush::Request.new(@client, 'GET', @client.url, {}) }.not_to raise_error
17
+ expect { RealPush::Request.new(@client, 'POST', @client.url, {}) }.not_to raise_error
18
+ expect { RealPush::Request.new(@client, 'PATH', @client.url, {}) }.to raise_error(RealPush::ConfigurationError)
19
+ end
20
+
21
+ it 'should give error when uri parameter is not URI' do
22
+ expect { RealPush::Request.new(@client, 'GET', @client.url, {}) }.not_to raise_error
23
+ expect { RealPush::Request.new(@client, 'GET', '', {}) }.to raise_error(RealPush::ConfigurationError)
24
+ end
25
+
26
+ end
27
+
28
+ describe 'verbs request' do
29
+ it 'should be able to send a GET request' do
30
+ api_path = %r{/key/channels/channel-name/}
31
+ stub_request(:get, api_path).
32
+ with({
33
+ :headers => {'X-RealPush-Secret-Key' => 'secret'},
34
+ :query => hash_including({'auth_key'=>'key'})
35
+ }).
36
+ to_return(:status => 202)
37
+ RealPush::Request.new(@client, 'GET', @client.url('key/channels/channel-name/'), {}).send_sync
38
+ end
39
+
40
+ it 'should be able to send a POST request' do
41
+ api_path = %r{/key/channels/channel-name/}
42
+ stub_request(:post, api_path).
43
+ with({
44
+ :headers => {'X-RealPush-Secret-Key' => 'secret'},
45
+ :body => {foo: 'bar'}
46
+ }).
47
+ to_return(:status => 202)
48
+ RealPush::Request.new(@client, 'POST', @client.url('key/channels/channel-name/'), {}, MultiJson.encode({foo: 'bar'})).send_sync
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'although not required, it is recommended that you use bundler when running the tests'
5
+ end
6
+
7
+ # Run Coverage report
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ add_group 'Libraries', 'lib'
11
+ end
12
+
13
+ require File.expand_path( '../../lib/realpush', __FILE__ )
14
+ require 'rspec'
15
+ require 'em-http' # As of webmock 1.4.0, em-http must be loaded first
16
+ require 'webmock/rspec'
17
+
18
+ # Report to codeclimate
19
+ require 'codeclimate-test-reporter'
20
+ CodeClimate::TestReporter.start
21
+
22
+ RSpec.configure do |config|
23
+ config.before(:each) do
24
+ WebMock.reset!
25
+ WebMock.disable_net_connect!(:allow => 'codeclimate.com')
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,288 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: realpush
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zaez Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: signature
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.12
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.12
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: growl
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: em-http-request
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.1.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.1.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: rake
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '10.0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '10.0'
223
+ description: |-
224
+ RealPush is a private and commercial system to send notifications via websocket.
225
+ The system allows the creation of applications based on its quota through access API.
226
+ Sending notifications to trigger customers with private and public channels. Synchronous and asynchronous requests..
227
+ email:
228
+ - contato@zaez.net
229
+ executables: []
230
+ extensions: []
231
+ extra_rdoc_files: []
232
+ files:
233
+ - ".gitignore"
234
+ - ".idea/encodings.xml"
235
+ - ".idea/scopes/scope_settings.xml"
236
+ - ".rspec"
237
+ - ".travis.yml"
238
+ - Gemfile
239
+ - Guardfile
240
+ - LICENSE
241
+ - README.md
242
+ - Rakefile
243
+ - lib/realpush.rb
244
+ - lib/realpush/api/app.rb
245
+ - lib/realpush/api/base.rb
246
+ - lib/realpush/api/base_create.rb
247
+ - lib/realpush/api/base_destroy.rb
248
+ - lib/realpush/api/base_list.rb
249
+ - lib/realpush/api/base_update.rb
250
+ - lib/realpush/client.rb
251
+ - lib/realpush/request.rb
252
+ - lib/realpush/resource.rb
253
+ - lib/realpush/version.rb
254
+ - realpush.gemspec
255
+ - spec/realpush/api/app_spec.rb
256
+ - spec/realpush/client_spec.rb
257
+ - spec/realpush/request_spec.rb
258
+ - spec/spec_helper.rb
259
+ homepage: http://realpush.cc/
260
+ licenses:
261
+ - MIT
262
+ metadata: {}
263
+ post_install_message:
264
+ rdoc_options: []
265
+ require_paths:
266
+ - lib
267
+ required_ruby_version: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ required_rubygems_version: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: '0'
277
+ requirements: []
278
+ rubyforge_project:
279
+ rubygems_version: 2.2.2
280
+ signing_key:
281
+ specification_version: 4
282
+ summary: Library of integration with RealPush system. Written in Ruby.
283
+ test_files:
284
+ - spec/realpush/api/app_spec.rb
285
+ - spec/realpush/client_spec.rb
286
+ - spec/realpush/request_spec.rb
287
+ - spec/spec_helper.rb
288
+ has_rdoc: