fake_friends 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +18 -12
- data/Rakefile +1 -1
- data/dev/fetch_from_twitter.rb +41 -40
- data/fake_friends.gemspec +7 -7
- data/lib/fake_friends/version.rb +2 -2
- data/lib/fake_friends.rb +39 -19
- metadata +24 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d060a2e210db540b54d69e31c77119dda83fb339
|
4
|
+
data.tar.gz: 864176c9c950e903a21951cbd63534ef9a8bb9f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75fb2ced330d3f161fdc5a9e5b7d4966f8a5780ed26b80cf5b6b78f73f084314e525cb243a5f7e2d143819468c3a35187fe4a6471280da8483a2b2e2e8282c38
|
7
|
+
data.tar.gz: 0ae9b218e5732ed6afbf74d48e03d6e89990a4942a9dc904f739ccb762371729d38e7630d9868b78716fb8f9a2f95cc87c2581119e2731c6e2bf991fec3bb522
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,34 +1,40 @@
|
|
1
1
|
# FakeFriends
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/fake_friends.png)](http://badge.fury.io/rb/fake_friends)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/jmromer/FakeFriends.png)](https://codeclimate.com/github/jmromer/FakeFriends)
|
5
|
+
[![Dependency Status](https://gemnasium.com/jmromer/FakeFriends.png)](https://gemnasium.com/jmromer/FakeFriends)
|
6
|
+
[![Build Status](https://travis-ci.org/jmromer/FakeFriends.png?branch=master)](https://travis-ci.org/jmromer/FakeFriends)
|
7
|
+
|
3
8
|
A simple [ruby gem](https://rubygems.org/gems/fake_friends) to generate consistent and realistic fake user data for demoing social networking apps (e.g., user names match their avatars, fake posts are pulled from actual Twitter posts rather than lorem text, etc), modeled on the popular [Faker](https://github.com/stympy/faker) gem.
|
4
9
|
|
5
|
-
## Release Notes
|
6
|
-
0.1.6 December 2, 2013 (152 KB) Adds tests in RSpec
|
7
|
-
0.1.5 November 26, 2013 (148 KB) Inital release
|
8
10
|
|
9
|
-
##
|
11
|
+
## Release Notes
|
12
|
+
**1.0.0** Rewrites fetch script and updates it for Twitter API v1.1 (backwards incompatible), minor bug fixed<br>
|
13
|
+
**0.1.6** Adds tests in RSpec<br>
|
14
|
+
**0.1.5** Inital release<br>
|
10
15
|
|
11
|
-
Add this line to your application's Gemfile: `gem 'fake_friends'`
|
12
16
|
|
13
|
-
|
17
|
+
## Installation
|
14
18
|
|
15
|
-
|
19
|
+
Add this line to your application's Gemfile: `gem 'fake_friends'`<br>
|
20
|
+
And then execute: `$ bundle`<br>
|
21
|
+
Or install it yourself as: `$ gem install fake_friends`<br>
|
16
22
|
|
17
23
|
|
18
24
|
## The FakeFriend class
|
19
25
|
|
20
26
|
#### class methods
|
21
|
-
* `::gather(n)`
|
27
|
+
* `::gather(n)`
|
22
28
|
`n`: int (number of user objects to create)
|
23
|
-
* `::find_by(options)`
|
29
|
+
* `::find_by(options)`
|
24
30
|
`options`: { `username:` string (twitter username) } or { `id:` int (from 1 to 101) }
|
25
31
|
|
26
32
|
#### instance methods
|
27
33
|
* `#username`
|
28
34
|
* `#name`
|
29
35
|
* `#description`
|
30
|
-
* `#avatar_url(size)`
|
31
|
-
`size`: requested size of image. Available in 128, 73, 48, and 24 px.
|
36
|
+
* `#avatar_url(size)`
|
37
|
+
`size`: requested size of image. Available in 128, 73, 48, and 24 px.
|
32
38
|
Returns a url to an image in the closest available size.
|
33
39
|
* `#url`
|
34
40
|
* `#posts`
|
@@ -66,7 +72,7 @@ Many thanks to these users for their contributions.
|
|
66
72
|
|
67
73
|
## Future work
|
68
74
|
|
69
|
-
A hundred users should be enough for most demoing needs, but a class method to fetch fresh data from the Twitter API may be added in future.
|
75
|
+
A hundred users should be enough for most demoing needs, but a class method to fetch fresh data from the Twitter API may be added in future. The script used to fetch data from the Twitter API is included in the `dev` folder.
|
70
76
|
|
71
77
|
## Contributing
|
72
78
|
|
data/Rakefile
CHANGED
data/dev/fetch_from_twitter.rb
CHANGED
@@ -55,46 +55,51 @@ class TweetFetcher
|
|
55
55
|
|
56
56
|
puts ""
|
57
57
|
users.each_with_index do |username, user_num|
|
58
|
-
|
59
|
-
|
58
|
+
if user_exists_and_tweets_are_public?(username)
|
59
|
+
fake_friends[username] = create_user_hash_for(username)
|
60
|
+
update_output_file_with(username, user_num)
|
61
|
+
end
|
60
62
|
end
|
61
63
|
|
62
64
|
puts "Finished fetching users and tweets"
|
63
65
|
end
|
64
66
|
|
67
|
+
private
|
68
|
+
|
69
|
+
# ---
|
70
|
+
# helper method
|
71
|
+
# ---
|
72
|
+
def user_exists_and_tweets_are_public?(u)
|
73
|
+
twitter_client.user?(u) && !twitter_client.user(u).protected?
|
74
|
+
end
|
75
|
+
|
65
76
|
# ---
|
66
77
|
# For a given Twitter user, returns a hash with the following strings:
|
67
78
|
# name, location, description, url[:expanded], url[:display], image url
|
68
79
|
# and an array containing the desired number of tweets
|
69
80
|
# ---
|
70
81
|
def create_user_hash_for(u)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
begin # get display url if it exists
|
85
|
-
display_url = user.attrs[:entities][:url][:urls].first[:display_url]
|
86
|
-
rescue
|
87
|
-
display_url = nil
|
88
|
-
end
|
89
|
-
|
90
|
-
{
|
91
|
-
name: user.name, location: user.location,
|
92
|
-
description: user.description,
|
93
|
-
url: { expanded: expanded_url, display: display_url },
|
94
|
-
image: user.profile_image_url, posts: posts
|
95
|
-
}
|
96
|
-
end
|
82
|
+
user = twitter_client.user(u) # load user
|
83
|
+
posts = posts(u, max_posts_per_user) # fetch 100 posts
|
84
|
+
|
85
|
+
begin # get expanded url if it exists
|
86
|
+
expanded_url = user.attrs[:entities][:url][:urls].first[:expanded_url]
|
87
|
+
rescue
|
88
|
+
expanded_url = nil
|
89
|
+
end
|
90
|
+
|
91
|
+
begin # get display url if it exists
|
92
|
+
display_url = user.attrs[:entities][:url][:urls].first[:display_url]
|
93
|
+
rescue
|
94
|
+
display_url = nil
|
97
95
|
end
|
96
|
+
|
97
|
+
{
|
98
|
+
name: user.name, location: user.location,
|
99
|
+
description: user.description,
|
100
|
+
url: { expanded: expanded_url, display: display_url },
|
101
|
+
image: user.profile_image_url, posts: posts
|
102
|
+
}
|
98
103
|
end
|
99
104
|
|
100
105
|
# ---
|
@@ -123,20 +128,16 @@ class TweetFetcher
|
|
123
128
|
# ---
|
124
129
|
def countdown_minutes(min)
|
125
130
|
puts "taking a #{min}-minute power nap to stay within Twitter API rate limits..."
|
131
|
+
seconds = (min * 60).to_i
|
126
132
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
done
|
134
|
-
SHELL
|
135
|
-
|
136
|
-
system(clock)
|
137
|
-
puts ""
|
133
|
+
(1..seconds).reverse_each do |sec|
|
134
|
+
print "\r%02d:%02d:%02d" % [ sec / 3600, sec / 60, sec % 60 ]
|
135
|
+
$stdout.flush
|
136
|
+
sleep 1
|
137
|
+
end
|
138
|
+
puts
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
141
142
|
twitter_api = TweetFetcher.new
|
142
|
-
twitter_api.fetch_users_and_their_tweets
|
143
|
+
twitter_api.fetch_users_and_their_tweets
|
data/fake_friends.gemspec
CHANGED
@@ -5,13 +5,13 @@ require 'fake_friends/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "fake_friends"
|
8
|
-
spec.version =
|
8
|
+
spec.version = FakeFriends::VERSION
|
9
9
|
spec.authors = ["Jake Romer"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["jacob.romer@icloud.com"]
|
11
11
|
spec.description = %q{A simple fake user generator}
|
12
12
|
spec.summary = %q{Generates fake users with consistent
|
13
|
-
attributes
|
14
|
-
|
13
|
+
attributes from public Twitter accounts
|
14
|
+
and image urls from uiFaces.com.}
|
15
15
|
spec.homepage = "http://github.com/jmromer/FakeFriends"
|
16
16
|
spec.license = "MIT"
|
17
17
|
spec.files = `git ls-files`.split($/)
|
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
# TO BE ADDED
|
23
|
-
# spec.add_runtime_dependency "twitter", "~> 5.
|
23
|
+
# spec.add_runtime_dependency "twitter", "~> 5.6.0"
|
24
24
|
|
25
|
-
spec.add_development_dependency "twitter", "~> 5.
|
25
|
+
spec.add_development_dependency "twitter", "~> 5.6.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 2.14.1"
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.5.2"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.1.0"
|
30
30
|
end
|
data/lib/fake_friends/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "1.0.
|
1
|
+
module FakeFriends
|
2
|
+
VERSION = "1.0.1"
|
3
3
|
end
|
data/lib/fake_friends.rb
CHANGED
@@ -9,28 +9,36 @@ module FakeFriends
|
|
9
9
|
class FakeFriend
|
10
10
|
attr_reader :username, :name, :location, :description, :url, :posts
|
11
11
|
|
12
|
-
#
|
13
|
-
#
|
12
|
+
# Public: FakeFriend.gather(n)
|
13
|
+
# Returns n FakeFriend objects
|
14
|
+
#
|
15
|
+
# n - An Integer from 1 to 101.
|
16
|
+
#
|
17
|
+
# Examples
|
18
|
+
#
|
19
|
+
# FakeFriend.gather(2)
|
20
|
+
# # => [#<FakeFriend:0x00..>, #<FakeFriend:0x00..>]
|
21
|
+
#
|
22
|
+
# Returns an array of n FakeFriend objects
|
14
23
|
def self.gather(n)
|
15
24
|
raise ArgumentError, "Can only gather 1 to 101 FakeFriends" unless n.between?(1, 101)
|
16
25
|
users = FakeFriend.list.keys.sample(n)
|
17
26
|
users.map{ |username| FakeFriend.new(username) }
|
18
27
|
end
|
19
28
|
|
20
|
-
# FakeFriend.find_by(options)
|
29
|
+
# Public: FakeFriend.find_by(options)
|
30
|
+
# Returns a FakeFriend object for a specific user in the user listing
|
21
31
|
#
|
22
|
-
# options
|
23
|
-
#
|
24
|
-
#
|
32
|
+
# options - The Hash of options (default: {}):
|
33
|
+
# :id - Integer - User's position in the user listing, 1 to 101
|
34
|
+
# :username - String - User's Twitter username
|
25
35
|
#
|
26
|
-
#
|
27
|
-
# twitter username
|
36
|
+
# Examples
|
28
37
|
#
|
29
|
-
#
|
30
|
-
# => #<
|
38
|
+
# FakeFriend.find_by(id: 101)
|
39
|
+
# # => #<FakeFriend:0x007ff0f286e2d8 ...>
|
31
40
|
#
|
32
|
-
#
|
33
|
-
|
41
|
+
# Returns the requested FakeFriend object if found, else raises ArgumentError
|
34
42
|
def self.find_by(options)
|
35
43
|
if options[:id] && options[:id].between?(1, FakeFriend.list.count)
|
36
44
|
username = FakeFriend.list.keys[options[:id]-1]
|
@@ -42,13 +50,18 @@ module FakeFriends
|
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
|
-
# FakeFriend.new(username)
|
53
|
+
# Public: FakeFriend.new(username)
|
54
|
+
# Creates a FakeFriend object with attributes fetched from
|
55
|
+
# the user listing defined in users.yml and accesses via FakeFriend.list
|
46
56
|
#
|
47
|
-
# username
|
48
|
-
# twitter username
|
57
|
+
# username - String - a Twitter username found in the user listing
|
49
58
|
#
|
50
|
-
#
|
51
|
-
|
59
|
+
# Examples
|
60
|
+
#
|
61
|
+
# FakeFriend.new('idiot')
|
62
|
+
# # => #<FakeFriend:0x00000101348a80 @username="idiot"...>
|
63
|
+
#
|
64
|
+
# Returns a FakeFriend object with attributes populated from FakeFriend.list
|
52
65
|
def initialize(username)
|
53
66
|
@username = username
|
54
67
|
@name = FakeFriend.list[username][:name]
|
@@ -58,8 +71,11 @@ module FakeFriends
|
|
58
71
|
@posts = FakeFriend.list[username][:posts]
|
59
72
|
end
|
60
73
|
|
61
|
-
#
|
62
|
-
#
|
74
|
+
# Public: returns a user's uiFaces url in the closest available size
|
75
|
+
#
|
76
|
+
# size - Integer - the requested image size (length = width), in pixels
|
77
|
+
#
|
78
|
+
# Returns a string with the appropriate url.
|
63
79
|
def avatar_url(size)
|
64
80
|
valid_sizes = [128, 73, 48, 24]
|
65
81
|
size = valid_sizes.min { |a,b| (size-a).abs <=> (size-b).abs }
|
@@ -71,6 +87,10 @@ module FakeFriends
|
|
71
87
|
libary_file = mydir + '/fake_friends/users.yml'
|
72
88
|
@friends_list = File.open(libary_file, 'r'){|f| YAML.load(f) }
|
73
89
|
|
90
|
+
# Private: FakeFriend.list
|
91
|
+
#
|
92
|
+
# Returns a class instance Hash variable holding the
|
93
|
+
# user list defined in users.yml
|
74
94
|
def self.list
|
75
95
|
@friends_list
|
76
96
|
end
|
metadata
CHANGED
@@ -1,80 +1,81 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_friends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Romer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.6.0
|
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
|
-
version: 5.
|
26
|
+
version: 5.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.14.1
|
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: 2.14.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.5.2
|
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
|
-
version: 1.
|
54
|
+
version: 1.5.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 10.1.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: 10.1.0
|
69
69
|
description: A simple fake user generator
|
70
70
|
email:
|
71
|
-
-
|
71
|
+
- jacob.romer@icloud.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -97,21 +98,22 @@ require_paths:
|
|
97
98
|
- lib
|
98
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
|
-
- -
|
101
|
+
- - ">="
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
105
|
requirements:
|
105
|
-
- -
|
106
|
+
- - ">="
|
106
107
|
- !ruby/object:Gem::Version
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.2.2
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
|
-
summary: Generates fake users with consistent attributes
|
114
|
-
|
114
|
+
summary: Generates fake users with consistent attributes from public Twitter accounts
|
115
|
+
and image urls from uiFaces.com.
|
115
116
|
test_files:
|
116
117
|
- spec/fake_friends_spec.rb
|
117
118
|
- spec/spec_helper.rb
|
119
|
+
has_rdoc:
|