creative_cocktails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2aeb01df8dd2104438485d09d2fcb46ad031f8e4
4
+ data.tar.gz: 3df6bf97c9e0ba7e51841279d1dc6187898d720d
5
+ SHA512:
6
+ metadata.gz: 000e1f92ae1f721710b50a805b01f82b7e8385b6ac398357034b356c554346197a597a32b9ceb0fcd0d9ffad4ee5cb41faf469175147951c54e4fb9ca8ace29d
7
+ data.tar.gz: 7b7c3b9e26702d2f482ffbb48a2955285c278b5b27786129d3a7464dfc96fac460be282d487e9fd3f6dcb7160ca22bec44bfd5e378a05d3cc93bb67fa83f6a9c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
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 creative_cocktails.gemspec
6
+ gemspec
7
+ gem 'require_all'
8
+ gem 'httparty'
9
+
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ creative_cocktails (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ httparty (0.16.3)
10
+ mime-types (~> 3.0)
11
+ multi_xml (>= 0.5.2)
12
+ mime-types (3.2.2)
13
+ mime-types-data (~> 3.2015)
14
+ mime-types-data (3.2018.0812)
15
+ multi_xml (0.6.0)
16
+ rake (10.4.2)
17
+ require_all (2.0.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.16)
24
+ creative_cocktails!
25
+ httparty
26
+ rake (~> 10.0)
27
+ require_all
28
+
29
+ BUNDLED WITH
30
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 ebuchheim
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,39 @@
1
+ # CreativeCocktails
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/creative_cocktails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ This gem provides inspiration for new cocktails. It also allows you to find cocktail recipes by name or ingredient.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'creative_cocktails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install creative_cocktails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/creative_cocktails.
36
+
37
+ ## License
38
+
39
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "creative_cocktails"
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__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../config/environment'
4
+
5
+ CLI.new
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,4 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require_all 'lib'
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "creative_cocktails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "creative_cocktails"
8
+ spec.version = CreativeCocktails::VERSION
9
+ spec.authors = ["ebuchheim"]
10
+ spec.email = ["emma.buchheim@gmail.com"]
11
+
12
+ spec.summary = "TheCocktailDB scraper CLI"
13
+ spec.description = "A CLI that scrapes TheCocktailDB for drink ingredients and inspirations."
14
+ spec.homepage = "https://github.com/ebuchheim/creative_cocktails"
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"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
data/lib/api.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'httparty'
2
+
3
+ class APIService
4
+ def self.fetch_random
5
+ response = HTTParty.get('https://www.thecocktaildb.com/api/json/v1/1/random.php')
6
+ response.parsed_response["drinks"][0]
7
+ end
8
+
9
+ def self.search_by_name(name)
10
+ link = "https://www.thecocktaildb.com/api/json/v1/1/search.php?s=" + name
11
+ response = HTTParty.get(link)
12
+ response.parsed_response["drinks"]
13
+ end
14
+
15
+ def self.search_by_ingredient(ingredient)
16
+ link = "https://www.thecocktaildb.com/api/json/v1/1/filter.php?i=" + ingredient
17
+ response = HTTParty.get(link)
18
+ if response.parsed_response != nil
19
+ response.parsed_response["drinks"]
20
+ else
21
+ nil
22
+ end
23
+ end
24
+
25
+ def self.search_by_id(drink_id)
26
+ link = "https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=" + drink_id
27
+ response = HTTParty.get(link)
28
+ response.parsed_response["drinks"][0]
29
+ end
30
+ end
data/lib/cli.rb ADDED
@@ -0,0 +1,150 @@
1
+ class CLI
2
+ def initialize
3
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
4
+ puts "Welcome to Creative Cocktails!"
5
+ puts "What would you like to do?"
6
+ puts " 1. Search for a recipe by name"
7
+ puts " 2. Browse drinks by ingredient"
8
+ puts " 3. Surprise me: random inspiration!"
9
+ user_input = gets.chomp
10
+ if user_input == "1"
11
+ drinks_by_name
12
+ elsif user_input == "2"
13
+ drinks_by_ingredient
14
+ elsif user_input == "3"
15
+ random_drink
16
+ else
17
+ puts "Sorry, I didn't get that! Please choose an option by entering 1, 2, or 3."
18
+ CLI.new
19
+ end
20
+ end
21
+
22
+ def drinks_by_name
23
+ puts "What drink did you have in mind?"
24
+ user_input = gets.chomp
25
+ search_results = APIService.search_by_name(user_input)
26
+ if search_results != nil
27
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
28
+ puts "I found these recipes for #{user_input}:"
29
+ counter = 1
30
+ drink_results = search_results.map do |result|
31
+ drink = Drink.new(result)
32
+ puts " #{counter}. #{drink.name}"
33
+ counter += 1
34
+ drink
35
+ end
36
+ drink_display(drink_results)
37
+ else
38
+ puts "Sorry, I don't have any #{user_input} drinks."
39
+ puts "Want to search again? Please enter (y)es or (n)o."
40
+ user_answer = gets.chomp
41
+ if user_answer == "n"
42
+ main_or_quit
43
+ elsif user_answer == "y"
44
+ drinks_by_name
45
+ end
46
+ end
47
+ end
48
+
49
+ def drink_display(drink_results)
50
+ puts "Select a drink to learn more about it!"
51
+ puts "Or enter 0 to return to the main menu."
52
+ user_selection = gets.chomp
53
+ total = drink_results.count
54
+ user_selection = user_selection.to_i
55
+ if user_selection >= 1 && user_selection <= total
56
+ index = user_selection - 1
57
+ drink_to_show = drink_results[index]
58
+ drink = APIService.search_by_id(drink_to_show.drinkId)
59
+ drink = Drink.new(drink)
60
+ drink.display
61
+ back_main_or_quit(drink_results)
62
+ elsif user_selection == 0
63
+ CLI.new
64
+ else
65
+ puts "Sorry, please choose a number from the list above."
66
+ end
67
+ end
68
+
69
+ def drinks_by_ingredient
70
+ puts "What ingredient did you have in mind?"
71
+ user_input = gets.chomp
72
+ search_results = APIService.search_by_ingredient(user_input)
73
+ if search_results != nil
74
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
75
+ puts "These drinks all include #{user_input}."
76
+ counter = 1
77
+ drink_results = search_results.map do |result|
78
+ drink = Drink.new(result)
79
+ puts " #{counter}. #{drink.name}"
80
+ counter += 1
81
+ drink
82
+ end
83
+ drink_display(drink_results)
84
+ else
85
+ puts "Sorry, I don't have any #{user_input} drinks."
86
+ puts "Want to search again? Please enter (y)es or (n)o."
87
+ user_answer = gets.chomp
88
+ if user_answer == "n"
89
+ main_or_quit
90
+ elsif user_answer == "y"
91
+ drinks_by_ingredient
92
+ end
93
+ end
94
+ end
95
+
96
+ def random_drink
97
+ drink = APIService.fetch_random
98
+ selection = Drink.new(drink)
99
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
100
+ puts "Let me tell you about #{selection.name}!"
101
+ selection.display
102
+ puts "If you'd like to see another random recipe, press 1!"
103
+ puts "Enter 0 to return to the main menu."
104
+ puts "Enter q to quit the program."
105
+ user_input = gets.chomp
106
+ if user_input == "1"
107
+ random_drink
108
+ elsif user_input == "0"
109
+ CLI.new
110
+ elsif user_input == "q"
111
+ puts "Good bye!"
112
+ end
113
+ end
114
+
115
+ def back_main_or_quit(drink_results)
116
+ puts "Enter b to go back to the previous list."
117
+ puts "Enter 0 to return to the main menu."
118
+ puts "Enter q to quit the program."
119
+ user_input = gets.chomp
120
+ if user_input == "0"
121
+ CLI.new
122
+ elsif user_input == "b"
123
+ counter = 1
124
+ drink_results.each do |drink|
125
+ puts " #{counter}. #{drink.name}"
126
+ counter += 1
127
+ end
128
+ drink_display(drink_results)
129
+ elsif user_input == "q"
130
+ puts "Good bye!"
131
+ else
132
+ puts "Sorry, I didn't get that."
133
+ back_main_or_quit(drink_results)
134
+ end
135
+ end
136
+
137
+ def main_or_quit
138
+ puts "Enter 0 to return to the main menu."
139
+ puts "Enter q to quit the program."
140
+ user_input = gets.chomp
141
+ if user_input == "0"
142
+ CLI.new
143
+ elsif user_input == "q"
144
+ puts "Good bye!"
145
+ else
146
+ puts "Sorry, I didn't get that."
147
+ main_or_quit
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ module CreativeCocktails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "creative_cocktails/version"
2
+
3
+ module CreativeCocktails
4
+ # Your code goes here...
5
+ end
data/lib/drink.rb ADDED
@@ -0,0 +1,92 @@
1
+ class Drink
2
+ attr_reader :name, :instructions, :glass, :category, :ingredient1, :measure1,\
3
+ :ingredient2, :measure2, :ingredient3, :measure3, :ingredient4, :measure4,\
4
+ :ingredient5, :measure5, :ingredient6, :measure6, :ingredient7, :measure7,\
5
+ :ingredient8, :measure8, :ingredient9, :measure9, :ingredient10, :measure10,\
6
+ :ingredient11, :measure11, :ingredient12, :measure12, :ingredient13, :measure13,\
7
+ :ingredient14, :measure14, :ingredient15, :measure15, :drinkId
8
+
9
+ def initialize(drink)
10
+ @name = drink["strDrink"]
11
+ @drinkId = drink["idDrink"]
12
+ @instructions = drink["strInstructions"]
13
+ @glass = drink["strGlass"]
14
+ @category = drink["strIBA"]
15
+ @ingredient1 = drink["strIngredient1"]
16
+ @measure1 = drink["strMeasure1"]
17
+ @ingredient2 = drink["strIngredient2"]
18
+ @measure2 = drink["strMeasure2"]
19
+ @ingredient3 = drink["strIngredient3"]
20
+ @measure3 = drink["strMeasure3"]
21
+ @ingredient4 = drink["strIngredient4"]
22
+ @measure4 = drink["strMeasure4"]
23
+ @ingredient5 = drink["strIngredient5"]
24
+ @measure5 = drink["strMeasure5"]
25
+ @ingredient6 = drink["strIngredient6"]
26
+ @measure6 = drink["strMeasure6"]
27
+ @ingredient7 = drink["strIngredient7"]
28
+ @measure7 = drink["strMeasure7"]
29
+ @ingredient8 = drink["strIngredient8"]
30
+ @measure8 = drink["strMeasure8"]
31
+ @ingredient9 = drink["strIngredient9"]
32
+ @measure9 = drink["strMeasure9"]
33
+ @ingredient10 = drink["strIngredient10"]
34
+ @measure10 = drink["strMeasure10"]
35
+ @ingredient11 = drink["strIngredient11"]
36
+ @measure11 = drink["strMeasure11"]
37
+ @ingredient12 = drink["strIngredient12"]
38
+ @measure12 = drink["strMeasure12"]
39
+ @ingredient13 = drink["strIngredient13"]
40
+ @measure13 = drink["strMeasure13"]
41
+ @ingredient14 = drink["strIngredient14"]
42
+ @measure14 = drink["strMeasure14"]
43
+ @ingredient15 = drink["strIngredient15"]
44
+ @measure15 = drink["strMeasure15"]
45
+ end
46
+
47
+ def display
48
+ puts "===================================="
49
+ puts "NAME: #{@name}"
50
+ puts "GLASS: #{@glass}"
51
+ if @category.to_s.length > 1
52
+ puts "CATEGORY: #{@category}"
53
+ end
54
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
55
+ puts "Want to enjoy this marvelous creation?"
56
+ puts "First, gather these ingredients:"
57
+ display_ingredients
58
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
59
+ puts "Then follow these instructions:"
60
+ puts "#{@instructions}"
61
+ puts "===================================="
62
+ end
63
+
64
+ def display_ingredients
65
+ ingredients = {
66
+ @ingredient1 => @measure1,
67
+ @ingredient2 => @measure2,
68
+ @ingredient3 => @measure3,
69
+ @ingredient4 => @measure4,
70
+ @ingredient5 => @measure5,
71
+ @ingredient6 => @measure6,
72
+ @ingredient7 => @measure7,
73
+ @ingredient8 => @measure8,
74
+ @ingredient9 => @measure9,
75
+ @ingredient10 => @measure10,
76
+ @ingredient11 => @measure11,
77
+ @ingredient12 => @measure12,
78
+ @ingredient13 => @measure13,
79
+ @ingredient14 => @measure14,
80
+ @ingredient15 => @measure15
81
+ }
82
+ ingredients.each do |ingredient, measure|
83
+ if ingredient != "" && !!ingredient
84
+ if measure != "" && measure
85
+ puts " - #{measure.strip} #{ingredient}"
86
+ else
87
+ puts " - #{ingredient.strip}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: creative_cocktails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ebuchheim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A CLI that scrapes TheCocktailDB for drink ingredients and inspirations.
42
+ email:
43
+ - emma.buchheim@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/creative_cocktails
56
+ - bin/setup
57
+ - config/environment.rb
58
+ - creative_cocktails.gemspec
59
+ - lib/api.rb
60
+ - lib/cli.rb
61
+ - lib/creative_cocktails.rb
62
+ - lib/creative_cocktails/version.rb
63
+ - lib/drink.rb
64
+ homepage: https://github.com/ebuchheim/creative_cocktails
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ allowed_push_host: https://rubygems.org
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.8
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: TheCocktailDB scraper CLI
89
+ test_files: []