buttermilk_biscuits 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80ecbaad68b671201932e2abe4d5b0e1364486dda43f46b1a425106c8da69150
4
- data.tar.gz: 80963a9dd2ccf814da897c06b38d00837c132151fb99fc9faa4bc181f0178e15
3
+ metadata.gz: 5c6c03cff0e60de2877ed0f4048d1993ceb528594ec23f65dda5b7095b3f3857
4
+ data.tar.gz: 9d4806d46ddccc9461c60b7eb5ef77674c7a62b0428936d28818866b1b488d3e
5
5
  SHA512:
6
- metadata.gz: 7f21375b67b22648da922392d162de57cf6656c32752dedbe1e2867aa0fcb995dfa2af9ddb0f952d53bd280fe2f1195fcf090fa295000276aa6bcf067d10a5fb
7
- data.tar.gz: 0156503f9f9199caa67c91fe46c93699bc0e363ce01be5286afd89fed77588aa44fc4f51452f0d571fb72de2ca71fec1f99328fdb02c314e8152426c75a4d102
6
+ metadata.gz: 034ab2181639f263c0132e12ccdd35f47cf26fb708538f130ae75a46ed789a471dc6ee2cfad2c01b331b3d57040ea904bcb2bc080a711bebb30da22a608171fa
7
+ data.tar.gz: 3ba484f3c5850f1924e6e1dff0ef52e2f3cbea66b39833386d87bdc998251bbe6e77cb912d005df295458d7c0be7d09072e7ae35cbccde9163b972279b98c2bd
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in buttermilk_biscuits.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 JackMarx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # ButtermilkBiscuits
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/buttermilk_biscuits`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ### Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'buttermilk_biscuits'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install buttermilk_biscuits
22
+
23
+ ## Usage
24
+
25
+ Here is the file to start up Cookbook Interface.
26
+
27
+ ```ruby
28
+ require 'buttermilk_biscuits'
29
+
30
+ # this line starts your terminal interface.
31
+ ButtermilkBiscuits::Frontend.new.run
32
+ ```
33
+
34
+ Once you create this file run from terminal or use the excutable in the terminal.
35
+
36
+ ```
37
+ $ cook_me
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec 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).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/StraightOuttaConstant/buttermilk_biscuits.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "buttermilk_biscuits"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "buttermilk_biscuits/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buttermilk_biscuits"
8
+ spec.version = ButtermilkBiscuits::VERSION
9
+ spec.authors = ["JackMarx"]
10
+ spec.email = ["seriousfools@gmail.com"]
11
+
12
+ spec.summary = "terminal interface for classroom cookbook app"
13
+ spec.description = "I have struggled long and hard to get access to my recipes from the terminal, this is the tool that granted my wishes."
14
+ spec.homepage = "https://github.com/StraightOuttaConstant/buttermilk_biscuits"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.executables = []
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_dependency "unirest", "1.1.2"
36
+ end
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
@@ -0,0 +1,279 @@
1
+ require "buttermilk_biscuits/version"
2
+ require 'unirest'
3
+
4
+ module ButtermilkBiscuits
5
+ module RecipesController
6
+ def recipes_index_action
7
+ recipe_hashs = get_request("/recipes")
8
+ recipes = Recipe.convert_hashs(recipe_hashs)
9
+ recipes_index_view(recipes)
10
+ end
11
+
12
+ def recipes_show_action
13
+ input_id = recipes_id_form
14
+ recipe_hash = get_request("/recipes/#{input_id}")
15
+ recipe = Recipe.new(recipe_hash)
16
+
17
+ recipes_show_view(recipe)
18
+ end
19
+
20
+ def recipes_create_action
21
+ client_params = recipes_new_form
22
+ json_data = post_request("/recipes", client_params)
23
+
24
+ if !json_data["errors"]
25
+ recipe = Recipe.new(json_data)
26
+ recipes_show_view(recipe)
27
+ else
28
+ errors = json_data["errors"]
29
+ recipes_errors_view(errors)
30
+ end
31
+ end
32
+
33
+ def recipes_update_action
34
+ input_id = recipes_id_form
35
+ recipe_hash = get_request("/recipes/#{input_id}")
36
+ recipe = Recipe.new(recipe_hash)
37
+
38
+ client_params = recipes_update_form(recipe)
39
+ json_data = patch_request("/recipes/#{input_id}", client_params)
40
+
41
+ if !json_data["errors"]
42
+ recipe = Recipe.new(json_data)
43
+ recipes_show_view(recipe)
44
+ else
45
+ errors = json_data["errors"]
46
+ recipes_errors_view(errors)
47
+ end
48
+ end
49
+
50
+ def recipes_destroy_action
51
+ input_id = recipes_id_form
52
+ json_data = delete_request("/recipes/#{input_id}")
53
+ puts json_data["message"]
54
+ end
55
+ end
56
+
57
+ module RecipesViews
58
+ def recipes_index_view(recipes)
59
+ puts "*" * 70
60
+ recipes.each do |recipe|
61
+ recipes_show_view(recipe)
62
+ puts "*" * 70
63
+ end
64
+ end
65
+
66
+ def recipes_show_view(recipe)
67
+ puts
68
+ puts recipe.title.upcase
69
+ puts "=" * 70
70
+ puts "by: #{recipe.chef}".ljust(35) + "prep: #{recipe.formatted_prep_time}".rjust(35)
71
+ puts
72
+ puts "Ingredients"
73
+ puts "-" * 70
74
+ recipe.formatted_ingredients.each do |ingredient|
75
+ puts " • #{ingredient}"
76
+ end
77
+ puts
78
+ puts "Directions"
79
+ puts "-" * 70
80
+ recipe.formatted_directions.each_with_index do |direction, index|
81
+ puts " #{index + 1}. #{direction}"
82
+ end
83
+ puts
84
+ end
85
+
86
+ def recipes_id_form
87
+ print "Enter recipe id: "
88
+ gets.chomp
89
+ end
90
+
91
+ def recipes_new_form
92
+ client_params = {}
93
+
94
+ print "Title: "
95
+ client_params[:title] = gets.chomp
96
+
97
+ print "Ingredients: "
98
+ client_params[:ingredients] = gets.chomp
99
+
100
+ print "Directions: "
101
+ client_params[:directions] = gets.chomp
102
+
103
+ print "Prep Time: "
104
+ client_params[:prep_time] = gets.chomp
105
+
106
+ client_params
107
+ end
108
+
109
+ def recipes_update_form(recipe)
110
+ client_params = {}
111
+
112
+ print "Title (#{recipe.title}): "
113
+ client_params[:title] = gets.chomp
114
+
115
+ print "Chef (#{recipe.chef}): "
116
+ client_params[:chef] = gets.chomp
117
+
118
+ print "Ingredients (#{recipe.ingredients}): "
119
+ client_params[:ingredients] = gets.chomp
120
+
121
+ print "Directions (#{recipe.directions}): "
122
+ client_params[:directions] = gets.chomp
123
+
124
+ print "Prep Time (#{recipe.prep_time}): "
125
+ client_params[:prep_time] = gets.chomp
126
+
127
+ client_params.delete_if { |key, value| value.empty? }
128
+ client_params
129
+ end
130
+ end
131
+
132
+ class Recipe
133
+ attr_accessor :id, :title, :chef, :ingredients, :directions, :created_at, :prep_time, :formatted_ingredients, :formatted_directions, :formatted_prep_time
134
+ def initialize(input_options)
135
+ @id = input_options["id"]
136
+ @title = input_options["title"]
137
+ @chef = input_options["chef"]
138
+ @ingredients = input_options["ingredients"]
139
+ @directions = input_options["directions"]
140
+ @created_at = input_options["created_at"]
141
+ @prep_time = input_options["prep_time"]
142
+ @formatted_ingredients = input_options["formatted"]["ingredients"]
143
+ @formatted_directions = input_options["formatted"]["directions"]
144
+ @formatted_prep_time = input_options["formatted"]["prep_time"]
145
+ end
146
+
147
+ def self.convert_hashs(recipe_hashs)
148
+ collection = []
149
+
150
+ recipe_hashs.each do |recipe_hash|
151
+ collection << Recipe.new(recipe_hash)
152
+ end
153
+
154
+ collection
155
+ end
156
+ end
157
+
158
+ class Frontend
159
+ include RecipesController
160
+ include RecipesViews
161
+
162
+ def run
163
+ while true
164
+ system "clear"
165
+
166
+ puts "Welcome to my Cookbook App"
167
+ puts "make a selection"
168
+ puts " [1] See all recipes"
169
+ puts " [1.1] Search all recipes"
170
+ puts " [1.2] Sort recipes by chef"
171
+ puts " [1.3] Sort recipes by prep time"
172
+ puts " [2] See one recipe"
173
+ puts " [3] Create a new recipe"
174
+ puts " [4] Update a recipe"
175
+ puts " [5] Destroy a recipe"
176
+ puts ""
177
+ puts " [signup] Signup (create a user)"
178
+ puts " [login] Login (create a JSON web token)"
179
+ puts " [logout] Logout (erase the JSON web token)"
180
+ puts " [q] Quit"
181
+
182
+ input_option = gets.chomp
183
+
184
+ if input_option == "1"
185
+ recipes_index_action
186
+
187
+ elsif input_option == "1.1"
188
+ print "Enter a search term: "
189
+ search_term = gets.chomp
190
+
191
+ response = Unirest.get("https://enigmatic-shore-27070.herokuapp.com/recipes?search=#{search_term}")
192
+ products = response.body
193
+ puts JSON.pretty_generate(products)
194
+
195
+ elsif input_option == "1.2"
196
+ response = Unirest.get("https://enigmatic-shore-27070.herokuapp.com/recipes?sort=chef")
197
+ products = response.body
198
+ puts JSON.pretty_generate(products)
199
+ elsif input_option == "1.3"
200
+ response = Unirest.get("https://enigmatic-shore-27070.herokuapp.com/recipes?sort=prep_time")
201
+ products = response.body
202
+ puts JSON.pretty_generate(products)
203
+ elsif input_option == "2"
204
+ recipes_show_action
205
+ elsif input_option == "3"
206
+ recipes_create_action
207
+ elsif input_option == "4"
208
+ recipes_update_action
209
+ elsif input_option == "5"
210
+ recipes_destroy_action
211
+ elsif input_option == "signup"
212
+ puts "Signup for a new account"
213
+ puts
214
+ client_params = {}
215
+
216
+ print "Name: "
217
+ client_params[:name] = gets.chomp
218
+
219
+ print "Email: "
220
+ client_params[:email] = gets.chomp
221
+
222
+ print "Password: "
223
+ client_params[:password] = gets.chomp
224
+
225
+ print "Password Confirmation: "
226
+ client_params[:password_confirmation] = gets.chomp
227
+
228
+ json_data = post_request("/users", client_params)
229
+ puts JSON.pretty_generate(json_data)
230
+ elsif input_option == "login"
231
+ puts "Login"
232
+ puts
233
+ print "Email: "
234
+ input_email = gets.chomp
235
+
236
+ print "Password: "
237
+ input_password = gets.chomp
238
+
239
+ response = Unirest.post(
240
+ "https://enigmatic-shore-27070.herokuapp.com/user_token",
241
+ parameters: {
242
+ auth: {
243
+ email: input_email,
244
+ password: input_password
245
+ }
246
+ }
247
+ )
248
+ puts JSON.pretty_generate(response.body)
249
+ jwt = response.body["jwt"]
250
+ Unirest.default_header("Authorization", "Bearer #{jwt}")
251
+ elsif input_option == "logout"
252
+ jwt = ""
253
+ Unirest.clear_default_headers
254
+ elsif input_option == "q"
255
+ puts "Thank you for using Josh's Cookbook"
256
+ exit
257
+ end
258
+ gets.chomp
259
+ end
260
+ end
261
+
262
+ private
263
+ def get_request(url, client_params={})
264
+ Unirest.get("https://enigmatic-shore-27070.herokuapp.com#{url}", parameters: client_params).body
265
+ end
266
+
267
+ def post_request(url, client_params={})
268
+ Unirest.post("https://enigmatic-shore-27070.herokuapp.com#{url}", parameters: client_params).body
269
+ end
270
+
271
+ def patch_request(url, client_params={})
272
+ Unirest.patch("https://enigmatic-shore-27070.herokuapp.com#{url}", parameters: client_params).body
273
+ end
274
+
275
+ def delete_request(url, client_params={})
276
+ Unirest.delete("https://enigmatic-shore-27070.herokuapp.com#{url}", parameters: client_params).body
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,3 @@
1
+ module ButtermilkBiscuits
2
+ VERSION = "0.1.2"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buttermilk_biscuits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JackMarx
@@ -56,26 +56,36 @@ dependencies:
56
56
  name: unirest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.1.2
62
62
  type: :runtime
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: 1.1.2
69
69
  description: I have struggled long and hard to get access to my recipes from the terminal,
70
70
  this is the tool that granted my wishes.
71
71
  email:
72
72
  - seriousfools@gmail.com
73
- executables:
74
- - cook_me
73
+ executables: []
75
74
  extensions: []
76
75
  extra_rdoc_files: []
77
76
  files:
78
- - bin/cook_me
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - buttermilk_biscuits.gemspec
87
+ - lib/buttermilk_biscuits.rb
88
+ - lib/buttermilk_biscuits/version.rb
79
89
  homepage: https://github.com/StraightOuttaConstant/buttermilk_biscuits
80
90
  licenses:
81
91
  - MIT
data/bin/cook_me DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'buttermilk_biscuits'
4
-
5
- ButtermilkBiscuits::Frontend.new.run