eventflit 0.1.0
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.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +24 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +301 -0
- data/Rakefile +11 -0
- data/eventflit.gemspec +33 -0
- data/examples/async_message.rb +28 -0
- data/lib/eventflit.rb +69 -0
- data/lib/eventflit/channel.rb +185 -0
- data/lib/eventflit/client.rb +437 -0
- data/lib/eventflit/native_notification/client.rb +68 -0
- data/lib/eventflit/request.rb +109 -0
- data/lib/eventflit/resource.rb +36 -0
- data/lib/eventflit/version.rb +3 -0
- data/lib/eventflit/webhook.rb +110 -0
- data/spec/channel_spec.rb +170 -0
- data/spec/client_spec.rb +629 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/web_hook_spec.rb +117 -0
- metadata +207 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
ENV['EVENTFLIT_URL']= 'http://some:secret@service.eventflit.com:441/apps/54'
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'em-http' # As of webmock 1.4.0, em-http must be loaded first
|
11
|
+
require 'webmock/rspec'
|
12
|
+
|
13
|
+
require 'eventflit'
|
14
|
+
require 'eventmachine'
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.before(:each) do
|
18
|
+
WebMock.reset!
|
19
|
+
WebMock.disable_net_connect!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def hmac(key, data)
|
24
|
+
digest = OpenSSL::Digest::SHA256.new
|
25
|
+
OpenSSL::HMAC.hexdigest(digest, key, data)
|
26
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
describe Eventflit::WebHook do
|
7
|
+
before :each do
|
8
|
+
@hook_data = {
|
9
|
+
"time_ms" => 123456,
|
10
|
+
"events" => [
|
11
|
+
{"name" => 'foo'}
|
12
|
+
]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "initialization" do
|
17
|
+
it "can be initialized with Rack::Request" do
|
18
|
+
request = Rack::Request.new({
|
19
|
+
'HTTP_X_EVENTFLIT_KEY' => '1234',
|
20
|
+
'HTTP_X_EVENTFLIT_SIGNATURE' => 'asdf',
|
21
|
+
'CONTENT_TYPE' => 'application/json',
|
22
|
+
'rack.input' => StringIO.new(MultiJson.encode(@hook_data))
|
23
|
+
})
|
24
|
+
wh = Eventflit::WebHook.new(request)
|
25
|
+
expect(wh.key).to eq('1234')
|
26
|
+
expect(wh.signature).to eq('asdf')
|
27
|
+
expect(wh.data).to eq(@hook_data)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can be initialized with a hash" do
|
31
|
+
request = {
|
32
|
+
:key => '1234',
|
33
|
+
:signature => 'asdf',
|
34
|
+
:content_type => 'application/json',
|
35
|
+
:body => MultiJson.encode(@hook_data),
|
36
|
+
}
|
37
|
+
wh = Eventflit::WebHook.new(request)
|
38
|
+
expect(wh.key).to eq('1234')
|
39
|
+
expect(wh.signature).to eq('asdf')
|
40
|
+
expect(wh.data).to eq(@hook_data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "after initialization" do
|
45
|
+
before :each do
|
46
|
+
@body = MultiJson.encode(@hook_data)
|
47
|
+
request = {
|
48
|
+
:key => '1234',
|
49
|
+
:signature => hmac('asdf', @body),
|
50
|
+
:content_type => 'application/json',
|
51
|
+
:body => @body
|
52
|
+
}
|
53
|
+
|
54
|
+
@client = Eventflit::Client.new
|
55
|
+
@wh = Eventflit::WebHook.new(request, @client)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should validate" do
|
59
|
+
@client.key = '1234'
|
60
|
+
@client.secret = 'asdf'
|
61
|
+
expect(@wh).to be_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not validate if key is wrong" do
|
65
|
+
@client.key = '12345'
|
66
|
+
@client.secret = 'asdf'
|
67
|
+
expect(Eventflit.logger).to receive(:warn).with("Received webhook with unknown key: 1234")
|
68
|
+
expect(@wh).not_to be_valid
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not validate if secret is wrong" do
|
72
|
+
@client.key = '1234'
|
73
|
+
@client.secret = 'asdfxxx'
|
74
|
+
digest = OpenSSL::Digest::SHA256.new
|
75
|
+
expected = OpenSSL::HMAC.hexdigest(digest, @client.secret, @body)
|
76
|
+
expect(Eventflit.logger).to receive(:warn).with("Received WebHook with invalid signature: got #{@wh.signature}, expected #{expected}")
|
77
|
+
expect(@wh).not_to be_valid
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should validate with an extra token" do
|
81
|
+
@client.key = '12345'
|
82
|
+
@client.secret = 'xxx'
|
83
|
+
expect(@wh.valid?({:key => '1234', :secret => 'asdf'})).to be_truthy
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should validate with an array of extra tokens" do
|
87
|
+
@client.key = '123456'
|
88
|
+
@client.secret = 'xxx'
|
89
|
+
expect(@wh.valid?([
|
90
|
+
{:key => '12345', :secret => 'wtf'},
|
91
|
+
{:key => '1234', :secret => 'asdf'}
|
92
|
+
])).to be_truthy
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not validate if all keys are wrong with extra tokens" do
|
96
|
+
@client.key = '123456'
|
97
|
+
@client.secret = 'asdf'
|
98
|
+
expect(Eventflit.logger).to receive(:warn).with("Received webhook with unknown key: 1234")
|
99
|
+
expect(@wh.valid?({:key => '12345', :secret => 'asdf'})).to be_falsey
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not validate if secret is wrong with extra tokens" do
|
103
|
+
@client.key = '123456'
|
104
|
+
@client.secret = 'asdfxxx'
|
105
|
+
expect(Eventflit.logger).to receive(:warn).with(/Received WebHook with invalid signature/)
|
106
|
+
expect(@wh.valid?({:key => '1234', :secret => 'wtf'})).to be_falsey
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should expose events" do
|
110
|
+
expect(@wh.events).to eq(@hook_data["events"])
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should expose time" do
|
114
|
+
expect(@wh.time).to eq(Time.at(123.456))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eventflit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eventflit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-24 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: pusher-signature
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpclient
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: em-http-request
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.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: 1.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: addressable
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.4.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.4.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 10.4.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 10.4.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.6.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.6.4
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: json
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.8.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.8.3
|
153
|
+
description: Wrapper for eventflit.com REST api
|
154
|
+
email:
|
155
|
+
- support@eventflit.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".document"
|
161
|
+
- ".gemtest"
|
162
|
+
- ".gitignore"
|
163
|
+
- ".travis.yml"
|
164
|
+
- CHANGELOG.md
|
165
|
+
- Gemfile
|
166
|
+
- LICENSE
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- eventflit.gemspec
|
170
|
+
- examples/async_message.rb
|
171
|
+
- lib/eventflit.rb
|
172
|
+
- lib/eventflit/channel.rb
|
173
|
+
- lib/eventflit/client.rb
|
174
|
+
- lib/eventflit/native_notification/client.rb
|
175
|
+
- lib/eventflit/request.rb
|
176
|
+
- lib/eventflit/resource.rb
|
177
|
+
- lib/eventflit/version.rb
|
178
|
+
- lib/eventflit/webhook.rb
|
179
|
+
- spec/channel_spec.rb
|
180
|
+
- spec/client_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
- spec/web_hook_spec.rb
|
183
|
+
homepage: http://github.com/eventflit/eventflit-http-ruby
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
metadata: {}
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
require_paths:
|
190
|
+
- lib
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
requirements: []
|
202
|
+
rubyforge_project:
|
203
|
+
rubygems_version: 2.5.2.1
|
204
|
+
signing_key:
|
205
|
+
specification_version: 4
|
206
|
+
summary: Eventflit API client
|
207
|
+
test_files: []
|