greenfinch-ruby 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/.gitignore +5 -0
- data/.idea/.gitignore +8 -0
- data/.idea/greenfinch-ruby.iml +16 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/LICENSE +190 -0
- data/README.md +124 -0
- data/Rakefile +13 -0
- data/Readme.rdoc +109 -0
- data/demo/faraday_consumer.rb +40 -0
- data/demo/out_of_process_consumer.rb +71 -0
- data/demo/simple_messages.rb +9 -0
- data/greenfinch-ruby.gemspec +21 -0
- data/lib/greenfinch-ruby.rb +3 -0
- data/lib/greenfinch-ruby/consumer.rb +271 -0
- data/lib/greenfinch-ruby/error.rb +46 -0
- data/lib/greenfinch-ruby/events.rb +140 -0
- data/lib/greenfinch-ruby/groups.rb +201 -0
- data/lib/greenfinch-ruby/people.rb +254 -0
- data/lib/greenfinch-ruby/tracker.rb +184 -0
- data/lib/greenfinch-ruby/version.rb +3 -0
- data/spec/mixpanel-ruby/consumer_spec.rb +208 -0
- data/spec/mixpanel-ruby/error_spec.rb +76 -0
- data/spec/mixpanel-ruby/events_spec.rb +76 -0
- data/spec/mixpanel-ruby/groups_spec.rb +159 -0
- data/spec/mixpanel-ruby/people_spec.rb +220 -0
- data/spec/mixpanel-ruby/tracker_spec.rb +134 -0
- data/spec/spec_helper.rb +15 -0
- metadata +132 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
require 'greenfinch-ruby'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
describe Mixpanel::Tracker do
|
8
|
+
before(:each) do
|
9
|
+
@time_now = Time.parse('Jun 6 1972, 16:23:04')
|
10
|
+
allow(Time).to receive(:now).and_return(@time_now)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should send an alias message to mixpanel no matter what the consumer is' do
|
14
|
+
WebMock.reset!
|
15
|
+
stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
|
16
|
+
mixpanel = Mixpanel::Tracker.new('TEST TOKEN') {|*args| }
|
17
|
+
mixpanel.alias('TEST ALIAS', 'TEST ID')
|
18
|
+
|
19
|
+
expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
|
20
|
+
with(:body => {:data => 'eyJldmVudCI6IiRjcmVhdGVfYWxpYXMiLCJwcm9wZXJ0aWVzIjp7ImRpc3RpbmN0X2lkIjoiVEVTVCBJRCIsImFsaWFzIjoiVEVTVCBBTElBUyIsInRva2VuIjoiVEVTVCBUT0tFTiJ9fQ==', 'verbose' => '1'})
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should generate pixel tracking urls correctly' do
|
24
|
+
mixpanel = Mixpanel::Tracker.new('TEST TOKEN')
|
25
|
+
event = 'TEST EVENT'
|
26
|
+
properties = {'Circumstances' => 'During test'}
|
27
|
+
default_properties = {
|
28
|
+
'distinct_id' => 'TEST_ID',
|
29
|
+
'mp_lib' => 'ruby',
|
30
|
+
'$lib_version' => Mixpanel::VERSION,
|
31
|
+
'token' => 'TEST TOKEN',
|
32
|
+
'time' => @time_now.to_i
|
33
|
+
}
|
34
|
+
expected_data = {'event' => event, 'properties' => properties.merge(default_properties)}
|
35
|
+
|
36
|
+
url_string = mixpanel.generate_tracking_url('TEST_ID', event, properties)
|
37
|
+
|
38
|
+
url = URI(url_string)
|
39
|
+
expect(url.scheme).to eq('https')
|
40
|
+
expect(url.host).to eq('api.mixpanel.com')
|
41
|
+
expect(url.path).to eq('/track/')
|
42
|
+
|
43
|
+
parsed_query = CGI.parse(url.query)
|
44
|
+
expect(parsed_query['ip'][0]).to eq('1')
|
45
|
+
expect(parsed_query['img'][0]).to eq('1')
|
46
|
+
|
47
|
+
data = JSON.parse(Base64.urlsafe_decode64(parsed_query['data'][0]))
|
48
|
+
expect(data).to eq(expected_data)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should send a request to the track api with the default consumer' do
|
52
|
+
WebMock.reset!
|
53
|
+
stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
|
54
|
+
stub_request(:any, 'https://api.mixpanel.com/engage').to_return({:body => '{"status": 1, "error": null}'})
|
55
|
+
mixpanel = Mixpanel::Tracker.new('TEST TOKEN')
|
56
|
+
|
57
|
+
mixpanel.track('TEST ID', 'TEST EVENT', {'Circumstances' => 'During test'})
|
58
|
+
|
59
|
+
body = nil
|
60
|
+
expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
|
61
|
+
with { |req| body = req.body }
|
62
|
+
|
63
|
+
message_urlencoded = body[/^data=(.*?)(?:&|$)/, 1]
|
64
|
+
message_json = Base64.strict_decode64(URI.unescape(message_urlencoded))
|
65
|
+
message = JSON.load(message_json)
|
66
|
+
expect(message).to eq({
|
67
|
+
'event' => 'TEST EVENT',
|
68
|
+
'properties' => {
|
69
|
+
'Circumstances' => 'During test',
|
70
|
+
'distinct_id' => 'TEST ID',
|
71
|
+
'mp_lib' => 'ruby',
|
72
|
+
'$lib_version' => Mixpanel::VERSION,
|
73
|
+
'token' => 'TEST TOKEN',
|
74
|
+
'time' => @time_now.to_i
|
75
|
+
}
|
76
|
+
})
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should call a consumer block if one is given' do
|
80
|
+
messages = []
|
81
|
+
mixpanel = Mixpanel::Tracker.new('TEST TOKEN') do |type, message|
|
82
|
+
messages << [type, JSON.load(message)]
|
83
|
+
end
|
84
|
+
mixpanel.track('ID', 'Event')
|
85
|
+
mixpanel.import('API_KEY', 'ID', 'Import')
|
86
|
+
mixpanel.people.set('ID', {'k' => 'v'})
|
87
|
+
mixpanel.people.append('ID', {'k' => 'v'})
|
88
|
+
|
89
|
+
expect = [
|
90
|
+
[ :event, 'data' =>
|
91
|
+
{ 'event' => 'Event',
|
92
|
+
'properties' => {
|
93
|
+
'distinct_id' => 'ID',
|
94
|
+
'mp_lib' => 'ruby',
|
95
|
+
'$lib_version' => Mixpanel::VERSION,
|
96
|
+
'token' => 'TEST TOKEN',
|
97
|
+
'time' => @time_now.to_i
|
98
|
+
}
|
99
|
+
}
|
100
|
+
],
|
101
|
+
[ :import, {
|
102
|
+
'data' => {
|
103
|
+
'event' => 'Import',
|
104
|
+
'properties' => {
|
105
|
+
'distinct_id' => 'ID',
|
106
|
+
'mp_lib' => 'ruby',
|
107
|
+
'$lib_version' => Mixpanel::VERSION,
|
108
|
+
'token' => 'TEST TOKEN',
|
109
|
+
'time' => @time_now.to_i
|
110
|
+
}
|
111
|
+
},
|
112
|
+
'api_key' => 'API_KEY',
|
113
|
+
}
|
114
|
+
],
|
115
|
+
[ :profile_update, 'data' =>
|
116
|
+
{ '$token' => 'TEST TOKEN',
|
117
|
+
'$distinct_id' => 'ID',
|
118
|
+
'$time' => @time_now.to_i * 1000,
|
119
|
+
'$set' => {'k' => 'v'}
|
120
|
+
}
|
121
|
+
],
|
122
|
+
[ :profile_update, 'data' =>
|
123
|
+
{ '$token' => 'TEST TOKEN',
|
124
|
+
'$distinct_id' => 'ID',
|
125
|
+
'$time' => @time_now.to_i * 1000,
|
126
|
+
'$append' => {'k' => 'v'}
|
127
|
+
}
|
128
|
+
]
|
129
|
+
]
|
130
|
+
expect.zip(messages).each do |expect, found|
|
131
|
+
expect(expect).to eq(found)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
config.raise_errors_for_deprecations!
|
9
|
+
|
10
|
+
# Run specs in random order to surface order dependencies. If you find an
|
11
|
+
# order dependency and want to debug it, you can fix the order by providing
|
12
|
+
# the seed, which is printed after each run.
|
13
|
+
# --seed 1234
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: greenfinch-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- KoreaCreditData
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.18'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.18'
|
69
|
+
description: The official Greenfinch tracking library for ruby
|
70
|
+
email: terry@kcd.co.kr
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- ".idea/.gitignore"
|
77
|
+
- ".idea/greenfinch-ruby.iml"
|
78
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
79
|
+
- ".idea/misc.xml"
|
80
|
+
- ".idea/modules.xml"
|
81
|
+
- ".idea/vcs.xml"
|
82
|
+
- ".rspec"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- Readme.rdoc
|
89
|
+
- demo/faraday_consumer.rb
|
90
|
+
- demo/out_of_process_consumer.rb
|
91
|
+
- demo/simple_messages.rb
|
92
|
+
- greenfinch-ruby.gemspec
|
93
|
+
- lib/greenfinch-ruby.rb
|
94
|
+
- lib/greenfinch-ruby/consumer.rb
|
95
|
+
- lib/greenfinch-ruby/error.rb
|
96
|
+
- lib/greenfinch-ruby/events.rb
|
97
|
+
- lib/greenfinch-ruby/groups.rb
|
98
|
+
- lib/greenfinch-ruby/people.rb
|
99
|
+
- lib/greenfinch-ruby/tracker.rb
|
100
|
+
- lib/greenfinch-ruby/version.rb
|
101
|
+
- spec/mixpanel-ruby/consumer_spec.rb
|
102
|
+
- spec/mixpanel-ruby/error_spec.rb
|
103
|
+
- spec/mixpanel-ruby/events_spec.rb
|
104
|
+
- spec/mixpanel-ruby/groups_spec.rb
|
105
|
+
- spec/mixpanel-ruby/people_spec.rb
|
106
|
+
- spec/mixpanel-ruby/tracker_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: https://github.com/koreacreditdata/greenfinch-ruby
|
109
|
+
licenses:
|
110
|
+
- Apache-2.0
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.0.0
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.2.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Official Greenfinch tracking library for ruby
|
132
|
+
test_files: []
|