aloha_analyzer 0.0.4 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78d30dc67ba7dcabf72a73d0c42cd001437b7e7d
4
- data.tar.gz: 449554af381111619d24a8a6a0ea696be43c18ca
3
+ metadata.gz: d60bfa2c43a2c496f98d2aadedd42036ca8e36fc
4
+ data.tar.gz: 4d6b145caa9f49366cf2d23ec9459b780d9722dd
5
5
  SHA512:
6
- metadata.gz: adcc8feeddd92b9a914aca0e065e6d80064a4bcf790a692a579c7a39ca4df42865dbbf2bd49b20cd9ca7dc85f0d3a274b0449fa4062f1ee1a2d3eb8779b1f5fb
7
- data.tar.gz: 9bc83a94c2e2ca71cd4ab167474b82b44f4dcb487ba889027ac28ef36d650e4b3ded69678cfbc06ce8534bd066450877d788260f7a2279109d0fe21715509a89
6
+ metadata.gz: 090644018e122c692324448b0903941d4144a065cf2d929413b10868cc98497c0e9e13dd407a6c408ba3db0a3f38c934814eecba20f026d31da43b0daf79f316
7
+ data.tar.gz: f23c8f3fd71bcd6b5bd894b07e7141877e02aba738d8b7da619e67fdbe4877c8a01231cb206a08911f03e26846b78326573f938b536cd34f5f8a768398488364
data/README.md CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- aloha = AlohaAnalyser::Follower.new(username, { credentials: credentials })
22
+ aloha = AlohaAnalyser::User.new(username, { credentials: credentials })
23
23
  aloha.analyze!
