janrandom 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/janrandom ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'janrandom'
@@ -0,0 +1,9 @@
1
+ en-janrain:
2
+ faker:
3
+ name:
4
+ female_name_common: [Mary, Patricia, Linda, Barbara, Elizabeth, Jennifer, Maria, Susan, Margaret, Dorothy, Lisa, Nancy, Karen, Betty, Helen, Sandra, Donna, Carol, Ruth, Sharon, Michelle, Laura, Sarah, Kimberly, Deborah, Jessica, Shirley, Cynthia, Angela, Melissa, Brenda, Amy, Anna, Rebecca, Virginia, Kathleen, Pamela, Martha, Debra, Amanda, Stephanie, Carolyn, Christine, Marie, Janet, Catherine, Frances, Ann, Joyce, Diane, Alice, Julie, Heather, Teresa, Doris, Gloria, Evelyn, Jean, Cheryl, Mildred, Katherine, Joan, Ashley, Judith, Rose, Janice, Kelly, Nicole, Judy, Christina, Kathy, Theresa, Beverly, Denise, Tammy, Irene, Jane, Lori, Rachel, Marilyn, Andrea, Kathryn, Louise, Sara, Anne, Jacqueline, Wanda, Bonnie, Julia, Ruby, Lois, Tina, Phyllis, Norma, Paula, Diana, Annie, Lillian, Emily, Robin, Peggy, Crystal, Gladys, Rita, Dawn, Connie, Florence, Tracy, Edna, Tiffany, Carmen, Rosa, Cindy, Grace, Wendy, Victoria, Edith, Kim, Sherry, Sylvia, Josephine, Thelma, Shannon, Sheila, Ethel, Ellen, Elaine, Marjorie, Carrie, Charlotte, Monica, Esther, Pauline, Emma, Juanita, Anita, Rhonda, Hazel, Amber, Eva, Debbie, April, Leslie, Clara, Lucille, Jamie, Joanne, Eleanor, Valerie, Danielle, Megan, Alicia, Suzanne, Michele, Gail, Bertha, Darlene, Veronica, Jill, Erin, Geraldine, Lauren, Cathy, Joann, Lorraine, Lynn, Sally, Regina, Erica, Beatrice, Dolores, Bernice, Audrey, Yvonne, Annette, June, Samantha, Marion, Dana, Stacy, Ana, Renee, Ida, Vivian, Roberta, Holly, Brittany, Melanie, Loretta, Yolanda, Jeanette, Laurie, Katie, Kristen, Vanessa, Alma, Sue, Elsie, Beth, Jeanne, Vicki, Carla, Tara, Rosemary, Eileen, Terri, Gertrude, Lucy, Tonya, Ella, Stacey, Wilma, Gina, Kristin, Jessie, Natalie, Agnes, Vera, Willie, Charlene, Bessie, Delores, Melinda, Pearl, Arlene, Maureen, Colleen, Allison, Tamara, Joy, Georgia, Constance, Lillie, Claudia, Jackie, Marcia, Tanya, Nellie, Minnie, Marlene, Heidi, Glenda, Lydia, Viola, Courtney, Marian, Stella, Caroline, Dora, Jo, Vickie, Mattie, Terry, Maxine, Irma, Mabel, Marsha, Myrtle, Lena, Christy, Deanna, Patsy, Hilda, Gwendolyn, Jennie, Nora, Margie, Nina, Cassandra, Leah, Penny, Kay, Priscilla, Naomi, Carole, Brandy, Olga, Billie, Dianne, Tracey, Leona, Jenny, Felicia, Sonia, Miriam, Velma, Becky, Bobbie, Violet, Kristina, Toni, Misty, Mae, Shelly, Daisy, Ramona, Sherri, Erika, Katrina, Claire, Lindsey, Lindsay, Geneva, Guadalupe, Belinda, Margarita, Sheryl, Cora, Faye, Ada, Natasha, Sabrina, Isabel, Marguerite, Hattie, Harriet, Molly, Cecilia, Kristi, Brandi, Blanche, Sandy, Rosie, Joanna, Iris, Eunice, Angie, Inez, Lynda, Madeline, Amelia, Alberta, Genevieve, Monique, Jodi, Janie, Maggie, Kayla, Sonya, Jan, Lee, Kristine, Candace, Fannie, Maryann, Opal, Alison, Yvette, Melody, Luz, Susie, Olivia, Flora, Shelley, Kristy, Mamie, Lula, Lola, Verna, Beulah, Antoinette, Candice, Juana, Jeannette, Pam, Kelli, Hannah, Whitney, Bridget, Karla, Celia, Latoya, Patty, Shelia, Gayle, Della, Vicky, Lynne, Sheri, Marianne, Kara, Jacquelyn, Erma, Blanca, Myra, Leticia, Pat, Krista, Roxanne, Angelica, Johnnie, Robyn, Francisx,]
5
+ male_name_common: [James, John, Robert, Michael, William, David, Richard, Charles, Joseph, Thomas, Christopher, Daniel, Paul, Mark, Donald, George, Kenneth, Steven, Edward, Brian, Ronald, Anthony, Kevin, Jason, Matthew, Gary, Timothy, Jose, Larry, Jeffrey, Frank, Scott, Eric, Stephen, Andrew, Raymond, Gregory, Joshua, Jerry, Dennis, Walter, Patrick, Peter, Harold, Douglas, Henry, Carl, Arthur, Ryan, Roger, Joe, Juan, Jack, Albert, Jonathan, Justin, Terry, Gerald, Keith, Samuel, Willie, Ralph, Lawrence, Nicholas, Roy, Benjamin, Bruce, Brandon, Adam, Harry, Fred, Wayne, Billy, Steve, Louis, Jeremy, Aaron, Randy, Howard, Eugene, Carlos, Russell, Bobby, Victor, Martin, Ernest, Phillip, Todd, Jesse, Craig, Alan, Shawn, Clarence, Sean, Philip, Chris, Johnny, Earl, Jimmy, Antonio, Danny, Bryan, Tony, Luis, Mike, Stanley, Leonard, Nathan, Dale, Manuel, Rodney, Curtis, Norman, Allen, Marvin, Vincent, Glenn, Jeffery, Travis, Jeff, Chad, Jacob, Lee, Melvin, Alfred, Kyle, Francis, Bradley, Jesus, Herbert, Frederick, Ray, Joel, Edwin, Don, Eddie, Ricky, Troy, Randall, Barry, Alexander, Bernard, Mario, Leroy, Francisco, Marcus, Micheal, Theodore, Clifford, Miguel, Oscar, Jay, Jim, Tom, Calvin, Alex, Jon, Ronnie, Bill, Lloyd, Tommy, Leon, Derek, Warren, Darrell, Jerome, Floyd, Leo, Alvin, Tim, Wesley, Gordon, Dean, Greg, Jorge, Dustin, Pedro, Derrick, Dan, Lewis, Zachary, Corey, Herman, Maurice, Vernon, Roberto, Clyde, Glen, Hector, Shane, Ricardo, Sam, Rick, Lester, Brent, Ramon, Charlie, Tyler, Gilbert, Gene, Marc, Reginald, Ruben, Brett, Angel, Nathaniel, Rafael, Leslie, Edgar, Milton, Raul, Ben, Chester, Cecil, Duane, Franklin, Andre, Elmer, Brad, Gabriel, Ron, Mitchell, Roland, Arnold, Harvey, Jared, Adrian, Karl, Cory, Claude, Erik, Darryl, Jamie, Neil, Jessie, Christian, Javier, Fernando, Clinton, Ted, Mathew, Tyrone, Darren, Lonnie, Lance, Cody, Julio, Kelly, Kurt, Allan, Nelson, Guy, Clayton, Hugh, Max, Dwayne, Dwight, Armando, Felix, Jimmie, Everett, Jordan, Ian, Wallace, Ken, Bob, Jaime, Casey, Alfredo, Alberto, Dave, Ivan, Johnnie, Sidney, Byron, Julian, Isaac, Morris, Clifton, Willard, Daryl, Ross, Virgil, Andy, Marshall, Salvador, Perry, Kirk, Sergio, Marion, Tracy, Seth, Kent, Terrance, Rene, Eduardo, Terrence, Enrique, Freddie, Wade]
6
+ lorem:
7
+ interests: [aerobics, amusement parks, baking, baseball, bicycling, bird-watching, canoeing, carpentry, cats, coding, cooking, dogs, exercising, fishing, football, gardening, geneology, hang-gliding, hiking, hunting, kayaking, knitting, macrame, model trains, motorcycles, music (performing), parenting, quilting, racing, reading, roller coasters, rowing, running, sailing, scrapbooking, skiing, skydiving, soccer, strategy games, swimming, surfing, tennis, travel, writing, video games]
8
+ music: ["The Beatles", "Elvis Presley", "Michael Jackson", "Madonna", "Elton John", "Led Zeppelin", "Pink Floyd", "Mariah Carey", "Celine Dion", "Whitney Houston", "AC/DC", "The Rolling Stones", "Queen", "ABBA", "Garth Brooks", "Eagles", "U2", "Billy Joel", "Bruce Springsteen", "Barbra Streisand", "Phil Collins", "Aerosmith", "Frank Sinatra", "Genesis", "Donna Summer", "Neil Diamond", "Bee Gees", "Julio Iglesias", "Dire Straits", "Taylor Swift", "Rihanna", "Metallica", "Eminem", "Britney Spears", "Bon Jovi", "Fleetwood Mac", "Rod Stewart", "Backstreet Boys", "Guns 'N Roses", "Prince", "Kenny Rogers", "Janet Jackson", "Chicago", "The Carpenters", "George Michael", "Def Leppard", "Bob Dylan", "Bryan Adams", "Cher", "Lionel Richie", "Olivia Newton-John", "Linda Ronstadt", "Tina Turner", "Stevie Wonder", "The Beach Boys", "Kiss", "Paul McCartney", "The Who", "Barry White", "Robin Thicke", "Miley Cyrus", "Jay-Z", "Daft Punk", "One Direction", "Bruno Mars", "Selena Gomez", "Maroon 5", "Phillip Phillips", "Justin Timberlake", "Pink", "Blake Shelton", "Darius Rucker", "Jason Aldean", "Keith Urban", "Carrie Underwood", "Train", "Collective Soul", "Pitbull", "Lil Wayne", "The 5th Dimension", "Brad Paisley", "Mumford & Sons", "Kelly Clarkson", "James Blunt", "Drake", "Kanye West", "Zac Brown Band", "Lady Antebellum", "Fun.", "Kid Rock", "Edward Sharpe and the Magnetic Zeros", "Outkast", "White Stripes", "Black Keys", "Sly and the Family Stone", "Beyonce", "Jimi Hendrix", "Christina Aguilera", "Neil Young", "Van Morrison", "Lady Gaga"]
9
+ movies: ["The Shawshank Redemption", "The Godfather", "The Godfather: Part II", "Pulp Fiction", "The Good, the Bad and the Ugly", "The Dark Knight", "12 Angry Men", "Schindler's List", "The Lord of the Rings: The Return of the King", "Fight Club", "Star Wars: Episode V - The Empire Strikes Back", "The Lord of the Rings: The Fellowship of the Ring", "One Flew Over the Cuckoo's Nest", "Inception", "Goodfellas", "Star Wars", "Seven Samurai", "Forrest Gump", "The Matrix", "The Lord of the Rings: The Two Towers", "City of God", "Se7en", "The Silence of the Lambs", "Once Upon a Time in the West", "Casablanca", "The Usual Suspects", "Raiders of the Lost Ark", "Rear Window", "It's a Wonderful Life", "Psycho", "Léon: The Professional", "Sunset Blvd.", "American History X", "Apocalypse Now", "Terminator 2: Judgment Day", "Memento", "Saving Private Ryan", "City Lights", "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb", "Alien", "Spirited Away", "Modern Times", "North by Northwest", "Back to the Future", "Citizen Kane", "Life Is Beautiful", "The Shining", "The Pianist", "The Departed", "M", "Vertigo", "Django Unchained", "Paths of Glory", "The Dark Knight Rises", "Taxi Driver", "American Beauty", "Aliens", "Double Indemnity", "The Intouchables", "WALL·E", "Gladiator", "The Green Mile", "Toy Story 3", "The Lives of Others", "The Great Dictator", "A Clockwork Orange", "The Prestige", "Amélie", "Lawrence of Arabia", "To Kill a Mockingbird", "Reservoir Dogs", "Das Boot", "Cinema Paradiso", "The Lion King", "The Treasure of the Sierra Madre", "The Third Man", "Requiem for a Dream", "Star Wars: Episode VI - Return of the Jedi", "Once Upon a Time in America", "Eternal Sunshine of the Spotless Mind", "Full Metal Jacket", "Braveheart", "Oldboy", "L.A. Confidential", "Chinatown", "Singin' in the Rain", "Bicycle Thieves", "Monty Python and the Holy Grail", "Some Like It Hot", "Metropolis", "Princess Mononoke", "Rashomon", "Amadeus", "2001: A Space Odyssey", "The Sting", "All About Eve", "The Apartment", "Unforgiven", "Indiana Jones and the Last Crusade", "Grave of the Fireflies", "Witness for the Prosecution", "Raging Bull", "The Bridge on the River Kwai", "Die Hard", "Batman Begins", "A Separation", "Yojimbo", "Inglourious Basterds", "For a Few Dollars More", "Snatch.", "The Great Escape", "Toy Story", "Mr. Smith Goes to Washington", "Up", "Downfall", "Pan's Labyrinth", "On the Waterfront", "The General", "The Seventh Seal", "Heat", "The Elephant Man", "The Maltese Falcon", "The Kid", "Blade Runner", "Scarface", "Wild Strawberries", "Rebecca", "Gran Torino", "Fargo", "Ran", "Ikiru", "The Big Lebowski", "Touch of Evil", "The Gold Rush", "The Deer Hunter", "Cool Hand Luke", "Lock, Stock and Two Smoking Barrels", "It Happened One Night", "No Country for Old Men", "Casino", "Sin City", "The Sixth Sense", "Good Will Hunting", "Strangers on a Train", "Platoon", "Jaws", "The Thing", "Butch Cassidy and the Sundance Kid", "Trainspotting", "The Wizard of Oz", "Kill Bill: Vol. 1", "Warrior", "High Noon", "The Secret in Their Eyes", "Hotel Rwanda", "The Grapes of Wrath", "Gone with the Wind", "Annie Hall", "The Avengers", "My Neighbor Totoro", "Finding Nemo", "V for Vendetta", "Notorious", "Dial M for Murder", "Into the Wild", "How to Train Your Dragon", "Life of Brian", "The Night of the Hunter", "There Will Be Blood", "Network", "The Terminator", "Ben-Hur", "Million Dollar Baby", "The King's Speech", "The Big Sleep", "Stand by Me", "The Hunt", "The Best Years of Our Lives", "Groundhog Day", "The 40 Blows", "Twelve Monkeys", "Mary and Max", "Donnie Darko", "Dog Day Afternoon", "Howl's Moving Castle", "Amores Perros", "The Bourne Ultimatum", "Persona", "Gandhi", "The Killing", "A Beautiful Mind", "Black Swan", "The Graduate", "The Princess Bride", "8½", "Who's Afraid of Virginia Woolf?", "The Hustler", "La Strada", "Rocky", "Star Trek Into Darkness", "Slumdog Millionaire", "Anatomy of a Murder", "The Man Who Shot Liberty Valance", "The Manchurian Candidate", "Rope", "The Exorcist", "The Wild Bunch", "Barry Lyndon", "Life of Pi", "In the Name of the Father", "Stalag 17", "Monsters, Inc.", "Infernal Affairs", "Fanny and Alexander", "Roman Holiday", "Sleuth", "Memories of Murder", "The Truman Show", "Pirates of the Caribbean: The Curse of the Black Pearl", "Stalker", "The Hobbit: An Unexpected Journey", "3 Idiots", "Like Stars on Earth", "Harry Potter and the Deathly Hallows: Part 2", "A Fistful of Dollars", "Star Trek", "Jurassic Park", "Ip Man", "The Artist", "Incendies", "District 9", "Ratatouille", "A Streetcar Named Desire", "La Haine", "Shutter Island", "The Diving Bell and the Butterfly", "Rain Man", "All Quiet on the Western Front", "Beauty and the Beast", "Rosemary's Baby", "Nausicaä of the Valley of the Wind", "Papillon", "Harvey", "Mystic River", "Before Sunrise", "Spring, Summer, Fall, Winter... and Spring", "The Untouchables", "In the Mood for Love", "The Celebration", "Manhattan", "Iron Man 3", "Despicable Me 2", "Man of Steel", "Monsters University", "Fast & Furious 6", "Oz the Great and Powerful", "Star Trek Into Darkness", "World War Z", "The Croods", "The Great Gatsby", "The Heat", "Identity Thief", "G.I. Joe: Retaliation", "Now You See Me", "The Hangover Part III", "Grown Ups 2", "Epic", "Olympus Has Fallen", "This Is The End", "42"]
data/lib/janrandom.rb ADDED
@@ -0,0 +1,375 @@
1
+ # == Synopsis
2
+ # Janrain Random User Generator
3
+ # Blah blah blah.
4
+ #
5
+ # == Examples
6
+ # Initialize your app for random user generation:
7
+ # (This will prompt you for Capture domain, client id, and secret,
8
+ # and save those credentials, as well as the app schema in a config file)
9
+ # janrandom init myapp
10
+ #
11
+ # Create 100 random users in your Janrain Capture app
12
+ # janrandom create myapp 100
13
+ #
14
+ # Uncreate all random users created with this script:
15
+ # janrandom uncreate myapp
16
+ #
17
+ # Remove the "janrandomIsAutoGenerated" flag from the app schema:
18
+ # janrandom uninit myapp
19
+ #
20
+ # == Usage
21
+ # janrandom create {app} [number]
22
+ #
23
+ # For help use: janrandom -h
24
+ #
25
+ # == Options
26
+ # -h, --help Displays help message
27
+ # -v, --version Display the version, then exit
28
+ # -q, --quiet Output as little as possible, overrides verbose
29
+ # -V, --verbose Verbose output
30
+ # TO DO - add additional options
31
+ #
32
+ # == Author
33
+ # Janrain
34
+ #
35
+ # == Copyright
36
+ # Copyright (c) 2013 Janrain. Licensed under the MIT License:
37
+ # http://www.opensource.org/licenses/mit-license.php
38
+
39
+ require 'i18n'
40
+ I18n.load_path += Dir[File.join(File.expand_path(File.dirname(__FILE__)),'data','*.yml')]
41
+ I18n.locale = 'en-janrain'
42
+
43
+ require 'thor'
44
+ require 'highline/import'
45
+ require 'yaml'
46
+ require 'rest_client'
47
+ require 'faker'
48
+ require 'terminal-table'
49
+
50
+ class JanRandom < Thor
51
+ option :verbose, :type => :boolean
52
+
53
+ desc "apps", "display a list of Capture apps configured for janrandom"
54
+ def apps()
55
+ read_options
56
+
57
+ puts 'Apps available to janrandom:'
58
+ @apps.each_key { |key| puts key }
59
+ end
60
+
61
+
62
+ desc "init APP", "set up APP for random-user generation"
63
+ def init(app)
64
+ read_options
65
+
66
+ if @apps && @apps.has_key?(app)
67
+ puts 'Using credentials from janrandom.appconfig file...'
68
+ appoptions = @apps[app]
69
+ else
70
+ puts "Enter credentials for #{app}...\n"
71
+ appoptions = Hash.new
72
+ appoptions[:server] = ask("Capture Server? ") { |q| q.default = app }
73
+ appoptions[:clientid] = ask("Client ID? ") { |q| q.default = "none" }
74
+ appoptions[:clientsecret] = ask("Client Secret? ") { |q| q.echo = "x" }
75
+ @apps[app] = appoptions
76
+ File.open(@config_file, 'w') { |f| YAML.dump(@apps, f) }
77
+ end
78
+
79
+ entityType = RestClient.post( "https://#{appoptions[:server]}/entityType",
80
+ {
81
+ :client_id => appoptions[:clientid],
82
+ :client_secret => appoptions[:clientsecret],
83
+ :type_name => 'user'
84
+ }
85
+ )
86
+
87
+ attrDefs = JSON.parse( entityType )
88
+
89
+ @schema = { }
90
+ parse_attr_defs( attrDefs['schema']['attr_defs'] )
91
+
92
+ # If there's no "janRandomGenerated" attribute in the schema, add it now
93
+ unless @schema.has_key?('janRandomGenerated')
94
+ RestClient.post( "https://#{appoptions[:server]}/entityType.addAttribute",
95
+ {
96
+ :client_id => appoptions[:clientid],
97
+ :client_secret => appoptions[:clientsecret],
98
+ :type_name => 'user',
99
+ :attr_def => '{"name":"janRandomGenerated","type":"string","length":1}'
100
+ }
101
+ )
102
+ end
103
+
104
+ @apps[app][:schema] = @schema
105
+ File.open(@config_file, 'w') { |f| YAML.dump(@apps, f) }
106
+
107
+ puts "Successfully prepared app #{app} for random user generation."
108
+ end
109
+
110
+
111
+ desc "create APP [NUMBER]", "create NUMBER (defaults to 10) dummy users for the Capture app APP"
112
+ def create(app, number = 10)
113
+ read_options
114
+
115
+ unless @apps.has_key?(app)
116
+ puts "#{app} has not been initialized to JRUG yet. Try running `janrandom init #{app}` first."
117
+ exit
118
+ end
119
+
120
+ puts "Creating #{number} randomized users for #{app}:"
121
+
122
+ randomUsers = [ ]
123
+ number.to_i.times do
124
+ user = UserAttrs.new()
125
+ record = { }
126
+ @apps[app][:schema].each do |attr,meth|
127
+ if meth.is_a?(String) && UserAttrs.method_defined?(meth)
128
+ record[attr] = user.send(meth)
129
+ end
130
+ end
131
+
132
+ randomUsers << record
133
+ user = nil
134
+ end
135
+
136
+ appoptions = @apps[app]
137
+
138
+ createdUsers = RestClient.post( "https://#{appoptions[:server]}/entity.bulkCreate",
139
+ {
140
+ :client_id => appoptions[:clientid],
141
+ :client_secret => appoptions[:clientsecret],
142
+ :type_name => 'user',
143
+ :all_attributes => JSON.dump(randomUsers)
144
+ }
145
+ )
146
+
147
+ apiResponse = JSON.parse( createdUsers )
148
+
149
+ tableRows = apiResponse['uuid_results'].zip(
150
+ randomUsers.collect { |n| n['displayName'] },
151
+ randomUsers.collect { |n| n['email'] },
152
+ randomUsers.collect { |n| n['currentLocation'] }
153
+ )
154
+
155
+ table = Terminal::Table.new :rows => tableRows
156
+ puts table
157
+ end
158
+
159
+
160
+ desc "uncreate APP", "uncreate (bulk delete) dummy users created for the Capture app APP"
161
+ def uncreate(app)
162
+
163
+ read_options
164
+ unless @apps.has_key?(app)
165
+ puts "#{app} has not been initialized to JRUG yet. Try running `janrandom init #{app}` first."
166
+ exit
167
+ end
168
+
169
+ appoptions = @apps[app]
170
+
171
+ deletedUsers = RestClient.post( "https://#{appoptions[:server]}/entity.bulkDelete",
172
+ {
173
+ :client_id => appoptions[:clientid],
174
+ :client_secret => appoptions[:clientsecret],
175
+ :type_name => 'user',
176
+ :filter => 'janRandomGenerated is not null',
177
+ :commit => true
178
+ }
179
+ )
180
+
181
+ apiResponse = JSON.parse( deletedUsers )
182
+ if apiResponse.has_key?('delete_count')
183
+ puts ( apiResponse['delete_count'] > 0 ) ?
184
+ "Successfully deleted #{apiResponse['delete_count']} random people from #{app}." :
185
+ "No random users left to delete from this app!"
186
+ else
187
+ puts "Error deleting users."
188
+ puts apiResponse
189
+ end
190
+
191
+ end
192
+
193
+ desc "uninit APP", "remove the flag field added to app schema by this tool"
194
+ def uninit(app)
195
+
196
+ read_options
197
+ unless @apps.has_key?(app)
198
+ puts 'Invalid app name.'
199
+ exit
200
+ end
201
+
202
+ # If there is a "janRandomGenerated" attribute in the schema, remove it now
203
+ if @apps[app].has_key?('janRandomGenerated')
204
+ apiResponse = RestClient.post( "https://#{appoptions[:server]}/entityType.removeAttribute",
205
+ {
206
+ :client_id => appoptions[:clientid],
207
+ :client_secret => appoptions[:clientsecret],
208
+ :type_name => 'user',
209
+ :attr_name => 'janRandomGenerated'
210
+ }
211
+ )
212
+ puts apiResponse
213
+ end
214
+ end
215
+
216
+ desc "test APP", "Dry-run, display a random user such as that would be generated for APP's schema"
217
+ def test(app)
218
+ read_options
219
+ unless @apps.has_key?(app)
220
+ puts 'Invalid app name.'
221
+ exit
222
+ end
223
+
224
+ user = UserAttrs.new()
225
+ record = { }
226
+ @apps[app][:schema].each do |attr,meth|
227
+ if meth.is_a?(String) && UserAttrs.method_defined?(meth)
228
+ record[attr] = user.send(meth)
229
+ end
230
+ end
231
+
232
+ table = Terminal::Table.new :rows => record
233
+ puts table
234
+ end
235
+
236
+ no_commands {
237
+ def read_options
238
+ @config_file = File.expand_path("~/janrandom.appconfig")
239
+ if File.exist?(@config_file)
240
+ @apps = YAML::load( File.open(@config_file) )
241
+ else
242
+ @apps = { }
243
+ end
244
+ end
245
+
246
+ def parse_attr_defs( entity, depth = false )
247
+ entity.each { |attr|
248
+ if attr['name']
249
+ attr_method = UserAttrs.method_defined?(attr['name']) ? attr['name'] : attr['type']
250
+ if attr['attr_defs']
251
+ @schema[ attr['name'] ] = parse_attr_defs( attr['attr_defs'], "#{depth}#{attr['name']}." )
252
+ else UserAttrs.method_defined?(attr['name'])
253
+ attr_method = UserAttrs.method_defined?(attr['name']) ? attr['name'] : attr['type']
254
+ if depth
255
+ return attr_method
256
+ else
257
+ @schema[ attr['name'] ] = attr_method
258
+ end
259
+ end
260
+ end
261
+ }
262
+ end
263
+
264
+ }
265
+
266
+ end
267
+
268
+ module Faker
269
+ class Base
270
+ class << self
271
+
272
+ def fetch_with_weighting(key)
273
+ fetched = translate("faker.#{key}")
274
+ num = rand(fetched.length) + rand(fetched.length) - fetched.length
275
+ fetched = fetched[num.abs] if fetched.respond_to?(:sample)
276
+ if fetched.match(/^\//) and fetched.match(/\/$/) # A regex
277
+ regexify(fetched)
278
+ else
279
+ fetched
280
+ end
281
+ end
282
+
283
+ def random_in_range( from, to )
284
+ from, to = to, from if to < from
285
+ rand * (to - from ) + from
286
+ end
287
+
288
+ def bell_random_in_range( from, to )
289
+ from, to = to, from if to < from
290
+ ( rand * (to - from ) + rand * (to - from ) ) / 2 + from
291
+ end
292
+
293
+ end
294
+ end
295
+ end
296
+
297
+ class UserAttrs
298
+ def initialize
299
+ @aboutMe
300
+ @birthday
301
+ @givenName
302
+ @middleName
303
+ @displayName
304
+ @familyName
305
+ @email
306
+ @currentLocation
307
+ @gender
308
+ @interests
309
+ @music
310
+ @movies
311
+ end
312
+
313
+ def aboutMe
314
+ @aboutMe ||= Faker::Lorem.paragraph
315
+ end
316
+
317
+ def birthday
318
+ now = Time.now().to_i()
319
+ d = Faker::Base.bell_random_in_range( now - 13 * 365 * 24 * 3600, now - 60 * 365 * 24 * 3600 )
320
+ Time.at(d).strftime('%Y-%m-%d')
321
+ end
322
+
323
+ def givenName
324
+ gender = gender()
325
+ @givenName ||= (gender == 'female') ?
326
+ Faker::Base.fetch_with_weighting('name.female_name_common')
327
+ : Faker::Base.fetch_with_weighting('name.male_name_common')
328
+ end
329
+
330
+ def middleName
331
+ gender = gender()
332
+ @middleName ||= (gender == 'female') ?
333
+ Faker::Base.fetch_with_weighting('name.female_name_common')
334
+ : Faker::Base.fetch_with_weighting('name.male_name_common')
335
+ end
336
+
337
+ def displayName
338
+ @displayName ||= [givenName(),familyName()].join(' ')
339
+ end
340
+
341
+ def familyName
342
+ @familyName ||= Faker::Name.last_name
343
+ end
344
+
345
+ def email
346
+ @email ||= Faker::Internet.email([givenName(),familyName()].join(' '))
347
+ end
348
+
349
+ def currentLocation
350
+ @currentLocation ||= Faker::Address.city + ', ' + Faker::Address.state
351
+ end
352
+
353
+ def gender
354
+ @gender ||= ['male', 'female'].sample
355
+ end
356
+
357
+ def interests
358
+ @interests ||= Random.rand(12).times.map{ Faker::Base.fetch_with_weighting('lorem.interests') }.uniq
359
+ end
360
+
361
+ def music
362
+ @music ||= Random.rand(12).times.map{ Faker::Base.fetch_with_weighting('lorem.music') }.uniq
363
+ end
364
+
365
+ def movies
366
+ @movies ||= Random.rand(12).times.map{ Faker::Base.fetch_with_weighting('lorem.movies') }.uniq
367
+ end
368
+
369
+ def janRandomGenerated
370
+ "Y"
371
+ end
372
+ end
373
+
374
+ # Create and run the application
375
+ JanRandom.start(ARGV)
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: janrandom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathaniel Taintor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: i18n
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faker
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rest-client
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: terminal-table
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A toolkit for generating and managing randomized dummy users for your
95
+ Capture instance
96
+ email: than@janrain.com
97
+ executables:
98
+ - janrandom
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - lib/janrandom.rb
103
+ - lib/data/en-janrain.yml
104
+ - bin/janrandom
105
+ homepage: http://github.com/thanj/janrandom
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.23
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Fake users for Janrain Capture
130
+ test_files: []