growviral-warehouse 0.0.5 → 0.0.6
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 -0
- data/lib/warehouse/client.rb +8 -0
- data/lib/warehouse/fetches_follow_history.rb +0 -1
- data/lib/warehouse/fetches_users.rb +51 -0
- data/lib/warehouse/preloads_users.rb +39 -0
- data/lib/warehouse/version.rb +1 -1
- data/test/checks_follow_history_test.rb +2 -2
- data/test/fetches_follow_history_test.rb +1 -1
- data/test/fetches_users_test.rb +51 -0
- data/test/preloads_users_test.rb +29 -0
- data/test/registers_followers_test.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 680d544858f0dab64b7107b52cbc5a1d1a037b10
|
4
|
+
data.tar.gz: 40ac6f5371f5e6e49ec081e037b7c5e8e4f52022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5547afffa84b0ba14fe3f2dc42da70a2ecd9b869caffe5fbf5da7361e3d7aedd39e39962b5bfffe0351088ba2f5d94505002a9d6af2ca1b3daf20aaa964ce1b9
|
7
|
+
data.tar.gz: 169673ae09a1044a932304b3c99dca2fb408ebdc4d948ec276258d7bba902d824b9c2da9fcca93018b6190458f68bd61a5747401de241dd7f263423ee465ec86
|
data/lib/growviral/warehouse.rb
CHANGED
@@ -7,6 +7,8 @@ require 'warehouse/configuration'
|
|
7
7
|
require 'warehouse/registers_followers'
|
8
8
|
require 'warehouse/fetches_follow_history'
|
9
9
|
require 'warehouse/checks_follow_history'
|
10
|
+
require 'warehouse/fetches_users'
|
11
|
+
require 'warehouse/preloads_users'
|
10
12
|
|
11
13
|
module GrowViral
|
12
14
|
module Warehouse
|
data/lib/warehouse/client.rb
CHANGED
@@ -23,6 +23,14 @@ module GrowViral
|
|
23
23
|
def has_existing_relationship?(uid, following_uid)
|
24
24
|
ChecksFollowHistory.exists?(uid, following_uid, config: config)
|
25
25
|
end
|
26
|
+
|
27
|
+
def preload_users(uids, options = {})
|
28
|
+
PreloadsUsers.preload(uids, options, config: config)
|
29
|
+
end
|
30
|
+
|
31
|
+
def users(uids, options = {})
|
32
|
+
FetchesUsers.fetch(uids, options, config: config)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module GrowViral
|
4
|
+
module Warehouse
|
5
|
+
class FetchesUsers
|
6
|
+
class Users
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
extend Forwardable
|
10
|
+
def_delegators :@data, :each, :size
|
11
|
+
|
12
|
+
attr_reader :missing_ids
|
13
|
+
def initialize(data, missing_ids)
|
14
|
+
@data = data
|
15
|
+
@missing_ids = missing_ids
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.fetch(*args)
|
20
|
+
new(*args).fetch
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :uids, :options, :config
|
24
|
+
def initialize(uids, options, deps)
|
25
|
+
uids.each do |uid|
|
26
|
+
raise HandleNotUidError unless uid.is_a? Numeric
|
27
|
+
end
|
28
|
+
|
29
|
+
@uids = uids
|
30
|
+
@options = options
|
31
|
+
@config = deps[:config]
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch
|
35
|
+
response = Net::HTTP.get_response(uri)
|
36
|
+
data = JSON.parse(response.body)
|
37
|
+
Users.new(data['data'], data['missing_ids'])
|
38
|
+
end
|
39
|
+
|
40
|
+
def uri
|
41
|
+
@uri ||= URI.parse(url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def url
|
45
|
+
u = "#{config.host}/tweeps/#{uids.join(',')}"
|
46
|
+
u += "?for_account=#{options[:for_account]}" if options[:for_account]
|
47
|
+
u
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module GrowViral
|
4
|
+
module Warehouse
|
5
|
+
class PreloadsUsers
|
6
|
+
def self.preload(*args)
|
7
|
+
new(*args).preload
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
attr_reader :uids, :options, :config
|
12
|
+
def initialize(uids, options, deps)
|
13
|
+
uids.each do |uid|
|
14
|
+
raise HandleNotUidError unless uid.is_a? Numeric
|
15
|
+
end
|
16
|
+
|
17
|
+
@uids = uids
|
18
|
+
@options = options
|
19
|
+
@config = deps[:config]
|
20
|
+
end
|
21
|
+
|
22
|
+
def preload
|
23
|
+
response = Net::HTTP.post_form(uri, {})
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def uri
|
28
|
+
@uri ||= URI.parse(url)
|
29
|
+
end
|
30
|
+
|
31
|
+
def url
|
32
|
+
u = "#{config.host}/tweeps/#{uids.join(',')}"
|
33
|
+
u += "?for_account=#{options[:for_account]}" if options[:for_account]
|
34
|
+
u
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/lib/warehouse/version.rb
CHANGED
@@ -15,7 +15,7 @@ class ChecksFollowHistoryTest < Minitest::Test
|
|
15
15
|
uid = 328383
|
16
16
|
following_uid = 4843432
|
17
17
|
|
18
|
-
uri = URI.parse("http://localhost:
|
18
|
+
uri = URI.parse("http://localhost:3001/follows?uid=#{uid}&following_uid=#{following_uid}")
|
19
19
|
|
20
20
|
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '200'))
|
21
21
|
|
@@ -27,7 +27,7 @@ class ChecksFollowHistoryTest < Minitest::Test
|
|
27
27
|
uid = 3478823
|
28
28
|
following_uid = 4939383
|
29
29
|
|
30
|
-
uri = URI.parse("http://localhost:
|
30
|
+
uri = URI.parse("http://localhost:3001/follows?uid=#{uid}&following_uid=#{following_uid}")
|
31
31
|
|
32
32
|
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '404'))
|
33
33
|
|
@@ -10,7 +10,7 @@ class FetchesFollowHistoryTest < Minitest::Test
|
|
10
10
|
uid = 328383
|
11
11
|
|
12
12
|
output = { 'foo' => 'bar' }
|
13
|
-
uri = URI.parse("http://localhost:
|
13
|
+
uri = URI.parse("http://localhost:3001/follow_history?uid=#{uid}")
|
14
14
|
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
15
15
|
|
16
16
|
client = GrowViral::Warehouse::Client.new(:development)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
module GrowViral::Warehouse
|
4
|
+
class FetchesFollowHistoryTest < Minitest::Test
|
5
|
+
def test_users_is_enumerable
|
6
|
+
data = mock
|
7
|
+
data.expects(:each)
|
8
|
+
data.expects(:size)
|
9
|
+
users = FetchesUsers::Users.new(data, nil)
|
10
|
+
users.each {}
|
11
|
+
users.size
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_users_returns_missing_ids
|
15
|
+
missing_ids = mock
|
16
|
+
users = FetchesUsers::Users.new(nil, missing_ids)
|
17
|
+
assert_equal missing_ids, users.missing_ids
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_raises_for_a_handle
|
21
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
22
|
+
assert_raises(GrowViral::HandleNotUidError) { client.users(["string"]) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_returns_output_correctly
|
26
|
+
uid1 = 328383
|
27
|
+
uid2 = 328383
|
28
|
+
|
29
|
+
output = { 'data' => [{'id' => uid1}], missing_ids: [uid2] }
|
30
|
+
uri = URI.parse("http://localhost:3001/tweeps/#{uid1},#{uid2}")
|
31
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
32
|
+
|
33
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
34
|
+
users = client.users([uid1, uid2])
|
35
|
+
assert_equal [{'id' => uid1}], users.each {|u|u}
|
36
|
+
assert_equal [uid2], users.missing_ids
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_posts_account_id_if_given
|
40
|
+
uid = 328383
|
41
|
+
account_uid = 848493
|
42
|
+
|
43
|
+
output = { 'data' => [], missing_ids: [] }
|
44
|
+
uri = URI.parse("http://localhost:3001/tweeps/#{uid}?for_account=#{account_uid}")
|
45
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
46
|
+
|
47
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
48
|
+
users = client.users([uid], for_account: account_uid)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
module GrowViral::Warehouse
|
4
|
+
class FetchesFollowHistoryTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_returns_output_correctly
|
7
|
+
uid1 = 328383
|
8
|
+
uid2 = 328383
|
9
|
+
|
10
|
+
uri = URI.parse("http://localhost:3001/tweeps/#{uid1},#{uid2}")
|
11
|
+
Net::HTTP.expects(:post_form).with(uri, {}).returns(mock(body: {}.to_json))
|
12
|
+
|
13
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
14
|
+
client.preload_users([uid1, uid2])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_posts_account_id_if_given
|
18
|
+
uid = 328383
|
19
|
+
account_uid = 848493
|
20
|
+
|
21
|
+
uri = URI.parse("http://localhost:3001/tweeps/#{uid}?for_account=#{account_uid}")
|
22
|
+
Net::HTTP.expects(:post_form).with(uri, {}).returns(mock(body: {}.to_json))
|
23
|
+
|
24
|
+
client = GrowViral::Warehouse::Client.new(:development)
|
25
|
+
client.preload_users([uid], for_account: account_uid)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -25,7 +25,7 @@ class RegistersFollowersTest < Minitest::Test
|
|
25
25
|
"following_uid" => following_uid,
|
26
26
|
}
|
27
27
|
|
28
|
-
uri = URI.parse("http://localhost:
|
28
|
+
uri = URI.parse("http://localhost:3001/follows")
|
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)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,10 +85,14 @@ files:
|
|
85
85
|
- lib/warehouse/client.rb
|
86
86
|
- lib/warehouse/configuration.rb
|
87
87
|
- lib/warehouse/fetches_follow_history.rb
|
88
|
+
- lib/warehouse/fetches_users.rb
|
89
|
+
- lib/warehouse/preloads_users.rb
|
88
90
|
- lib/warehouse/registers_followers.rb
|
89
91
|
- lib/warehouse/version.rb
|
90
92
|
- test/checks_follow_history_test.rb
|
91
93
|
- test/fetches_follow_history_test.rb
|
94
|
+
- test/fetches_users_test.rb
|
95
|
+
- test/preloads_users_test.rb
|
92
96
|
- test/registers_followers_test.rb
|
93
97
|
- test/test_helper.rb
|
94
98
|
homepage: ''
|
@@ -118,6 +122,8 @@ summary: A wrapper for the GrowViral warehouse.
|
|
118
122
|
test_files:
|
119
123
|
- test/checks_follow_history_test.rb
|
120
124
|
- test/fetches_follow_history_test.rb
|
125
|
+
- test/fetches_users_test.rb
|
126
|
+
- test/preloads_users_test.rb
|
121
127
|
- test/registers_followers_test.rb
|
122
128
|
- test/test_helper.rb
|
123
129
|
has_rdoc:
|