analytics-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.0 / 2013-4-5
2
+ ===========
3
+ * Adding alias call
4
+
1
5
  0.2.0 / 2013-3-21
2
6
  ===========
3
7
  * Adding flush method
@@ -18,6 +18,11 @@ module AnalyticsRuby
18
18
  @client.identify(options)
19
19
  end
20
20
 
21
+ def alias(options)
22
+ return false unless @client
23
+ @client.alias(options)
24
+ end
25
+
21
26
  def flush
22
27
  return false unless @client
23
28
  @client.flush
@@ -102,6 +102,35 @@ module AnalyticsRuby
102
102
  action: 'identify' })
103
103
  end
104
104
 
105
+ # public: Aliases a user from one id to another
106
+ #
107
+ # options - Hash
108
+ # :from - String of the id to alias from
109
+ # :to - String of the id to alias to
110
+ # :timestamp - Time of when the alias occured (optional)
111
+ # :context - Hash of context (optional)
112
+ def alias(options)
113
+
114
+ check_secret
115
+
116
+ from = options[:from].to_s
117
+ to = options[:to].to_s
118
+ timestamp = options[:timestamp] || Time.new
119
+ context = options[:context] || {}
120
+
121
+ ensure_user(from)
122
+ ensure_user(to)
123
+ check_timestamp(timestamp)
124
+
125
+ add_context(context)
126
+
127
+ enqueue({ from: from,
128
+ to: to,
129
+ context: context,
130
+ timestamp: timestamp.iso8601,
131
+ action: 'alias' })
132
+ end
133
+
105
134
  # public: Returns the number of queued messages
106
135
  #
107
136
  # returns Fixnum of messages in the queue
@@ -1,3 +1,3 @@
1
1
  module AnalyticsRuby
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -50,6 +50,24 @@ describe Analytics::Client do
50
50
  end
51
51
  end
52
52
 
53
+ describe '#alias' do
54
+ before :all do
55
+ @client = Analytics::Client.new secret: AnalyticsHelpers::SECRET
56
+ end
57
+
58
+ it 'should error without from' do
59
+ expect { @client.alias to: 1234 }.to raise_error(ArgumentError)
60
+ end
61
+
62
+ it 'should error without to' do
63
+ expect { @client.alias from: 1234 }.to raise_error(ArgumentError)
64
+ end
65
+
66
+ it 'should not error with the required options' do
67
+ @client.alias AnalyticsHelpers::ALIAS
68
+ end
69
+ end
70
+
53
71
  describe '#flush' do
54
72
  before(:all) do
55
73
  @client = Analytics::Client.new secret: AnalyticsHelpers::SECRET
@@ -56,6 +56,21 @@ describe Analytics do
56
56
  end
57
57
  end
58
58
 
59
+ describe '#alias' do
60
+ it 'should error without from' do
61
+ expect { Analytics.alias to: 1234 }.to raise_error(ArgumentError)
62
+ end
63
+
64
+ it 'should error without to' do
65
+ expect { Analytics.alias from: 1234 }.to raise_error(ArgumentError)
66
+ end
67
+
68
+ it 'should not error with the required options' do
69
+ Analytics.alias AnalyticsHelpers::ALIAS
70
+ sleep(1)
71
+ end
72
+ end
73
+
59
74
  describe '#flush' do
60
75
 
61
76
  it 'should flush without error' do
@@ -20,6 +20,9 @@ module AnalyticsHelpers
20
20
  action: 'identify'
21
21
  }
22
22
 
23
+ ALIAS = { from: 1234,
24
+ to: 'abcd' }
25
+
23
26
  USER_ID = 1234
24
27
 
25
28
  # Hashes sent to the client
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: &10049160 !ruby/object:Gem::Requirement
16
+ requirement: &20475340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0.10'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *10049160
27
+ version_requirements: *20475340
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday_middleware
30
- requirement: &10048220 !ruby/object:Gem::Requirement
30
+ requirement: &23402460 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '0.10'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *10048220
41
+ version_requirements: *23402460
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: multi_json
44
- requirement: &10047320 !ruby/object:Gem::Requirement
44
+ requirement: &23401720 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '1.0'
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *10047320
52
+ version_requirements: *23401720
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rake
55
- requirement: &10046680 !ruby/object:Gem::Requirement
55
+ requirement: &23401340 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0'
61
61
  type: :development
62
62
  prerelease: false
63
- version_requirements: *10046680
63
+ version_requirements: *23401340
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: rspec
66
- requirement: &10044520 !ruby/object:Gem::Requirement
66
+ requirement: &23400880 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ! '>='
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *10044520
74
+ version_requirements: *23400880
75
75
  description: The Segment.io ruby analytics library
76
76
  email: friends@segment.io
77
77
  executables: []
@@ -88,7 +88,6 @@ files:
88
88
  - lib/analytics-ruby/version.rb
89
89
  - lib/analytics-ruby/json.rb
90
90
  - lib/analytics-ruby/client.rb
91
- - analytics-ruby-0.1.4.gem
92
91
  - History.md
93
92
  - analytics-ruby.gemspec
94
93
  - Rakefile
Binary file