Class: Faker::Twitter

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/twitter.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.screen_nameString

Produces a random screen name.

Examples:

Faker::Twitter.screen_name #=> "audreanne_hackett"


125
126
127
# File 'lib/faker/default/twitter.rb', line 125

def screen_name
  Faker::Internet.username(specifier: nil, separators: ['_'])[0...20]
end

.status(include_user: true, include_photo: false) ⇒ Hash

Produces a random Twitter user.

Examples:

Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
Faker::Twitter.status(include_photo: true) # Includes entities for an attached image


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/faker/default/twitter.rb', line 83

def status(include_user: true, include_photo: false)
  status_id = id
  status = {
    id: status_id,
    id_str: status_id.to_s,
    contributors: nil,
    coordinates: nil,
    created_at: created_at,
    entities: status_entities(include_photo: include_photo),
    favorite_count: Faker::Number.between(to: 1, from: 10_000),
    favorited: false,
    geo: nil,
    in_reply_to_screen_name: nil,
    in_reply_to_status_id: nil,
    in_reply_to_user_id_str: nil,
    in_reply_to_user_id: nil,
    is_quote_status: false,
    lang: Faker::Address.country_code,
    nil: nil,
    place: nil,
    possibly_sensitive: Faker::Boolean.boolean(true_ratio: 0.1),
    retweet_count: Faker::Number.between(to: 1, from: 10_000),
    retweeted_status: nil,
    retweeted: false,
    source: "<a href=\"#{Faker::Internet.url(host: 'example.com')}\" rel=\"nofollow\">#{Faker::Company.name}</a>",
    text: Faker::Lorem.sentence,
    truncated: false
  }
  status[:user] = Faker::Twitter.user(include_status: false) if include_user
  status[:text] = "#{status[:text]} #{status[:entities][:media].first[:url]}" if include_photo
  status
end

.user(include_status: true, include_email: false) ⇒ Hash

Produces a random Twitter user.

Examples:

Faker::Twitter.user #=>  {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/faker/default/twitter.rb', line 19

def user(include_status: true, include_email: false)
  user_id = id
  background_image_url = Faker::LoremFlickr.image(size: '600x400')
  profile_image_url = Faker::Avatar.image(slug: user_id, size: '48x48')
  user = {
    id: user_id,
    id_str: user_id.to_s,
    contributors_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
    created_at: created_at,
    default_profile_image: Faker::Boolean.boolean(true_ratio: 0.1),
    default_profile: Faker::Boolean.boolean(true_ratio: 0.1),
    description: Faker::Lorem.sentence,
    entities: user_entities,
    favourites_count: Faker::Number.between(to: 1, from: 100_000),
    follow_request_sent: false,
    followers_count: Faker::Number.between(to: 1, from: 10_000_000),
    following: false,
    friends_count: Faker::Number.between(to: 1, from: 100_000),
    geo_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
    is_translation_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
    is_translator: Faker::Boolean.boolean(true_ratio: 0.1),
    lang: Faker::Address.country_code,
    listed_count: Faker::Number.between(to: 1, from: 1000),
    location: "#{Faker::Address.city}, #{Faker::Address.state_abbr}, #{Faker::Address.country_code}",
    name: Faker::Name.name,
    notifications: false,
    profile_background_color: Faker::Color.hex_color,
    profile_background_image_url_https: background_image_url,
    profile_background_image_url: background_image_url.sub('https://', 'http://'),
    profile_background_tile: Faker::Boolean.boolean(true_ratio: 0.1),
    profile_banner_url: Faker::LoremFlickr.image(size: '1500x500'),
    profile_image_url_https: profile_image_url,
    profile_image_url: profile_image_url.sub('https://', 'http://'),
    profile_link_color: Faker::Color.hex_color,
    profile_sidebar_border_color: Faker::Color.hex_color,
    profile_sidebar_fill_color: Faker::Color.hex_color,
    profile_text_color: Faker::Color.hex_color,
    profile_use_background_image: Faker::Boolean.boolean(true_ratio: 0.4),
    protected: Faker::Boolean.boolean(true_ratio: 0.1),
    screen_name: screen_name,
    statuses_count: Faker::Number.between(to: 1, from: 100_000),
    time_zone: Faker::Address.time_zone,
    url: Faker::Internet.url(host: 'example.com'),
    utc_offset: utc_offset,
    verified: Faker::Boolean.boolean(true_ratio: 0.1)
  }
  user[:status] = Faker::Twitter.status(include_user: false) if include_status
  user[:email] = Faker::Internet.email if include_email
  user
end