intellisense-ruby 0.6.5

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,118 @@
1
+ require 'intellisense-ruby'
2
+ require 'spec_helper'
3
+ require 'pp'
4
+
5
+ describe Intellisense::Client do
6
+
7
+ describe '#init' do
8
+
9
+ it 'should error if no secret is supplied' do
10
+ expect { Intellisense::Client.new }.to raise_error(RuntimeError)
11
+ end
12
+
13
+ it 'should not error if a secret is supplied' do
14
+ Intellisense::Client.new secret: IntellisenseHelpers::SECRET
15
+ end
16
+
17
+ pp 'Testing pretty print'
18
+ end
19
+
20
+ describe '#describe' do
21
+
22
+ before(:all) do
23
+ @client = Intellisense::Client.new secret: IntellisenseHelpers::SECRET
24
+ end
25
+
26
+ it 'should error without an entity' do
27
+ expect { @client.describe(entity_id: 'test-id-12321') }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it 'should error without a entity_id' do
31
+ expect { @client.describe(type: 'User') }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'should error if properties is not a hash' do
35
+ expect {
36
+ @client.describe(entity_id: 'test-id-12321', type: 'User', properties: [1,2,3])
37
+ }.to raise_error(ArgumentError)
38
+ end
39
+
40
+ it 'should not error with the required options' do
41
+ @client.describe IntellisenseHelpers::Queued::DESCRIBE
42
+ end
43
+ end
44
+
45
+ describe '#track' do
46
+
47
+ before(:all) do
48
+ @client = Intellisense::Client.new secret: IntellisenseHelpers::SECRET
49
+ end
50
+
51
+ it 'should error without an event' do
52
+ expect { @client.track(user_id: 'user') }.to raise_error(ArgumentError)
53
+ end
54
+
55
+ it 'should error without a user_id' do
56
+ expect { @client.track(event: 'Event') }.to raise_error(ArgumentError)
57
+ end
58
+
59
+ it 'should error if properties is not a hash' do
60
+ expect {
61
+ @client.track(user_id: 'user', event: 'Event', properties: [1,2,3])
62
+ }.to raise_error(ArgumentError)
63
+ end
64
+
65
+ it 'should not error with the required options' do
66
+ @client.track IntellisenseHelpers::Queued::TRACK
67
+ end
68
+ end
69
+
70
+
71
+ describe '#identify' do
72
+
73
+ before(:all) do
74
+ @client = Intellisense::Client.new secret: IntellisenseHelpers::SECRET
75
+ end
76
+
77
+ it 'should error without any user id' do
78
+ expect { @client.identify({}) }.to raise_error(ArgumentError)
79
+ end
80
+
81
+ it 'should not error with the required options' do
82
+ @client.identify IntellisenseHelpers::Queued::IDENTIFY
83
+ end
84
+ end
85
+
86
+ describe '#alias' do
87
+ before :all do
88
+ @client = Intellisense::Client.new secret: IntellisenseHelpers::SECRET
89
+ end
90
+
91
+ it 'should error without from' do
92
+ expect { @client.alias to: 1234 }.to raise_error(ArgumentError)
93
+ end
94
+
95
+ it 'should error without to' do
96
+ expect { @client.alias from: 1234 }.to raise_error(ArgumentError)
97
+ end
98
+
99
+ it 'should not error with the required options' do
100
+ @client.alias IntellisenseHelpers::ALIAS
101
+ end
102
+ end
103
+
104
+ describe '#flush' do
105
+ before(:all) do
106
+ @client = Intellisense::Client.new secret: IntellisenseHelpers::SECRET
107
+ end
108
+
109
+ it 'should wait for the queue to finish on a flush' do
110
+ @client.identify IntellisenseHelpers::Queued::IDENTIFY
111
+ @client.track IntellisenseHelpers::Queued::TRACK
112
+ @client.flush
113
+ @client.queued_messages.should == 0
114
+ end
115
+ end
116
+ end
117
+
118
+
@@ -0,0 +1,88 @@
1
+ require 'intellisense-ruby'
2
+ require 'thread'
3
+ require 'spec_helper'
4
+
5
+ describe Intellisense::Consumer do
6
+
7
+ describe '#flush' do
8
+
9
+ it 'should not error if the endpoint is unreachable' do
10
+
11
+ Faraday::Connection.any_instance.stub(:post).and_raise(Exception)
12
+
13
+ queue = Queue.new
14
+ queue << {}
15
+ consumer = Intellisense::Consumer.new(queue, 'secret')
16
+ consumer.flush
17
+
18
+ queue.should be_empty
19
+
20
+ Faraday::Connection.any_instance.unstub(:post)
21
+ end
22
+
23
+ it 'should execute the error handler if the request is invalid' do
24
+
25
+ Intellisense::Request.any_instance
26
+ .stub(:post)
27
+ .and_return(Intellisense::Response.new(400, "Some error"))
28
+
29
+ on_error = Proc.new do |status, error|
30
+ puts "#{status}, #{error}"
31
+ end
32
+
33
+ on_error.should_receive(:call).once
34
+
35
+ queue = Queue.new
36
+ queue << {}
37
+ consumer = Intellisense::Consumer.new(queue, 'secret', { on_error: on_error })
38
+ consumer.flush
39
+
40
+ Intellisense::Request::any_instance.unstub(:post)
41
+
42
+ queue.should be_empty
43
+ end
44
+
45
+ it 'should not call on_error if the request is good' do
46
+
47
+ # on_error = Proc.new do |status, error|
48
+ # puts "#{status}, #{error}"
49
+ # end
50
+
51
+ # on_error.should_receive(:call).at_most(0).times
52
+
53
+ # queue = Queue.new
54
+ # queue << IntellisenseHelpers::Requested::TRACK
55
+ # consumer = Intellisense::Consumer.new(queue, 'testsecret', { on_error: on_error })
56
+ # consumer.flush
57
+
58
+ # queue.should be_empty
59
+ end
60
+ end
61
+
62
+ describe '#is_requesting?' do
63
+
64
+ it 'should not return true if there isn\'t a current batch' do
65
+
66
+ queue = Queue.new
67
+ consumer = Intellisense::Consumer.new(queue, 'testsecret')
68
+
69
+ consumer.is_requesting?.should == false
70
+ end
71
+
72
+ it 'should return true if there is a current batch' do
73
+
74
+ queue = Queue.new
75
+ queue << IntellisenseHelpers::Requested::TRACK
76
+ consumer = Intellisense::Consumer.new(queue, 'testsecret')
77
+
78
+ Thread.new {
79
+ consumer.flush
80
+ consumer.is_requesting?.should == false
81
+ }
82
+
83
+ # sleep barely long enough to let thread flush the queue.
84
+ sleep(0.001)
85
+ consumer.is_requesting?.should == true
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,81 @@
1
+ require 'intellisense-ruby'
2
+ require 'spec_helper'
3
+
4
+ describe Intellisense do
5
+
6
+ describe '#not-initialized' do
7
+ it 'should ignore calls to track if not initialized' do
8
+ expect { Intellisense.track({}) }.not_to raise_error
9
+ end
10
+
11
+ it 'should return false on track if not initialized' do
12
+ Intellisense.track({}).should == false
13
+ end
14
+
15
+ it 'should ignore calls to identify if not initialized' do
16
+ expect { Intellisense.identify({}) }.not_to raise_error
17
+ end
18
+
19
+ it 'should return false on identify if not initialized' do
20
+ Intellisense.identify({}).should == false
21
+ end
22
+ end
23
+
24
+ describe '#init' do
25
+
26
+ it 'should successfully init' do
27
+ Intellisense.init secret: IntellisenseHelpers::SECRET
28
+ end
29
+ end
30
+
31
+ describe '#track' do
32
+
33
+ it 'should error without an event' do
34
+ expect { Intellisense.track user_id: 'user' }.to raise_error(ArgumentError)
35
+ end
36
+
37
+ it 'should error without a user_id' do
38
+ expect { Intellisense.track event: 'Event' }.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it 'should not error with the required options' do
42
+ Intellisense.track IntellisenseHelpers::Queued::TRACK
43
+ sleep(1)
44
+ end
45
+ end
46
+
47
+
48
+ describe '#identify' do
49
+ it 'should error without a user_id' do
50
+ expect { Intellisense.identify traits: {} }.to raise_error(ArgumentError)
51
+ end
52
+
53
+ it 'should not error with the required options' do
54
+ Intellisense.identify IntellisenseHelpers::Queued::IDENTIFY
55
+ sleep(1)
56
+ end
57
+ end
58
+
59
+ describe '#alias' do
60
+ it 'should error without from' do
61
+ expect { Intellisense.alias to: 1234 }.to raise_error(ArgumentError)
62
+ end
63
+
64
+ it 'should error without to' do
65
+ expect { Intellisense.alias from: 1234 }.to raise_error(ArgumentError)
66
+ end
67
+
68
+ it 'should not error with the required options' do
69
+ Intellisense.alias IntellisenseHelpers::ALIAS
70
+ sleep(1)
71
+ end
72
+ end
73
+
74
+ describe '#flush' do
75
+
76
+ it 'should flush without error' do
77
+ Intellisense.identify IntellisenseHelpers::Queued::IDENTIFY
78
+ Intellisense.flush
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,55 @@
1
+
2
+ module IntellisenseHelpers
3
+
4
+ SECRET = 'testsecret'
5
+
6
+ DESCRIBE = { type: 'User',
7
+ properties: {
8
+ firstName: 'Jane',
9
+ lastName: 'Smythe',
10
+ created: Time.new
11
+ }
12
+ }
13
+
14
+ TRACK = { event: 'Ruby Library test event',
15
+ properties: {
16
+ type: 'Chocolate',
17
+ is_a_lie: true,
18
+ layers: 20,
19
+ created: Time.new
20
+ }
21
+ }
22
+
23
+ IDENTIFY = { traits: {
24
+ likes_animals: true,
25
+ instrument: 'Guitar',
26
+ age: 25
27
+ },
28
+ action: 'identify'
29
+ }
30
+
31
+ ALIAS = { from: 1234,
32
+ to: 'abcd' }
33
+
34
+ USER_ID = 1234
35
+ ENTITY_ID = 1234
36
+
37
+ # Hashes sent to the client
38
+ module Queued
39
+
40
+ DESCRIBE = DESCRIBE.merge({ entity_id: ENTITY_ID })
41
+
42
+ TRACK = TRACK.merge({ user_id: USER_ID })
43
+
44
+ IDENTIFY = IDENTIFY.merge({ user_id: USER_ID })
45
+ end
46
+
47
+ # Hashes which are sent from the consumer
48
+ module Requested
49
+ TRACK = TRACK.merge({ userId: USER_ID,
50
+ action: 'track' })
51
+
52
+ IDENTIFY = IDENTIFY.merge({ userId: USER_ID,
53
+ action: 'identify' })
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ require 'intellisense-ruby'
2
+ require 'spec_helper'
3
+ require 'pp'
4
+ require 'aws-sdk'
5
+ require 'mocha/setup'
6
+
7
+ describe IntellisenseRuby::SQS_Publisher do
8
+
9
+ describe '#init' do
10
+
11
+ it 'should initialize correctly' do
12
+ sqs_publisher = IntellisenseRuby::SQS_Publisher.new
13
+ end
14
+
15
+ end
16
+
17
+ describe '#send_message' do
18
+
19
+ it 'should send correctly' do
20
+ #AWS::SQS::Queue.any_instance.stubs(:send_message).returns('STUBBED send_message')
21
+ sqs_publisher = IntellisenseRuby::SQS_Publisher.new
22
+ #sqs_publisher.stubs(:send_message).returns('STUBBED send_message')
23
+ puts sqs_publisher.send_message(value: 'test')
24
+ end
25
+
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intellisense-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Intellify Learning
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '0.10'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0.8'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '0.10'
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday_middleware
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '0.10'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - - <
56
+ - !ruby/object:Gem::Version
57
+ version: '0.10'
58
+ - !ruby/object:Gem::Dependency
59
+ name: multi_json
60
+ requirement: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ - !ruby/object:Gem::Dependency
75
+ name: aws-sdk
76
+ requirement: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: rake
92
+ requirement: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ - !ruby/object:Gem::Dependency
107
+ name: rspec
108
+ requirement: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ - !ruby/object:Gem::Dependency
123
+ name: mocha
124
+ requirement: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ description: The Intellisense API for Ruby
139
+ email: founders@intellifylearning.com
140
+ executables: []
141
+ extensions: []
142
+ extra_rdoc_files: []
143
+ files:
144
+ - lib/intellisense-ruby.rb
145
+ - lib/intellisense-ruby/request.rb
146
+ - lib/intellisense-ruby/json.rb
147
+ - lib/intellisense-ruby/response.rb
148
+ - lib/intellisense-ruby/sqs_publisher.rb
149
+ - lib/intellisense-ruby/version.rb
150
+ - lib/intellisense-ruby/consumer.rb
151
+ - lib/intellisense-ruby/client.rb
152
+ - lib/intellisense-ruby/defaults.rb
153
+ - intellisense-ruby-0.6.4.gem
154
+ - intellisense-ruby.sublime-project
155
+ - intellisense-ruby.sublime-workspace
156
+ - README.md
157
+ - Gemfile
158
+ - Gemfile.lock
159
+ - intellisense-ruby.gemspec
160
+ - Rakefile
161
+ - spec/consumer_spec.rb
162
+ - spec/module_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/sqs_publisher_spec.rb
165
+ - spec/client_spec.rb
166
+ homepage: https://github.com/pnayak/intellisense-ruby.git
167
+ licenses: []
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.25
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Intellify Learning Intellisense
190
+ test_files: []