connect_client 0.2.2 → 0.3.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.
@@ -1,125 +1,125 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'webmock/minitest'
4
- require 'connect_client/http/event_endpoint'
5
- require 'connect_client/event_push_response'
6
- require 'connect_client/event'
7
- require 'connect_client/configuration'
8
- require 'securerandom'
9
-
10
- describe ConnectClient::Http::EventEndpoint do
11
- before do
12
- @endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new)
13
- @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
- @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
- @sample_event = ConnectClient::Event.new(@sample_event_data)
16
- @sample_events_reponse = '{"sample": [{"success": true}]}'
17
- @sample_collection = 'sample'
18
- @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
- @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
- end
21
-
22
- it "should get a push response back when pushing a single event to a collection" do
23
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
25
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
-
27
- response = @endpoint.push @sample_collection, @sample_event
28
-
29
- response.must_be_instance_of ConnectClient::EventPushResponse
30
- end
31
-
32
- it "should get push to overriden base_url" do
33
- overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
34
- endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
35
- stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
36
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
37
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
38
-
39
- response = endpoint.push @sample_collection, @sample_event
40
-
41
- response.must_be_instance_of ConnectClient::EventPushResponse
42
- end
43
-
44
- it "should get push response for a non sucessful error code" do
45
- overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
46
- endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
47
- stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
48
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
49
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
50
-
51
- response = endpoint.push @sample_collection, @sample_event
52
-
53
- response.http_status_code.to_s.must_equal '500'
54
- end
55
-
56
- it "should get a push response back when pushing batches" do
57
- stub_request(:post, "https://api.getconnect.io/events").
58
- with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
59
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
60
-
61
- response = @endpoint.push_batch @sample_batch
62
- response.must_be_instance_of ConnectClient::EventPushResponse
63
- end
64
-
65
- it "should get a push response back when pushing a single event to a collection async" do
66
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
67
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
68
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
69
-
70
- EM.run do
71
- @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
72
- begin
73
- response.must_be_instance_of ConnectClient::EventPushResponse
74
- ensure
75
- EM.stop
76
- end
77
- }.error_occured { |error|
78
- EM.stop
79
- raise error
80
- }
81
- end
82
- end
83
-
84
- it "should get push response for a non sucessful error code async" do
85
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
86
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
87
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
88
-
89
- EM.run do
90
- @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
91
- begin
92
- response.http_status_code.to_s.must_equal '500'
93
- ensure
94
- EM.stop
95
- end
96
- }.error_occured { |error|
97
- EM.stop
98
- raise error
99
- }
100
- end
101
- end
102
-
103
- it "should get a push response back when pushing batches" do
104
- stub_request(:post, "https://api.getconnect.io/events").
105
- with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
106
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
107
-
108
- EM.run do
109
- @async_endpoint.push_batch(@sample_batch).response_received { |response|
110
- begin
111
- response.must_be_instance_of ConnectClient::EventPushResponse
112
- ensure
113
- EM.stop
114
- end
115
- }.error_occured { |error|
116
- EM.stop
117
- raise error
118
- }
119
- end
120
- end
121
-
122
- it "should throw an async exception if EM is not running" do
123
- proc { @async_endpoint.push_batch(@sample_batch) }.must_raise ConnectClient::Http::AsyncHttpError
124
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'connect_client/http/event_endpoint'
5
+ require 'connect_client/event_push_response'
6
+ require 'connect_client/event'
7
+ require 'connect_client/configuration'
8
+ require 'securerandom'
9
+
10
+ describe ConnectClient::Http::EventEndpoint do
11
+ before do
12
+ @endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new)
13
+ @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
+ @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
+ @sample_event = ConnectClient::Event.new(@sample_event_data)
16
+ @sample_events_reponse = '{"sample": [{"success": true}]}'
17
+ @sample_collection = 'sample'
18
+ @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
+ @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
+ end
21
+
22
+ it "should get a push response back when pushing a single event to a collection" do
23
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
25
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
+
27
+ response = @endpoint.push @sample_collection, @sample_event
28
+
29
+ response.must_be_instance_of ConnectClient::EventPushResponse
30
+ end
31
+
32
+ it "should get push to overriden base_url" do
33
+ overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
34
+ endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
35
+ stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
36
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
37
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
38
+
39
+ response = endpoint.push @sample_collection, @sample_event
40
+
41
+ response.must_be_instance_of ConnectClient::EventPushResponse
42
+ end
43
+
44
+ it "should get push response for a non sucessful error code" do
45
+ overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
46
+ endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
47
+ stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
48
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
49
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
50
+
51
+ response = endpoint.push @sample_collection, @sample_event
52
+
53
+ response.http_status_code.to_s.must_equal '500'
54
+ end
55
+
56
+ it "should get a push response back when pushing batches" do
57
+ stub_request(:post, "https://api.getconnect.io/events").
58
+ with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
59
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
60
+
61
+ response = @endpoint.push_batch @sample_batch
62
+ response.must_be_instance_of ConnectClient::EventPushResponse
63
+ end
64
+
65
+ it "should get a push response back when pushing a single event to a collection async" do
66
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
67
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
68
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
69
+
70
+ EM.run do
71
+ @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
72
+ begin
73
+ response.must_be_instance_of ConnectClient::EventPushResponse
74
+ ensure
75
+ EM.stop
76
+ end
77
+ }.error_occured { |error|
78
+ EM.stop
79
+ raise error
80
+ }
81
+ end
82
+ end
83
+
84
+ it "should get push response for a non sucessful error code async" do
85
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
86
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
87
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
88
+
89
+ EM.run do
90
+ @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
91
+ begin
92
+ response.http_status_code.to_s.must_equal '500'
93
+ ensure
94
+ EM.stop
95
+ end
96
+ }.error_occured { |error|
97
+ EM.stop
98
+ raise error
99
+ }
100
+ end
101
+ end
102
+
103
+ it "should get a push response back when pushing batches" do
104
+ stub_request(:post, "https://api.getconnect.io/events").
105
+ with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
106
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
107
+
108
+ EM.run do
109
+ @async_endpoint.push_batch(@sample_batch).response_received { |response|
110
+ begin
111
+ response.must_be_instance_of ConnectClient::EventPushResponse
112
+ ensure
113
+ EM.stop
114
+ end
115
+ }.error_occured { |error|
116
+ EM.stop
117
+ raise error
118
+ }
119
+ end
120
+ end
121
+
122
+ it "should throw an async exception if EM is not running" do
123
+ proc { @async_endpoint.push_batch(@sample_batch) }.must_raise ConnectClient::Http::AsyncHttpError
124
+ end
125
125
  end