24
24
  ```
25
25
 
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_development_dependency 'rake', '~> 10.1'
22
+ spec.add_development_dependency 'rake', '~> 10.3'
23
23
  spec.add_development_dependency 'rspec', '~> 2.14'
24
24
  spec.add_development_dependency 'webmock', '~> 1.17'
25
25
  spec.add_development_dependency 'debugger', '~> 1.6'
26
- spec.add_dependency 'twitter', '~> 5.6'
26
+ spec.add_dependency 'twitter', '~> 5.8'
27
27
  end
@@ -0,0 +1,81 @@
1
+ - abbreviation: fr
2
+ name: French
3
+ population: 14_000_000
4
+ - abbreviation: en
5
+ name: English
6
+ population: 238_000_000
7
+ - abbreviation: ar
8
+ name: Arabic
9
+ population: 42_000_000
10
+ - abbreviation: ja
11
+ name: Japanese
12
+ population: 106_580_000
13
+ - abbreviation: es
14
+ name: Spanish
15
+ population: 95_000_000
16
+ - abbreviation: de
17
+ name: 'German'
18
+ population: 5_000_000
19
+ - abbreviation: it
20
+ name: Italian
21
+ population: 8_000_000
22
+ - abbreviation: id
23
+ name: Indonesian
24
+ population: 20_000_000
25
+ - abbreviation: pt
26
+ name: Portuguese
27
+ population: 42_000_000
28
+ - abbreviation: ko
29
+ name: Korean
30
+ population: 7_000_000
31
+ - abbreviation: tr
32
+ name: Turkish
33
+ population: 14_000_000
34
+ - abbreviation: ru
35
+ name: Russian
36
+ population: 5_000_000
37
+ - abbreviation: nl
38
+ name: Dutch
39
+ population: 8_000_000
40
+ - abbreviation: fil
41
+ name: Filipino
42
+ population: 8_000_000
43
+ - abbreviation: msa
44
+ name: Malay
45
+ population: 50_000_000
46
+ - abbreviation: zh
47
+ name: Chinese
48
+ population: 20_000
49
+ - abbreviation: hi
50
+ name: Hindi
51
+ population: 12_000_000
52
+ - abbreviation: 'no'
53
+ name: Norwegian
54
+ population: 300_000
55
+ - abbreviation: sv
56
+ name: Swedish
57
+ population: 500_000
58
+ - abbreviation: fi
59
+ name: Finnish
60
+ population: 100_000
61
+ - abbreviation: da
62
+ name: Danish
63
+ population: 200_000
64
+ - abbreviation: pl
65
+ name: Polish
66
+ population: 300_000
67
+ - abbreviation: hu
68
+ name: Hungarian
69
+ population: 1_000_000
70
+ - abbreviation: fa
71
+ name: Farsi
72
+ population: 1_000_000
73
+ - abbreviation: he
74
+ name: Hebrew
75
+ population: 1_000_000
76
+ - abbreviation: ur
77
+ name: Urdu
78
+ population: 1_000_000
79
+ - abbreviation: th
80
+ name: Thai
81
+ population: 7_0000_000
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ module AlohaAnalyzer
4
+ class Language
5
+ LANGUAGES = YAML::load(File.open('config/language.yml'))
6
+ TOTAL_POPULATION = 750_000_000
7
+
8
+ def self.all
9
+ LANGUAGES
10
+ end
11
+
12
+ def self.total
13
+ TOTAL_POPULATION
14
+ end
15
+
16
+ def self.aliases
17
+ {
18
+ 'en-gb' => 'en',
19
+ 'zh-cb' => 'zh',
20
+ 'zh-tw' => 'zh'
21
+ }
22
+ end
23
+
24
+ def self.find_by_abbreviation(abbreviation)
25
+ all.each do |language|
26
+ return language if language['abbreviation'] == abbreviation
27
+ end
28
+ nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,86 @@
1
+ module AlohaAnalyzer
2
+ class User
3
+
4
+ attr_reader :language
5
+
6
+ def initialize(language, users)
7
+ @language = language
8
+ @users = users
9
+ @users_count = users.size
10
+ clean_language!
11
+ clean_users_languages!
12
+ end
13
+
14
+ def analyze
15
+ {
16
+ with_user_language: with_user_language,
17
+ without_user_language: without_user_language
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def with_user_language
24
+ @with_user_language ||= Hash.new.tap do |languages|
25
+ @users.each do |user|
26
+ abbreviation = user['lang']
27
+ if languages[abbreviation]
28
+ languages[abbreviation]['count'] += 1
29
+ else
30
+ languages[abbreviation] = {
31
+ 'count' => 1,
32
+ 'population' => Language.find_by_abbreviation(abbreviation)['population']
33
+ }
34
+ end
35
+ languages[abbreviation]['percentage'] = ((100 / @users_count.to_f) * languages[abbreviation]['count']).round
36
+ end
37
+ end
38
+ end
39
+
40
+ def without_user_language
41
+ @without_user_language ||= Hash.new.tap do |languages|
42
+ @users.each do |user|
43
+ abbreviation = user['lang']
44
+ if abbreviation != @language
45
+ if languages[abbreviation]
46
+ languages[abbreviation]['count'] += 1
47
+ else
48
+ languages[abbreviation] = {
49
+ 'count' => 1,
50
+ 'population' => Language.find_by_abbreviation(abbreviation)['population']
51
+ }
52
+ end
53
+ languages[abbreviation]['percentage'] = ((100 / users_total_without_user_language.to_f) * languages[abbreviation]['count']).round
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def users_total_without_user_language
60
+ @users_total_without_user_language ||= @users_count - user_language_count
61
+ end
62
+
63
+ def user_language_count
64
+ @user_language_count ||= if with_user_language[@language]
65
+ with_user_language[@language]['count']
66
+ else
67
+ 0
68
+ end
69
+ end
70
+
71
+ def clean_language!
72
+ if Language.aliases.keys.include?(@language)
73
+ @language = Language.aliases[@language]
74
+ end
75
+ end
76
+
77
+ def clean_users_languages!
78
+ @users.map! do |user|
79
+ if Language.aliases.keys.include?(user['lang'])
80
+ user['lang'] = Language.aliases[user['lang']]
81
+ end
82
+ user
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module AlohaAnalyzer
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "aloha_analyzer/version"
2
- require "aloha_analyzer/follower"
2
+ require "aloha_analyzer/language"
3
+ require "aloha_analyzer/user"
3
4
 
4
5
  module AlohaAnalyzer
5
6
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe AlohaAnalyzer::Language do
4
+ describe '.all' do
5
+ it 'returns an array' do
6
+ described_class.all.should be_a Array
7
+ end
8
+
9
+ it 'is not empty' do
10
+ described_class.all.should be_a Array
11
+ end
12
+ end
13
+
14
+ describe '.total' do
15
+ it 'returns the total number of language users' do
16
+ total = 0
17
+ described_class.all.each do |language|
18
+ total += language['population']
19
+ end
20
+ total.should eq described_class.total
21
+ end
22
+ end
23
+
24
+ describe '.find_by_abbreviation' do
25
+ subject(:language) { described_class.find_by_abbreviation(abbreviation) }
26
+ context 'when it exits' do
27
+ let(:abbreviation) { 'fr' }
28
+
29
+ it 'returns a hash' do
30
+ subject.should be_a Hash
31
+ end
32
+
33
+ it 'includes the total language population' do
34
+ subject['population'].should be_a Fixnum
35
+ end
36
+
37
+ it 'includes the language name' do
38
+ subject['name'].should eq 'French'
39
+ end
40
+
41
+ it 'includes the language abbreviation' do
42
+ subject['abbreviation'].should eq 'fr'
43
+ end
44
+ end
45
+
46
+ context 'when it does not exist' do
47
+ let(:abbreviation) { 'esperanto' }
48
+ it 'returns nil' do
49
+ subject.should be_nil
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,251 @@
1
+ require 'spec_helper'
2
+
3
+ describe AlohaAnalyzer::User do
4
+ subject(:user) { described_class.new(language, users) }
5
+ let(:language) { 'en' }
6
+
7
+ describe '#new' do
8
+ let(:users) { [] }
9
+ context 'when language is british' do
10
+ let(:language) { 'en-gb' }
11
+
12
+ it 'changes to english' do
13
+ subject.language.should eq 'en'
14
+ end
15
+ end
16
+
17
+ context 'when language is simplified chinese' do
18
+ let(:language) { 'zh-cb' }
19
+
20
+ it 'changes to chinese' do
21
+ subject.language.should eq 'zh'
22
+ end
23
+ end
24
+
25
+ context 'when language is tradiational chinese' do
26
+ let(:language) { 'zh-tw' }
27
+
28
+ it 'changes to chinese' do
29
+ subject.language.should eq 'zh'
30
+ end
31
+ end
32
+
33
+ context 'when language is something else' do
34
+ let(:language) { 'something' }
35
+
36
+ it 'does not change it' do
37
+ subject.language.should eq language
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#analyze' do
43
+ subject(:analyze) { described_class.new(language, users).analyze }
44
+ context 'when no users' do
45
+ let(:users) { [] }
46
+
47
+ it 'returns a hash' do
48
+ subject.should be_a Hash
49
+ end
50
+
51
+ it 'has no results with the user language' do
52
+ subject[:with_user_language].should eq({})
53
+ end
54
+
55
+ it 'has no results without the user language' do
56
+ subject[:without_user_language].should eq({})
57
+ end
58
+ end
59
+
60
+ context 'when users' do
61
+ context 'and no aliases' do
62
+ let(:users) {
63
+ [
64
+ {'lang' => 'en'},
65
+ {'lang' => 'fr'},
66
+ {'lang' => 'en'},
67
+ {'lang' => 'de'}
68
+ ]
69
+ }
70
+
71
+ it 'returns a hash' do
72
+ subject.should be_a Hash
73
+ end
74
+
75
+ it 'returns results based on the user language' do
76
+ subject[:with_user_language].should == {
77
+ 'en' => {
78
+ 'percentage' => 50,
79
+ 'count' => 2,
80
+ 'population' => 238_000_000,
81
+ },
82
+ 'fr' => {
83
+ 'percentage' => 25,
84
+ 'count' => 1,
85
+ 'population' => 14_000_000,
86
+ },
87
+ 'de' => {
88
+ 'percentage' => 25,
89
+ 'count' => 1,
90
+ 'population' => 5_000_000,
91
+ }
92
+ }
93
+ end
94
+
95
+ it 'returns results results based on the non user language' do
96
+ subject[:without_user_language].should eq(
97
+ 'fr' => {
98
+ 'percentage' => 50,
99
+ 'count' => 1,
100
+ 'population' => 14_000_000,
101
+ },
102
+ 'de' => {
103
+ 'percentage' => 50,
104
+ 'count' => 1,
105
+ 'population' => 5_000_000,
106
+ }
107
+ )
108
+ end
109
+ end
110
+
111
+ context 'when only user langugages users' do
112
+ let(:users) {
113
+ [
114
+ {'lang' => 'en'},
115
+ {'lang' => 'en'}
116
+ ]
117
+ }
118
+
119
+ it 'returns a hash' do
120
+ subject.should be_a Hash
121
+ end
122
+
123
+ it 'returns results based on the user language' do
124
+ subject[:with_user_language].should == {
125
+ 'en' => {
126
+ 'percentage' => 100,
127
+ 'count' => 2,
128
+ 'population' => 238_000_000,
129
+ }
130
+ }
131
+ end
132
+
133
+ it 'returns results results based on the non user language' do
134
+ subject[:without_user_language].should == {}
135
+ end
136
+ end
137
+
138
+ context 'when no users language users' do
139
+ let(:users) {
140
+ [
141
+ {'lang' => 'de'},
142
+ {'lang' => 'fr'}
143
+ ]
144
+ }
145
+
146
+ it 'returns a hash' do
147
+ subject.should be_a Hash
148
+ end
149
+
150
+ it 'returns results based on the user language' do
151
+ subject[:with_user_language].should == {
152
+ 'fr' => {
153
+ 'percentage' => 50,
154
+ 'count' => 1,
155
+ 'population' => 14_000_000,
156
+ },
157
+ 'de' => {
158
+ 'percentage' => 50,
159
+ 'count' => 1,
160
+ 'population' => 5_000_000,
161
+ }
162
+ }
163
+ end
164
+
165
+ it 'returns results results based on the non user language' do
166
+ subject[:without_user_language].should eq(
167
+ 'fr' => {
168
+ 'percentage' => 50,
169
+ 'count' => 1,
170
+ 'population' => 14_000_000,
171
+ },
172
+ 'de' => {
173
+ 'percentage' => 50,
174
+ 'count' => 1,
175
+ 'population' => 5_000_000,
176
+ }
177
+ )
178
+ end
179
+ end
180
+
181
+ context 'when aliases' do
182
+ context 'and some users british' do
183
+ let(:users) {
184
+ [
185
+ {'lang' => 'en'},
186
+ {'lang' => 'fr'},
187
+ {'lang' => 'en-gb'}
188
+ ]
189
+ }
190
+
191
+ it 'merges english and british' do
192
+ subject[:with_user_language].should == {
193
+ 'en' => {
194
+ 'percentage' => 67,
195
+ 'count' => 2,
196
+ 'population' => 238_000_000,
197
+ },
198
+ 'fr' => {
199
+ 'percentage' => 33,
200
+ 'count' => 1,
201
+ 'population' => 14_000_000
202
+ }
203
+ }
204
+
205
+ subject[:without_user_language].should eq(
206
+ 'fr' => {
207
+ 'percentage' => 100,
208
+ 'count' => 1,
209
+ 'population' => 14_000_000
210
+ }
211
+ )
212
+ end
213
+ end
214
+
215
+ context 'and some users are chinese' do
216
+ let(:users) {
217
+ [
218
+ {'lang' => 'zh-cb'},
219
+ {'lang' => 'zh-cb'},
220
+ {'lang' => 'en'},
221
+ {'lang' => 'zh-tw'}
222
+ ]
223
+ }
224
+
225
+ it 'merges chinese' do
226
+ subject[:with_user_language].should == {
227
+ 'zh' => {
228
+ 'percentage' => 75,
229
+ 'count' => 3,
230
+ 'population' => 20000,
231
+ },
232
+ 'en' => {
233
+ 'percentage' => 25,
234
+ 'count' => 1,
235
+ 'population' => 238000000
236
+ }
237
+ }
238
+
239
+ subject[:without_user_language].should eq(
240
+ 'zh' => {
241
+ 'percentage' => 100,
242
+ 'count' => 3,
243
+ 'population' => 20000
244
+ }
245
+ )
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aloha_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Aussaguel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.1'
33
+ version: '10.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.1'
40
+ version: '10.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '5.6'
89
+ version: '5.8'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '5.6'
96
+ version: '5.8'
97
97
  description: Analyze twitter followers languages
98
98
  email:
99
99
  - matthieu.aussaguel@gmail.com
@@ -109,10 +109,13 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - aloha_analyzer.gemspec
112
+ - config/language.yml
112
113
  - lib/aloha_analyzer.rb
113
- - lib/aloha_analyzer/follower.rb
114
+ - lib/aloha_analyzer/language.rb
115
+ - lib/aloha_analyzer/user.rb
114
116
  - lib/aloha_analyzer/version.rb
115
- - spec/aloha_analyzer/follower_spec.rb
117
+ - spec/aloha_analyzer/language_spec.rb
118
+ - spec/aloha_analyzer/user_spec.rb
116
119
  - spec/aloha_analyzer_spec.rb
117
120
  - spec/spec_helper.rb
118
121
  homepage: https://github.com/matthieua/aloha_analyzer
@@ -135,11 +138,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
138
  version: '0'
136
139
  requirements: []
137
140
  rubyforge_project:
138
- rubygems_version: 2.2.1
141
+ rubygems_version: 2.2.2
139
142
  signing_key:
140
143
  specification_version: 4
141
144
  summary: Analyze twitter followers languages
142
145
  test_files:
143
- - spec/aloha_analyzer/follower_spec.rb
146
+ - spec/aloha_analyzer/language_spec.rb
147
+ - spec/aloha_analyzer/user_spec.rb
144
148
  - spec/aloha_analyzer_spec.rb
145
149
  - spec/spec_helper.rb
@@ -1,52 +0,0 @@
1
- module AlohaAnalyzer
2
- class Follower
3
- attr_reader :screen_name, :cursor, :languages
4
-
5
- def initialize(screen_name, options = {})
6
- @screen_name = screen_name
7
- @cursor = options[:cursor] || -1
8
- @languages = options[:languages] || Hash.new(0)
9
- @credentials = options[:credentials]
10
- end
11
-
12
- def count
13
- counter = 0
14
- @languages.each do |_, language_count|
15
- counter += language_count
16
- end
17
- counter
18
- end
19
-
20
- def analyze!
21
- response = client.followers(@screen_name, request_options).to_h
22
- response[:users].each do |follower|
23
- increment follower[:lang]
24
- end
25
- @cursor = response[:next_cursor]
26
- end
27
-
28
- private
29
-
30
- def request_options
31
- {
32
- count: 200,
33
- skip_status: false,
34
- cursor: @cursor
35
- }
36
- end
37
-
38
- def client
39
- @client ||= ::Twitter::REST::Client.new(
40
- consumer_key: @credentials[:consumer_key],
41
- consumer_secret: @credentials[:consumer_secret],
42
- access_token: @credentials[:access_token],
43
- access_token_secret: @credentials[:access_token_secret]
44
- )
45
- end
46
-
47
- def increment(language)
48
- @languages[language] = @languages[language] || 0
49
- @languages[language] += 1
50
- end
51
- end
52
- end
@@ -1,197 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AlohaAnalyzer::Follower do
4
- subject(:follower) { described_class.new(screen_name, options) }
5
- let(:screen_name) { 'mattaussaguel' }
6
-
7
- let(:options) do
8
- {
9
- credentials: credentials
10
- }
11
- end
12
-
13
- let(:credentials) do
14
- {
15
- consumer_key: 'CK',
16
- consumer_secret: 'CS',
17
- access_token: 'AT',
18
- access_token_secret: 'AS'
19
- }
20
- end
21
-
22
- describe '#new' do
23
- it 'sets the screen_name' do
24
- subject.screen_name.should eq screen_name
25
- end
26
-
27
- context 'cursor option is passed' do
28
- let(:options) { { cursor: cursor } }
29
- let(:cursor) { double }
30
-
31
- it 'sets the cursor to the option value' do
32
- subject.cursor.should eq cursor
33
- end
34
- end
35
-
36
- context 'cursor option is not set' do
37
- it 'sets the cursor to -1' do
38
- subject.cursor.should eq -1
39
- end
40
- end
41
-
42
- context 'when languages option are passed' do
43
- let(:languages) { double }
44
- let(:options) { { languages: languages } }
45
-
46
- it 'sets the languages to the option value' do
47
- subject.languages.should eq languages
48
- end
49
- end
50
-
51
- context 'when languages option is not set' do
52
- it 'sets the cursor to an empty hash' do
53
- subject.languages.should be_a Hash
54
- subject.languages.should be_empty
55
- end
56
- end
57
- end
58
-
59
- describe '#count' do
60
- let(:options) { { languages: languages } }
61
- let(:languages) do
62
- {
63
- 'en' => 2,
64
- 'fr' => 3,
65
- 'es' => 0
66
- }
67
- end
68
-
69
- it 'includes the total language count' do
70
- subject.count.should eq 5
71
- end
72
- end
73
-
74
- describe '#analyze!' do
75
- let(:followers) do
76
- {
77
- "users" => [
78
- {"id" => 1, "lang" => "en"},
79
- {"id" => 2, "lang" => "fr"},
80
- {"id" => 3, "lang" => "en"},
81
- {"id" => 4, "lang" => "de"}
82
- ],
83
- "next_cursor" => next_cursor
84
- }
85
- end
86
- let(:next_cursor) { 1 }
87
- let(:query_args) do
88
- {
89
- skip_status: false,
90
- count: 200,
91
- :cursor => '-1',
92
- :screen_name => screen_name}
93
- end
94
-
95
- let(:body) { followers.to_json }
96
- let(:headers) { {:content_type => 'application/json; charset=utf-8'} }
97
-
98
- before do
99
- stub_get('/1.1/followers/list.json')
100
- .with(:query => query_args)
101
- .to_return(:body => body, :headers => headers)
102
- end
103
-
104
- context 'when first call' do
105
- it 'sets the next cursor' do
106
- subject.analyze!
107
-
108
- subject.cursor.should eq next_cursor
109
- end
110
-
111
- it 'calculates the langauges stats' do
112
- subject.analyze!
113
-
114
- subject.languages.should eq(
115
- 'en' => 2,
116
- 'fr' => 1,
117
- 'de' => 1
118
- )
119
- end
120
-
121
- it 'updates the count value' do
122
- subject.analyze!
123
-
124
- subject.count.should eq 4
125
- end
126
-
127
- it 'creates a new twitter client' do
128
- Twitter::REST::Client.should_receive(:new).and_call_original
129
-
130
- subject.analyze!
131
- end
132
- end
133
-
134
- context 'when run the second time' do
135
- let(:new_query_args) do
136
- {
137
- skip_status: false,
138
- count: 200,
139
- :cursor => '1',
140
- :screen_name => screen_name}
141
- end
142
-
143
- let(:new_followers) do
144
- {
145
- "users" => [
146
- {"id" => 1, "lang" => "fr"},
147
- {"id" => 2, "lang" => "de"},
148
- {"id" => 3, "lang" => "es"},
149
- {"id" => 4, "lang" => "de"}
150
- ],
151
- "next_cursor" => new_next_cursor
152
- }
153
- end
154
-
155
- let(:new_next_cursor) { 1 }
156
- let(:new_body) { new_followers.to_json }
157
-
158
- before do
159
- subject.analyze!
160
-
161
- stub_get('/1.1/followers/list.json')
162
- .with(query: new_query_args)
163
- .to_return(body: new_body, headers: headers)
164
-
165
- end
166
-
167
- it 'sets the next cursor' do
168
- subject.analyze!
169
-
170
- subject.cursor.should eq new_next_cursor
171
- end
172
-
173
- it 'calculates the langauges stats' do
174
- subject.analyze!
175
-
176
- subject.languages.should eq(
177
- 'en' => 2,
178
- 'fr' => 2,
179
- 'de' => 3,
180
- 'es' => 1
181
- )
182
- end
183
-
184
- it 'updates the count value' do
185
- subject.analyze!
186
-
187
- subject.count.should eq 8
188
- end
189
-
190
- it 'does not create another twitter client' do
191
- Twitter::REST::Client.should_not_receive(:new)
192
-
193
- subject.analyze!
194
- end
195
- end
196
- end
197
- end