mockstarter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca122c9c2695668619ae32af0476dc69f68e7c9c
4
+ data.tar.gz: 82fd453fd9d673fd8742a44ad9a173a3e6c8029b
5
+ SHA512:
6
+ metadata.gz: ffef8663d33d612e1548ecb60ef9816392bf6acfe5a7e542da278ee0102d27a06aa03568f97495104d9e00a3c9d925f9b310ad1b780e9f318ff2d31aceed8db1
7
+ data.tar.gz: 53e5cecabc5f577a7127dcc1901b9db7753ba0b1f2105eaa432dbd388e386601ac243becac1462679332c1dcab8999bf4f8aa9760fc747be0cf51bbc390e750d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mockstarter.gemspec
4
+ gemspec
@@ -0,0 +1,67 @@
1
+ # Mockstarter
2
+
3
+ Mockstarter. Redis backed mini kickstarter. Allows for creating, funding, and viewing backs of mockstarter projects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ Git clone this repo
10
+ ```ruby
11
+ git clone https://github.com/shannonrdunn/Mockstarter
12
+ ```
13
+
14
+ install gem dependencies
15
+ ```bash
16
+ bundle
17
+ ```
18
+
19
+ Run the rake command to build and install the gem, from the root of the git repo.
20
+ ```bash
21
+ rake install
22
+ ```
23
+
24
+ This application requires redis to be somewhere. It's the mockstarter brain. Export the redis url as a env variable.
25
+
26
+ ```
27
+ export MOCKSTARTER_BRAIN=redis://localhost:6379
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ You are ready to start your project. Create it!
33
+
34
+ ```
35
+ mockstarter project tardis 5000
36
+ ```
37
+
38
+ Check status of your project
39
+
40
+ ```
41
+ mockstarter list Tardis
42
+ ```
43
+
44
+ Back a project.
45
+ ```
46
+ back ryan california_water 4111111111111111 50
47
+ ```
48
+
49
+ Run report on a user. See who they backed.
50
+ ```
51
+ backer aurore
52
+ ```
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+
60
+ To run the unit tests, run `rake spec`.
61
+
62
+ NOTE: Unit tests use a local the same redis instance as set by export MOCKSTARTER_BRAIN, just a different db.
63
+
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shannonrdunn/mockstarter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mockstarter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mockstarter'
4
+ require 'thor'
5
+
6
+ ## CLI for Mockstarter. Takes input and creates objects to manipulate as the user wants.
7
+ ## Some workarounds in here are string manipulation on to delete ids from usernames (i am catting them together in redis)
8
+
9
+ class MockStarterCLI < Thor
10
+ desc "project PROJECTNAME GOAL", "create a project by PROJECTNAME for given GOAL"
11
+ def project(projectname, goal)
12
+ project = Mockstarter::Project.new(:projectname => projectname, :goal => goal, :redis => Redis.new(:url => ENV['MOCKSTARTER_BRAIN']))
13
+ project.create
14
+ say "Created new campaign #{projectname} with goal of $#{goal}!"
15
+ end
16
+
17
+ desc "back USERNAME PROJECTNAME CREDITCARD AMOUNT", "fund a project for USERNAME to PROJECTNAME with CREDITCARD for AMOUNT"
18
+ def back(name, projectname, creditcard, amount)
19
+ project = Mockstarter::Fund.new(:username => name, :projectname => projectname, :amount => amount, :creditcard => creditcard, :redis => Redis.new(:url => ENV['MOCKSTARTER_BRAIN']))
20
+ project.transaction
21
+ say "Backed #{projectname} with amount of $#{project.instance_variable_get(:@amount)}!"
22
+ end
23
+
24
+ desc "list PROJECTNAME", "show backers for PROJECTNAME"
25
+ def list(projectname)
26
+ project = Mockstarter::Project.new(:projectname => projectname, :redis => Redis.new(:url => ENV['MOCKSTARTER_BRAIN']))
27
+ project.log.each {|e| puts "-- " + e.sub(/(:*[:0-9][^\s]+)/,"") + "\n"}
28
+ if project.funded == true
29
+ puts "#{projectname} is SUCCESSFUL!"
30
+ else
31
+ puts "#{projectname} needs $#{project.funded} more to be SUCCESSFUL"
32
+ end
33
+ end
34
+
35
+ desc "backer USERNAME", "get projects backed by USERNAME"
36
+ def backer(username)
37
+ project = Mockstarter::Fund.new(:username => username, :redis => Redis.new(:url => ENV['MOCKSTARTER_BRAIN']))
38
+ project.log.each {|e| puts "-- " + e.sub(/(:*[:0-9][^\s]+)/,"") + "\n"}
39
+ end
40
+
41
+ end
42
+
43
+ ## Ensure that the MOCKSTARTER_BRAIN environment variable is set before starting the CLI.
44
+ if ENV['MOCKSTARTER_BRAIN'].nil?
45
+ raise ArgumentError, 'You must set MOCKSTARTER_BRAIN env variable to redis url'
46
+ end
47
+
48
+ MockStarterCLI.start(ARGV)
@@ -0,0 +1,174 @@
1
+ require "mockstarter/version"
2
+ require "redis"
3
+ require "json"
4
+
5
+
6
+ ## Core Mockstarter module
7
+ ## There are two main classes, Fund and Project. Fund is for mainly funding
8
+ ## a project and checking CC info. Project is for manipulation of Projects and
9
+ ## users.
10
+
11
+ module Mockstarter
12
+ class Fund
13
+ VALID_PARAMS = [
14
+ "username",
15
+ "projectname",
16
+ "amount",
17
+ "creditcard",
18
+ "redis"
19
+ ].freeze
20
+
21
+ def initialize(params)
22
+ ## Cast each param as a instance variable.
23
+ params.each do |key, value|
24
+ if value && VALID_PARAMS.include?(key.to_s)
25
+ instance_variable_set("@#{key}", value)
26
+ end
27
+ end if params.is_a? Hash
28
+ ## round amount to nearest 100th
29
+ @amount = (@amount.to_f * 100).round / 100.00
30
+ end
31
+
32
+ def transaction
33
+ ## Call this method on the object and it will verify your card number
34
+ ## and then pass the values to fund the project
35
+ unless card_verify == false
36
+ @redis.sadd('user_set', @username)
37
+ id = Time.now.to_i.to_s
38
+ @redis.set('user:creditcard:' + @username,
39
+ @creditcard)
40
+ @redis.hset('user:transaction:' + @username,
41
+ @projectname + ":" + id,
42
+ @amount)
43
+ @redis.hset('project:transaction:' + @projectname,
44
+ @username + ":" + id,
45
+ @amount)
46
+ end
47
+ end
48
+
49
+ def card_verify
50
+ ## Credit card verifications tests
51
+ case
52
+ when @creditcard.to_s.size > 19
53
+ fail ArgumentError, "Credit card number too large (must be less than 19)."
54
+ when luhn_check == false
55
+ fail ArgumentError, "Not valid card."
56
+ when duplicate_card == true
57
+ fail ArgumentError, "Credit taken by another user"
58
+ end
59
+ return true
60
+ end
61
+
62
+ def luhn_check
63
+ ## Luhn check stolen from wikipedia, not my code.
64
+ ## works great
65
+ s1 = s2 = 0
66
+ @creditcard.to_s.reverse.chars.each_slice(2) do |odd, even|
67
+ s1 += odd.to_i
68
+
69
+ double = even.to_i * 2
70
+ double -= 9 if double >= 10
71
+ s2 += double
72
+ end
73
+ (s1 + s2) % 10 == 0
74
+ end
75
+
76
+ def duplicate_card
77
+ ## Check for duplicate card
78
+ ## Pulls all users, deletes your own, looks up card for each user.
79
+ all_users = @redis.smembers('user_set')
80
+ all_users.delete(@username)
81
+ all_users.map { |u|
82
+ puts u
83
+ if @redis.get('user:creditcard:' + u) == @creditcard
84
+ return true
85
+ end
86
+ }
87
+ return false
88
+ end
89
+
90
+ def log
91
+ ## Log all user transactions
92
+ array = Array.new
93
+ transactions = @redis.hgetall('user:transaction:' + @username)
94
+ transactions.map { |k,v|
95
+ array.push("Backed #{k} for $#{v}")
96
+ }
97
+ return array
98
+ end
99
+ end
100
+
101
+ class Project
102
+ VALID_PARAMS = [
103
+ "projectname",
104
+ "goal",
105
+ "redis"
106
+ ].freeze
107
+
108
+ def initialize(params)
109
+ ## Read params, set as instance variables
110
+ params.each do |key, value|
111
+ if value && VALID_PARAMS.include?(key.to_s)
112
+ instance_variable_set("@#{key}", value)
113
+ end
114
+ end if params.is_a? Hash
115
+
116
+ @progress = progress
117
+ @goal = (@goal.to_f * 100).round / 100.00
118
+ end
119
+
120
+ def create
121
+ ## Ensure name passes verification, then create the project in redis.
122
+ unless name_verify == false
123
+ @redis.set('project:goal:' + @projectname,
124
+ @goal)
125
+ end
126
+ end
127
+
128
+ def progress
129
+ # Count and return total contributions for a given project
130
+ total = 0
131
+ transactions = @redis.hgetall('project:transaction:' + @projectname)
132
+ transactions.map { |k,v|
133
+ total = total + v.to_i
134
+ }
135
+ return total
136
+ end
137
+
138
+ def log
139
+ ## Log new transactions for projects
140
+ array = Array.new
141
+ transactions = @redis.hgetall('project:transaction:' + @projectname)
142
+ transactions.map { |k,v|
143
+ array.push("#{k} backed for $#{v}")
144
+ }
145
+ return array
146
+ end
147
+
148
+ def funded
149
+ ## is Project success yet? return boolean if true if false returns how much more it needs
150
+ goal = @redis.get('project:goal:' + @projectname).to_i
151
+ if @progress >= goal
152
+ return true
153
+ else
154
+ return goal - @progress
155
+ end
156
+ end
157
+
158
+ def name_verify
159
+ ## Tests for size, and characters in string, and if it already exists.
160
+ case
161
+ when @projectname.size < 4
162
+ fail ArgumentError, "Project name is too short(less than 4 characters)"
163
+ when @projectname.size > 19
164
+ fail ArgumentError, "Project name is too large(more than 19 characters)"
165
+ when (@projectname =~ /[^a-zA-Z0-9\-\_]/) != nil
166
+ fail ArgumentError, "Project names can only have a-zA-Z, -, _"
167
+ when @redis.get('project:goal:' + @projectname) != nil
168
+ fail ArgumentError, "Project already exists!"
169
+ end
170
+ return true
171
+ end
172
+
173
+ end
174
+ end
@@ -0,0 +1,3 @@
1
+ module Mockstarter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ load 'mockstarter.rb'
2
+
3
+
4
+ fund = Mockstarter::Fund.new(:username => "sdunn", :projectname => "kung fury", :amount => 823, :creditcard => 4342562230449520)
5
+ project = Mockstarter::Project.new(:projectname => "kung fury", :goal => 50000)
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mockstarter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mockstarter"
8
+ spec.version = Mockstarter::VERSION
9
+ spec.authors = ["Shannon Dunn"]
10
+ spec.email = ["shannonrdunn@gmail.com"]
11
+
12
+ spec.summary = %q{cli mock of kickstarter}
13
+ spec.description = %q{Create projects, fund projects, simply}
14
+ spec.homepage = "https://github.com/shannonrdunn/Mockstarter"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.add_runtime_dependency "redis"
21
+ spec.add_runtime_dependency "thor"
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "mock_redis"
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mockstarter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shannon Dunn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mock_redis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Create projects, fund projects, simply
98
+ email:
99
+ - shannonrdunn@gmail.com
100
+ executables:
101
+ - mockstarter
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/mockstarter
115
+ - lib/mockstarter.rb
116
+ - lib/mockstarter/version.rb
117
+ - lib/test.rb
118
+ - mockstarter.gemspec
119
+ homepage: https://github.com/shannonrdunn/Mockstarter
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: cli mock of kickstarter
142
+ test_files: []