@@ -1,60 +1,60 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'webmock/minitest'
4
- require 'connect_client/client'
5
- require 'connect_client/configuration'
6
- require 'connect_client/event_push_response'
7
- require 'securerandom'
8
- require 'em-synchrony'
9
- require 'em-synchrony/em-http'
10
-
11
- describe ConnectClient::Http::EventEndpoint, "Test with syncrony defined" do
12
- before do
13
- @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
- @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
- @sample_event = ConnectClient::Event.new(@sample_event_data)
16
- @sample_events_reponse = '{"sample": [{"success": true}]}'
17
- @sample_collection = 'sample'
18
- @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
- @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
- end
21
-
22
- it "should get a push response back when pushing a single event to a collection" do
23
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
- with(:body => @sample_event_data).
25
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
-
27
- response = nil
28
- EM.synchrony do
29
- response = @async_endpoint.push @sample_collection, @sample_event
30
- EM.stop
31
- end
32
- response.must_be_instance_of ConnectClient::EventPushResponse
33
- end
34
-
35
- it "should get push response for a non sucessful error code" do
36
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
37
- with(:body => @sample_event_data).
38
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
39
-
40
- response = nil
41
- EM.synchrony do
42
- response = @async_endpoint.push @sample_collection, @sample_event
43
- EM.stop
44
- end
45
- response.http_status_code.to_s.must_equal '500'
46
- end
47
-
48
- it "should get a push response back when pushing batches" do
49
- stub_request(:post, "https://api.getconnect.io/events").
50
- with(:body => @sample_batch_data).
51
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
52
-
53
- response = nil
54
- EM.synchrony do
55
- response = @async_endpoint.push_batch @sample_batch
56
- EM.stop
57
- end
58
- response.must_be_instance_of ConnectClient::EventPushResponse
59
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'connect_client/client'
5
+ require 'connect_client/configuration'
6
+ require 'connect_client/event_push_response'
7
+ require 'securerandom'
8
+ require 'em-synchrony'
9
+ require 'em-synchrony/em-http'
10
+
11
+ describe ConnectClient::Http::EventEndpoint, "Test with syncrony defined" do
12
+ before do
13
+ @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
+ @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
+ @sample_event = ConnectClient::Event.new(@sample_event_data)
16
+ @sample_events_reponse = '{"sample": [{"success": true}]}'
17
+ @sample_collection = 'sample'
18
+ @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
+ @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
+ end
21
+
22
+ it "should get a push response back when pushing a single event to a collection" do
23
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
+ with(:body => @sample_event_data).
25
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
+
27
+ response = nil
28
+ EM.synchrony do
29
+ response = @async_endpoint.push @sample_collection, @sample_event
30
+ EM.stop
31
+ end
32
+ response.must_be_instance_of ConnectClient::EventPushResponse
33
+ end
34
+
35
+ it "should get push response for a non sucessful error code" do
36
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
37
+ with(:body => @sample_event_data).
38
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
39
+
40
+ response = nil
41
+ EM.synchrony do
42
+ response = @async_endpoint.push @sample_collection, @sample_event
43
+ EM.stop
44
+ end
45
+ response.http_status_code.to_s.must_equal '500'
46
+ end
47
+
48
+ it "should get a push response back when pushing batches" do
49
+ stub_request(:post, "https://api.getconnect.io/events").
50
+ with(:body => @sample_batch_data).
51
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
52
+
53
+ response = nil
54
+ EM.synchrony do
55
+ response = @async_endpoint.push_batch @sample_batch
56
+ EM.stop
57
+ end
58
+ response.must_be_instance_of ConnectClient::EventPushResponse
59
+ end
60
60
  end
