Sha256: a15da44fdc0bf8d6526f2bfb357502fbd5b54ce39ef201c0ef403cb42522b353

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module LearnWeb
  class Client
    module ValidateRepo
      class Slug
        attr_accessor :data, :repo_slug, :lab, :lesson_id
        attr_reader   :response

        include AttributePopulatable

        def initialize(response)
          @response = response

          parse!
        end

        private

        def parse!
          case response.status
          when 200
            self.data = Oj.load(response.body, symbol_keys: true)
            populate_attributes!
          when 401
            puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
            exit
          when 422
            begin
              self.data = Oj.load(response.body, symbol_keys: true)
              if data[:message].match(/Cannot find lesson/)
                puts "Hmm...#{data[:message]}. Please check your input and try again."
                exit
              else
                puts "Sorry, something went wrong. Please try again."
                exit
              end
            rescue
              puts "Sorry, something went wrong. Please try again."
              exit
            end
          when 500
            puts "Sorry, something went wrong. Please try again."
            exit
          else
            puts "Sorry, something went wrong. Please try again."
            exit
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
learn-web-1.0.2 lib/learn_web/client/validate_repo/slug.rb
learn-web-1.0.1 lib/learn_web/client/validate_repo/slug.rb
learn-web-1.0.0 lib/learn_web/client/validate_repo/slug.rb