Class: ShopifyAppReviews::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_app_reviews/cli.rb

Instance Method Summary collapse

Instance Method Details

#add_metadata_to_app(app) ⇒ Object



149
150
151
# File 'lib/shopify_app_reviews/cli.rb', line 149

def (app)
   = AppReviewScraper.(app)
end

#add_reviews_to_app(app) ⇒ Object



143
144
145
146
147
# File 'lib/shopify_app_reviews/cli.rb', line 143

def add_reviews_to_app(app)
  review_array = AppReviewScraper.scrape_app_reviews(app)
  AppReview.create_from_collection(review_array, app)
  app.app_reviews << review_array
end

#app_details_table(app) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/shopify_app_reviews/cli.rb', line 113

def app_details_table(app)
  (app)
  puts "Found ".colorize(:green) + "#{app.name.colorize(:white)}" + " in the ".colorize(:green) + "#{app.category.colorize(:white)}" + " category. ".colorize(:green)
  print "#{app.description.colorize(:white)}" + " - ".colorize(:green)
  puts "#{app.overall_rating.colorize(:white)}"
  puts "App URL: ".colorize(:green) + "#{app.url.colorize(:white)}"
  puts "Developer: ".colorize(:green) + "#{app.developer_name.colorize(:white)}" + " (#{app.developer_url})".colorize(:green)
  puts "Developer Contact: ".colorize(:green) + "#{app.developer_contact}".colorize(:white)
  puts "The overall sentiment for".colorize(:green) + " #{app.name.colorize(:white)} " + "is ".colorize(:green) + "#{app.overall_sentiment}"
  trending_sentiment(app) unless app.app_reviews.empty?
end

#display_app_details(input) ⇒ Object

if an app is not found, return falsey



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/shopify_app_reviews/cli.rb', line 64

def display_app_details(input) # if an app is not found, return falsey
  unless input == "exit cli"
    requested_app = ShopifyApp.find_by_url(input)
    requested_app = ShopifyApp.find_by_name(input) if requested_app.nil?
    requested_app.nil? ? false : app_details_table(requested_app)

    unless false
      sub_input = nil
      while !sub_input != "new app"
        hr
        if requested_app.nil?
          puts "Doesn't look like an app exists for that. Did you spell your request properly?".colorize(:red)
          hr
          get_input
        else
          print_sub_instructions(requested_app)
        end
        sub_input = gets.chomp.downcase
        if sub_input == "latest reviews"
          display_app_reviews(requested_app)
        end
        get_input if sub_input == "new app"
        if sub_input == "exit" || sub_input == "quit" || sub_input == "exit cli"
          goodbye
          exit
        end
        app_details_table(requested_app) if sub_input == "app details"
        overall_sentiment(requested_app) if sub_input == "overall sentiment"
        unless requested_app.app_reviews.empty?
          if sub_input == "trending sentiment"
            hr
            trending_sentiment(requested_app)
          end
        end

      end
    end
  end
end

#display_app_reviews(app) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/shopify_app_reviews/cli.rb', line 125

def display_app_reviews(app)
  add_reviews_to_app(app)
  total_reviews = app.total_review_count
  puts "#{app.name}'s 10 Latest Reviews:".colorize(:light_green)
  hr
  app.app_reviews.each_with_index do |review, index|
    puts "##{(index + 1)}. ".colorize(:yellow) + "#{review.title.split.map(&:capitalize).join(' ').colorize(:green)} - #{review.rating}".colorize(:green)
    puts "Reviewed on #{review.date}".colorize(:green)
    puts "#{review.body}".colorize(:white)
    hr unless review == app.app_reviews.last
  end
end

#get_inputObject



55
56
57
58
59
60
61
62
# File 'lib/shopify_app_reviews/cli.rb', line 55

def get_input
  input = nil
  while input != "exit cli"
    print_instructions
    input = gets.chomp.downcase
    display_app_details(input) ? display_app_details(input) : puts("Doesn't look like an app exists for that. Did you spell your request properly?").colorize(:red) unless input == "exit cli"
  end
end

#goodbyeObject



153
154
155
# File 'lib/shopify_app_reviews/cli.rb', line 153

def goodbye
  puts "Closing CLI."
end

#hrObject



24
25
26
27
# File 'lib/shopify_app_reviews/cli.rb', line 24

def hr
  80.times {print "-".colorize(:cyan)}
  puts "-".colorize(:cyan)
end

#library_updatedObject



29
30
31
32
33
34
35
# File 'lib/shopify_app_reviews/cli.rb', line 29

def library_updated
  now = Time.now.asctime
  checkmark = "\u2713"
  puts checkmark.encode('utf-8').colorize(:light_green)
  puts "Library updated as of #{now}".colorize(:green)
  hr
end

#overall_sentiment(app) ⇒ Object



104
105
106
107
# File 'lib/shopify_app_reviews/cli.rb', line 104

def overall_sentiment(app)
  hr
  puts "The overall sentiment for".colorize(:green) + " #{app.name.colorize(:white)} " + "is ".colorize(:green) + "#{app.overall_sentiment}"
end


37
38
39
40
41
# File 'lib/shopify_app_reviews/cli.rb', line 37

def print_instructions
  puts "You can use 'exit cli' to leave at any time.".colorize(:yellow)
  puts "Search for a Shopify app by name or URL to access its information.".colorize(:green)
  print "Enter the name or URL of a Shopify app: ".colorize(:green)
end


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shopify_app_reviews/cli.rb', line 43

def print_sub_instructions(requested_app)
  puts "Use 'latest reviews' to see #{requested_app.name}'s 10 latest reviews.".colorize(:yellow)
  puts "Use 'app details' to review #{requested_app.name}'s details.".colorize(:yellow)
  puts "Use 'overall sentiment' to see how people feel about #{requested_app.name} in general.".colorize(:yellow)
  unless requested_app.app_reviews.empty?
    puts "Use 'trending sentiment' to see how people feel about #{requested_app.name} lately.".colorize(:yellow)
  end
  puts "Use 'new app' to return to the previous menu.".colorize(:yellow)
  puts "You can use 'exit cli' to leave at any time.".colorize(:yellow)
  print "What would you like to do? ".colorize(:green)
end

#runObject



10
11
12
13
14
15
16
# File 'lib/shopify_app_reviews/cli.rb', line 10

def run
  welcome
  scrape_and_create_apps
  library_updated
  get_input
  goodbye
end

#scrape_and_create_appsObject



138
139
140
141
# File 'lib/shopify_app_reviews/cli.rb', line 138

def scrape_and_create_apps
  app_array = AppListScraper.scrape_shopify_apps
  ShopifyApp.create_from_collection(app_array)
end


109
110
111
# File 'lib/shopify_app_reviews/cli.rb', line 109

def trending_sentiment(app)
  puts "The trending sentiment for".colorize(:green) + " #{app.name.colorize(:white)} " + "is ".colorize(:green) + "#{app.trending_sentiment}"
end

#welcomeObject



18
19
20
21
22
# File 'lib/shopify_app_reviews/cli.rb', line 18

def welcome
  hr
  print "Welcome to Shopify App Reviews CLI.".colorize(:light_green)
  print " The Shopify App Library is updating. One moment...".colorize(:green)
end