@@ -0,0 +1,13 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'connect_client/security/filtered_key_generation'
4
+
5
+ describe ConnectClient::Security do
6
+ it "should generate a symmetrical filtered key" do
7
+ keyJson = '{"filters":{"customerId":5},"canPush":false,"canQuery":true}'
8
+ master_key = "2fMSlDSOGtMWH50wffnCscgGMcJGMQ0s"
9
+ filtered_key = ConnectClient::Security.generate_filtered_key(keyJson, master_key)
10
+ generated_key_json = ConnectClient::Security.generate_key_json(filtered_key, master_key)
11
+ generated_key_json.must_equal keyJson
12
+ end
13
+ end
@@ -1,25 +1,25 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'connect_client/configuration'
4
- require 'connect_client'
5
-
6
- describe ConnectClient do
7
- before do
8
- ConnectClient.reset
9
- end
10
-
11
- it "should throw a configuration error configuration has not been called" do
12
- connect_event = proc { ConnectClient.push 'test', {} }.must_raise ConnectClient::UnconfiguredError
13
- end
14
-
15
- it "should respond to push" do
16
- ConnectClient.configure {}
17
- ConnectClient.respond_to?(:push).must_equal true
18
- end
19
-
20
- it "should support configuration via a block" do
21
- ConnectClient.configure do |config|
22
- config.must_be_instance_of ConnectClient::Configuration
23
- end
24
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'connect_client/configuration'
4
+ require 'connect_client'
5
+
6
+ describe ConnectClient do
7
+ before do
8
+ ConnectClient.reset
9
+ end
10
+
11
+ it "should throw a configuration error configuration has not been called" do
12
+ connect_event = proc { ConnectClient.push 'test', {} }.must_raise ConnectClient::UnconfiguredError
13
+ end
14
+
15
+ it "should respond to push" do
16
+ ConnectClient.configure {}
17
+ ConnectClient.respond_to?(:push).must_equal true
18
+ end
19
+
20
+ it "should support configuration via a block" do
21
+ ConnectClient.configure do |config|
22
+ config.must_be_instance_of ConnectClient::Configuration
23
+ end
24
+ end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connect_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Connect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -114,13 +114,15 @@ files:
114
114
  - lib/connect_client/event_push_response.rb
115
115
  - lib/connect_client/http/deferred_http_response.rb
116
116
  - lib/connect_client/http/event_endpoint.rb
117
+ - lib/connect_client/security/filtered_key_generation.rb
117
118
  - lib/connect_client/version.rb
118
119
  - spec/connect_client/client_spec.rb
119
120
  - spec/connect_client/configuration_spec.rb
120
121
  - spec/connect_client/event_push_response_spec.rb
121
122
  - spec/connect_client/event_spec.rb
122
123
  - spec/connect_client/http/http_event_endpoint_spec.rb
123
- - spec/connect_client/http/synchrony/event_endpoint_spec.rb
124
+ - spec/connect_client/http/synchrony/http_event_endpoint_spec.rb
125
+ - spec/connect_client/security/filtered_key_generation_spec.rb
124
126
  - spec/connect_client_spec.rb
125
127
  homepage: https://github.com/getconnect/connect-rb
126
128
  licenses:
@@ -152,5 +154,6 @@ test_files:
152
154
  - spec/connect_client/event_push_response_spec.rb
153
155
  - spec/connect_client/event_spec.rb
154
156
  - spec/connect_client/http/http_event_endpoint_spec.rb
155
- - spec/connect_client/http/synchrony/event_endpoint_spec.rb
157
+ - spec/connect_client/http/synchrony/http_event_endpoint_spec.rb
158
+ - spec/connect_client/security/filtered_key_generation_spec.rb
156
159
  - spec/connect_client_spec.rb