aloha_analyzer 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8ba9337afa5ffabd013152135eb491570b1e8b4
4
+ data.tar.gz: c28c69157e0fae6b1337cb05a00d0d9f056e1004
5
+ SHA512:
6
+ metadata.gz: 149cc56d51da2fdee363fa8ea10ac274cf62d65cc9850cadbcaf9c6e868ad278fc438755bd70b256746ac8cbeb086ad73789c9ced24d6b140f340cb8fbba3e50
7
+ data.tar.gz: 7b15090925e99953fd7c0262efd3c2dba2708f8527cb8d54af29fd74081c15b4b4f5080d1e73bf4576a464e2ebe644b4a520c9411ba08c4f440fff7ec8b9fb68
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aloha.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthieu Aussaguel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Aloha Analyzer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aloha_analyzer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aloha_analyzer
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ aloha = AlohaAnalyser::Follower.new(username, { credentials: credentials })
23
+ alohas.calculate!
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aloha_analyzer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aloha_analyzer"
8
+ spec.version = AlohaAnalyzer::VERSION
9
+ spec.authors = ["Matthieu Aussaguel"]
10
+ spec.email = ["matthieu.aussaguel@gmail.com"]
11
+ spec.description = %q{Analyze twitter followers languages}
12
+ spec.summary = %q{Analyze twitter followers languages}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake', '~> 10.1'
23
+ spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'webmock', '~> 1.17'
25
+ spec.add_dependency 'twitter', '~> 5.6'
26
+ end
File without changes
@@ -0,0 +1,51 @@
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 calculate!
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] += 1
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module AlohaAnalyzer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "aloha_analyzer/version"
2
+ require "aloha_analyzer/follower"
3
+
4
+ module AlohaAnalyzer
5
+ end
@@ -0,0 +1,197 @@
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 '#calculate!' 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.calculate!
107
+
108
+ subject.cursor.should eq next_cursor
109
+ end
110
+
111
+ it 'calculates the langauges stats' do
112
+ subject.calculate!
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.calculate!
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.calculate!
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.calculate!
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.calculate!
169
+
170
+ subject.cursor.should eq new_next_cursor
171
+ end
172
+
173
+ it 'calculates the langauges stats' do
174
+ subject.calculate!
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.calculate!
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.calculate!
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe AlohaAnalyzer do
4
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'debugger'
3
+ require 'bundler/setup'
4
+
5
+ require 'twitter'
6
+ require 'aloha_analyzer'
7
+ require 'webmock/rspec'
8
+
9
+
10
+ RSpec.configure do |config|
11
+ end
12
+
13
+ # stolen from the twitter gem
14
+ def stub_get(path)
15
+ stub_request(:get, Twitter::REST::Client::ENDPOINT + path)
16
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aloha_analyzer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthieu Aussaguel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
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.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: twitter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.6'
83
+ description: Analyze twitter followers languages
84
+ email:
85
+ - matthieu.aussaguel@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-version"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - aloha_analyzer.gemspec
98
+ - lib/aloha_analyzer.rb
99
+ - lib/aloha_analyzer/analyzer.rb
100
+ - lib/aloha_analyzer/follower.rb
101
+ - lib/aloha_analyzer/version.rb
102
+ - spec/aloha_analyzer/follower_spec.rb
103
+ - spec/aloha_analyzer_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.0
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Analyze twitter followers languages
129
+ test_files:
130
+ - spec/aloha_analyzer/follower_spec.rb
131
+ - spec/aloha_analyzer_spec.rb
132
+ - spec/spec_helper.rb