cli-scripts-jakewmeyer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71bbe856306b81efb42d6a9eaf66bce2fe50349a
4
- data.tar.gz: 113206333cef3311c415fb02158beb2cae56c8c1
3
+ metadata.gz: 25dce8292b9c0b9b44be21a17b56778c040582ea
4
+ data.tar.gz: d395049fb53c6ee8ad674a04d15b62e6cbc86e28
5
5
  SHA512:
6
- metadata.gz: 5009e3a391f81f82d83ab9941fa0e9ad9ef606f6af27af01ec3c8b3d08ffa6b9ab32f3bf766164b79d38d88d77b65113578cd01e191693c2903ab5a9b768e70d
7
- data.tar.gz: bfcacc44215598d10b2499975718b6d59f26f171042aa6b7abb6af521880a4092491c6cb3a2a0dcb19805007a6cdae66f78ec3bd72a1527d441a2b720277ca50
6
+ metadata.gz: af8fbe39dcc61703a2044bdcf412f1b6f0c2d1d8bc482ac58908c7d8827fbf1e36fba50163e5573265acee627678fb8a9c966a118acd6848cf07b7b97fd205e3
7
+ data.tar.gz: 023bdbb35adc0053f63035f603931945d50961ea1d7b9d4bac7d4df7be8623b8b12c750a64f5b69e850d34f99f64c6681632705b0cc440a7301f10c1d8d42296
data/.DS_Store ADDED
Binary file
data/bin/movie ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ # CLI app that searched movies and returns info
3
+
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ # Word wrapping method
8
+ def wrap(s, width = 78)
9
+ s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n| ")
10
+ end
11
+
12
+ def movie
13
+ # This is a live API key, don't absue it
14
+ api_key = '946f500a'
15
+
16
+ puts
17
+ print 'Movie => '
18
+ movie_name = gets.chomp
19
+
20
+ # Program escape statements
21
+ if movie_name == 'quit' || movie_name == 'exit'
22
+ puts
23
+ exit(1)
24
+ else
25
+ url = "http://www.omdbapi.com/?t=#{movie_name}&apikey=#{api_key}"
26
+ response = RestClient.get(url)
27
+ info = JSON.parse(response)
28
+ end
29
+
30
+ # Exception for invalid response
31
+ if info['Response'] == 'False'
32
+ puts
33
+ puts 'No Movie Found'
34
+ puts
35
+ exit(1)
36
+ else
37
+ # Rescue if no tomato score
38
+ # Word wrap added to plot and actors
39
+ begin
40
+ title = info['Title']
41
+ year = info['Year']
42
+ score = info['Ratings'][1]['Value']
43
+ rescue
44
+ score = 'No Score Found'
45
+ end
46
+
47
+ rated = info['Rated']
48
+ genre = info['Genre']
49
+ director = info['Director']
50
+ actors = wrap(info['Actors'], 48)
51
+ plot_unformatted = info['Plot']
52
+ plot = wrap(plot_unformatted, 48)
53
+
54
+ puts
55
+ puts '=================================================='
56
+ puts "| Title: #{title}"
57
+ puts "| Year: #{year}"
58
+ puts "| Tomato: #{score}"
59
+ puts "| Rated: #{rated}"
60
+ puts "| Genre: #{genre}"
61
+ puts "| Director: #{director}"
62
+ puts "| Actors: #{actors}"
63
+ puts "| Plot: #{plot}"
64
+ puts '=================================================='
65
+ puts
66
+ end
67
+ end
68
+
69
+ movie
data/bin/stock ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ # CLI app that searches stock info by symbol.
3
+
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ def stock_search
8
+ puts
9
+ print 'Stock => '
10
+ symbol = gets.chomp
11
+
12
+ if symbol == 'quit' || symbol == 'exit'
13
+ exit(1)
14
+ else
15
+ begin
16
+ # Takes user input and generates ticker symbol.
17
+ url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{symbol}&region=1&lang=en%22"
18
+ response = RestClient.get(url)
19
+ parsed = JSON.parse(response)
20
+ parsed_symbol = parsed['ResultSet']['Result'][0]['symbol']
21
+ rescue
22
+ puts
23
+ puts 'Invalid Search'
24
+ puts
25
+ exit(1)
26
+ end
27
+
28
+ # Rest API to fetch current JSON data.
29
+ url = "http://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=#{parsed_symbol}&apikey=946DU3BV54DQIGIK"
30
+ response = RestClient.get(url)
31
+ parsed = JSON.parse(response)
32
+
33
+ # Check API response validity.
34
+ if parsed['Realtime Global Securities Quote'].empty?
35
+ puts
36
+ puts 'No Stock Found'
37
+ puts
38
+ exit(1)
39
+ else
40
+ # Assign variables to hash key values.
41
+ parsed_symbol = parsed['Realtime Global Securities Quote']['01. Symbol']
42
+ parsed_price = parsed['Realtime Global Securities Quote']['03. Latest Price']
43
+ parsed_open = parsed['Realtime Global Securities Quote']['04. Open (Current Trading Day)']
44
+ parsed_high = parsed['Realtime Global Securities Quote']['05. High (Current Trading Day)']
45
+ parsed_price_chg = parsed['Realtime Global Securities Quote']['08. Price Change']
46
+ parsed_price_pct = parsed['Realtime Global Securities Quote']['09. Price Change Percentage']
47
+ parsed_volume = parsed['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']
48
+ parsed_exchange = parsed['Realtime Global Securities Quote']['02. Exchange Name']
49
+
50
+ # Output of parsed hash.
51
+ puts
52
+ puts '======================'
53
+ puts "| Symbol: #{parsed_symbol}"
54
+ puts "| Price: $#{parsed_price}"
55
+ puts "| Open: $#{parsed_open}"
56
+ puts "| High: $#{parsed_high}"
57
+ puts "| Price Chg: $#{parsed_price_chg}"
58
+ puts "| Price Chg % : #{parsed_price_pct}"
59
+ puts "| Volume: #{parsed_volume}"
60
+ puts "| Echange: #{parsed_exchange}"
61
+ puts '======================'
62
+ puts
63
+ end
64
+ end
65
+ end
66
+
67
+ stock_search
@@ -1,7 +1,7 @@
1
1
  module Cli
2
2
  module Scripts
3
3
  module Jakewmeyer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-scripts-jakewmeyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Meyer
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".DS_Store"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".travis.yml"
@@ -108,7 +109,9 @@ files:
108
109
  - README.md
109
110
  - Rakefile
110
111
  - bin/console
112
+ - bin/movie
111
113
  - bin/setup
114
+ - bin/stock
112
115
  - cli-scripts-jakewmeyer.gemspec
113
116
  - lib/cli/scripts/jakewmeyer.rb
114
117
  - lib/cli/scripts/jakewmeyer/version.rb