growviral-warehouse 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/growviral/warehouse.rb +2 -1
- data/lib/warehouse/client.rb +5 -1
- data/lib/warehouse/fetches_users.rb +13 -4
- data/lib/warehouse/{registers_followers.rb → records_follow.rb} +8 -3
- data/lib/warehouse/records_unfollow.rb +40 -0
- data/lib/warehouse/version.rb +1 -1
- data/test/fetches_users_test.rb +29 -6
- data/test/preloads_users_test.rb +1 -1
- data/test/{registers_followers_test.rb → records_follow_test.rb} +7 -9
- data/test/records_unfollow_test.rb +36 -0
- metadata +21 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f32e8c15ebcf39957b9170d1a1a5180d16fc0e6a
|
4
|
+
data.tar.gz: fe4889949aa7ab3e04cbf659208ab6e1582ca128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58174c64a1aca594a547ea78410d3b7d33e6db18db29090cecce0ec2780847f22e211190b7b45525636285ef00e3e8f752e6e19f6bbb0567e1e6265286ccc5fc
|
7
|
+
data.tar.gz: e1cd8eea88573982edc157a525df35394884f3b3373e9f5b33920fccd88a178895782271a26709e3d3dad5cf1e9a37788b7eceed12f3bd58976485126b004016
|
data/lib/growviral/warehouse.rb
CHANGED
@@ -4,7 +4,8 @@ require 'json'
|
|
4
4
|
|
5
5
|
require 'warehouse/client'
|
6
6
|
require 'warehouse/configuration'
|
7
|
-
require 'warehouse/
|
7
|
+
require 'warehouse/records_follow'
|
8
|
+
require 'warehouse/records_unfollow'
|
8
9
|
require 'warehouse/fetches_follow_history'
|
9
10
|
require 'warehouse/checks_follow_history'
|
10
11
|
require 'warehouse/fetches_users'
|
data/lib/warehouse/client.rb
CHANGED
@@ -8,7 +8,11 @@ module GrowViral
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def register_follow!(uid, following_uid)
|
11
|
-
|
11
|
+
RecordsFollow.register(uid, following_uid, config: config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_unfollow!(uid, following_uid)
|
15
|
+
RecordsUnfollow.register(uid, following_uid, config: config)
|
12
16
|
end
|
13
17
|
|
14
18
|
def follow_history(uid)
|
@@ -9,10 +9,12 @@ module GrowViral
|
|
9
9
|
extend Forwardable
|
10
10
|
def_delegators :@data, :each, :size
|
11
11
|
|
12
|
-
attr_reader :missing_ids
|
13
|
-
def initialize(data,
|
12
|
+
attr_reader :missing_ids, :invalid_ids, :protected_ids
|
13
|
+
def initialize(data, options = {})
|
14
14
|
@data = data
|
15
|
-
@missing_ids = missing_ids
|
15
|
+
@missing_ids = options[:missing_ids] || []
|
16
|
+
@invalid_ids = options[:invalid_ids] || []
|
17
|
+
@protected_ids = options[:protected_ids] || []
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -34,7 +36,14 @@ module GrowViral
|
|
34
36
|
def fetch
|
35
37
|
response = Net::HTTP.get_response(uri)
|
36
38
|
data = JSON.parse(response.body)
|
37
|
-
Users.new(
|
39
|
+
Users.new(
|
40
|
+
data['twitter_users'],
|
41
|
+
{
|
42
|
+
missing_ids: data['missing_ids'],
|
43
|
+
invalid_ids: data['invalid_ids'],
|
44
|
+
protected_ids: data['protected_ids']
|
45
|
+
}
|
46
|
+
)
|
38
47
|
end
|
39
48
|
|
40
49
|
def uri
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GrowViral
|
2
2
|
module Warehouse
|
3
|
-
class
|
3
|
+
class RecordsFollow
|
4
4
|
def self.register(*args)
|
5
5
|
new(*args).register
|
6
6
|
end
|
@@ -21,13 +21,18 @@ module GrowViral
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def uri
|
24
|
-
@uri ||= URI.parse("#{config.host}/
|
24
|
+
@uri ||= URI.parse("#{config.host}/interactions/mark_followed")
|
25
|
+
end
|
26
|
+
|
27
|
+
def timestamp
|
28
|
+
@timestamp ||= Time.now.to_i
|
25
29
|
end
|
26
30
|
|
27
31
|
def form_data
|
28
32
|
{
|
29
33
|
"uid" => uid,
|
30
|
-
"
|
34
|
+
"follow_uid" => following_uid,
|
35
|
+
"timestamp" => timestamp
|
31
36
|
}
|
32
37
|
end
|
33
38
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module GrowViral
|
2
|
+
module Warehouse
|
3
|
+
class RecordsUnfollow
|
4
|
+
def self.register(*args)
|
5
|
+
new(*args).register
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :uid, :following_uid, :config
|
9
|
+
def initialize(uid, following_uid, deps)
|
10
|
+
raise HandleNotUidError unless uid.is_a? Numeric
|
11
|
+
raise HandleNotUidError unless following_uid.is_a? Numeric
|
12
|
+
|
13
|
+
@uid = uid
|
14
|
+
@following_uid = following_uid
|
15
|
+
@config = deps[:config]
|
16
|
+
end
|
17
|
+
|
18
|
+
def register
|
19
|
+
response = Net::HTTP.post_form(uri, form_data)
|
20
|
+
JSON.parse(response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def uri
|
24
|
+
@uri ||= URI.parse("#{config.host}/interactions/mark_unfollowed")
|
25
|
+
end
|
26
|
+
|
27
|
+
def timestamp
|
28
|
+
@timestamp ||= Time.now.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def form_data
|
32
|
+
{
|
33
|
+
"uid" => uid,
|
34
|
+
"follow_uid" => following_uid,
|
35
|
+
"timestamp" => timestamp
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/warehouse/version.rb
CHANGED
data/test/fetches_users_test.rb
CHANGED
@@ -1,22 +1,41 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
3
|
module GrowViral::Warehouse
|
4
|
-
class
|
4
|
+
class FetchesUsersTest < Minitest::Test
|
5
5
|
def test_users_is_enumerable
|
6
6
|
data = mock
|
7
7
|
data.expects(:each)
|
8
8
|
data.expects(:size)
|
9
|
-
users = FetchesUsers::Users.new(data
|
9
|
+
users = FetchesUsers::Users.new(data)
|
10
10
|
users.each {}
|
11
11
|
users.size
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_users_returns_missing_ids
|
15
15
|
missing_ids = mock
|
16
|
-
users = FetchesUsers::Users.new(nil, missing_ids)
|
16
|
+
users = FetchesUsers::Users.new(nil, missing_ids: missing_ids)
|
17
17
|
assert_equal missing_ids, users.missing_ids
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_users_returns_invalid_ids
|
21
|
+
invalid_ids = mock
|
22
|
+
users = FetchesUsers::Users.new(nil, invalid_ids: invalid_ids)
|
23
|
+
assert_equal invalid_ids, users.invalid_ids
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_users_returns_protected_ids
|
27
|
+
protected_ids = mock
|
28
|
+
users = FetchesUsers::Users.new(nil, protected_ids: protected_ids)
|
29
|
+
assert_equal protected_ids, users.protected_ids
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_users_returns_arrays_as_defaults
|
33
|
+
users = FetchesUsers::Users.new(nil)
|
34
|
+
assert_equal [], users.missing_ids
|
35
|
+
assert_equal [], users.invalid_ids
|
36
|
+
assert_equal [], users.protected_ids
|
37
|
+
end
|
38
|
+
|
20
39
|
def test_raises_for_a_handle
|
21
40
|
client = GrowViral::Warehouse::Client.new(:development)
|
22
41
|
assert_raises(GrowViral::HandleNotUidError) { client.users(["string"]) }
|
@@ -24,9 +43,11 @@ module GrowViral::Warehouse
|
|
24
43
|
|
25
44
|
def test_returns_output_correctly
|
26
45
|
uid1 = 328383
|
27
|
-
uid2 =
|
46
|
+
uid2 = 39994
|
47
|
+
uid3 = 4757392
|
48
|
+
uid4 = 99122
|
28
49
|
|
29
|
-
output = { '
|
50
|
+
output = { 'twitter_users' => [{'id' => uid1}], 'missing_ids' => [uid2], 'invalid_ids' => [uid3], 'protected_ids' => [uid4] }
|
30
51
|
uri = URI.parse("http://localhost:3001/tweeps/#{uid1},#{uid2}")
|
31
52
|
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
32
53
|
|
@@ -34,13 +55,15 @@ module GrowViral::Warehouse
|
|
34
55
|
users = client.users([uid1, uid2])
|
35
56
|
assert_equal [{'id' => uid1}], users.each {|u|u}
|
36
57
|
assert_equal [uid2], users.missing_ids
|
58
|
+
assert_equal [uid3], users.invalid_ids
|
59
|
+
assert_equal [uid4], users.protected_ids
|
37
60
|
end
|
38
61
|
|
39
62
|
def test_posts_account_id_if_given
|
40
63
|
uid = 328383
|
41
64
|
account_uid = 848493
|
42
65
|
|
43
|
-
output = {
|
66
|
+
output = { }
|
44
67
|
uri = URI.parse("http://localhost:3001/tweeps/#{uid}?for_account=#{account_uid}")
|
45
68
|
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
46
69
|
|
data/test/preloads_users_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class RecordsFollowWTest < Minitest::Test
|
4
4
|
def test_raises_for_a_handle
|
5
5
|
client = GrowViral::Warehouse::Client.new(:development)
|
6
6
|
assert_raises(GrowViral::HandleNotUidError) { client.register_follow!("string", 2312422) }
|
@@ -14,18 +14,18 @@ class RegistersFollowersTest < Minitest::Test
|
|
14
14
|
def test_response_is_correct
|
15
15
|
uid = 23432423
|
16
16
|
following_uid = 342423
|
17
|
+
now = 42
|
17
18
|
|
18
19
|
input = {
|
19
20
|
"uid" => uid,
|
20
|
-
"
|
21
|
+
"follow_uid" => following_uid,
|
22
|
+
"timestamp" => now
|
21
23
|
}
|
22
24
|
|
23
|
-
output = {
|
24
|
-
"uid" => uid,
|
25
|
-
"following_uid" => following_uid,
|
26
|
-
}
|
25
|
+
output = { "status" => "accepted" }
|
27
26
|
|
28
|
-
uri = URI.parse("http://localhost:3001/
|
27
|
+
uri = URI.parse("http://localhost:3001/interactions/mark_followed")
|
28
|
+
Time.expects(:now).returns(mock(to_i: 42))
|
29
29
|
Net::HTTP.expects(:post_form).with(uri, input).returns(mock(body: output.to_json))
|
30
30
|
|
31
31
|
client = GrowViral::Warehouse::Client.new(:development)
|
@@ -34,5 +34,3 @@ class RegistersFollowersTest < Minitest::Test
|
|
34
34
|
assert_equal output, actual
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class RecordsUnFollowWTest < Minitest::Test
|
4
|
+
def test_raises_for_a_handle
|
5
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
6
|
+
assert_raises(GrowViral::HandleNotUidError) { client.register_unfollow!("string", 2312422) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_raises_for_a_following_handle
|
10
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
11
|
+
assert_raises(GrowViral::HandleNotUidError) { client.register_unfollow!(972822, "string") }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_response_is_correct
|
15
|
+
uid = 23432423
|
16
|
+
following_uid = 342423
|
17
|
+
now = 42
|
18
|
+
|
19
|
+
input = {
|
20
|
+
"uid" => uid,
|
21
|
+
"follow_uid" => following_uid,
|
22
|
+
"timestamp" => now
|
23
|
+
}
|
24
|
+
|
25
|
+
output = { "status" => "accepted" }
|
26
|
+
|
27
|
+
uri = URI.parse("http://localhost:3001/interactions/mark_unfollowed")
|
28
|
+
Time.expects(:now).returns(mock(to_i: 42))
|
29
|
+
Net::HTTP.expects(:post_form).with(uri, input).returns(mock(body: output.to_json))
|
30
|
+
|
31
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
32
|
+
actual = client.register_unfollow!(uid, following_uid)
|
33
|
+
|
34
|
+
assert_equal output, actual
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growviral-warehouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
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
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: ''
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
77
|
-
-
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -87,13 +87,15 @@ files:
|
|
87
87
|
- lib/warehouse/fetches_follow_history.rb
|
88
88
|
- lib/warehouse/fetches_users.rb
|
89
89
|
- lib/warehouse/preloads_users.rb
|
90
|
-
- lib/warehouse/
|
90
|
+
- lib/warehouse/records_follow.rb
|
91
|
+
- lib/warehouse/records_unfollow.rb
|
91
92
|
- lib/warehouse/version.rb
|
92
93
|
- test/checks_follow_history_test.rb
|
93
94
|
- test/fetches_follow_history_test.rb
|
94
95
|
- test/fetches_users_test.rb
|
95
96
|
- test/preloads_users_test.rb
|
96
|
-
- test/
|
97
|
+
- test/records_follow_test.rb
|
98
|
+
- test/records_unfollow_test.rb
|
97
99
|
- test/test_helper.rb
|
98
100
|
homepage: ''
|
99
101
|
licenses:
|
@@ -105,17 +107,17 @@ require_paths:
|
|
105
107
|
- lib
|
106
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
109
|
requirements:
|
108
|
-
- -
|
110
|
+
- - '>='
|
109
111
|
- !ruby/object:Gem::Version
|
110
112
|
version: '0'
|
111
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
114
|
requirements:
|
113
|
-
- -
|
115
|
+
- - '>='
|
114
116
|
- !ruby/object:Gem::Version
|
115
117
|
version: '0'
|
116
118
|
requirements: []
|
117
119
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.1.9
|
119
121
|
signing_key:
|
120
122
|
specification_version: 4
|
121
123
|
summary: A wrapper for the GrowViral warehouse.
|
@@ -124,6 +126,6 @@ test_files:
|
|
124
126
|
- test/fetches_follow_history_test.rb
|
125
127
|
- test/fetches_users_test.rb
|
126
128
|
- test/preloads_users_test.rb
|
127
|
-
- test/
|
129
|
+
- test/records_follow_test.rb
|
130
|
+
- test/records_unfollow_test.rb
|
128
131
|
- test/test_helper.rb
|
129
|
-
has_rdoc:
|