Class: ErrorMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita_org/error_message.rb

Instance Method Summary collapse

Constructor Details

#initializeErrorMessage

Returns a new instance of ErrorMessage.



5
6
# File 'lib/qiita_org/error_message.rb', line 5

def initialize()
end

Instance Method Details

#access_token_error(access_token) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/qiita_org/error_message.rb', line 8

def access_token_error(access_token)
  if access_token == ""
    puts "Please setting ACCESS_TOKEN.".red
    puts "Hint: qiita config global access_token 'your access_token'.".red
    puts "Hint: qiita config local access_token 'your access_token'.".red
    exit
  end
end

#config_set_error(conf_dir) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/qiita_org/error_message.rb', line 58

def config_set_error(conf_dir)
  conf_path = File.join(conf_dir, ".qiita.conf")
  conf = JSON.load(File.read(conf_path))
  check = true

  if conf["name"] == ""
    puts "Please set your name in config.".red
    puts "Hint: qiita config global name 'YOUR NAME'.".red
    puts "Hint: qiita config local name 'YOUR NAME'.".red
#      system "rm template.org"
    check = false
  end

  if conf["email"] == ""
    puts "Please set your email in config.".red
    puts "Hint: qiita config global email '[email protected]'.".red
    puts "Hint: qiita config local name '[email protected]'.".red
    check = false
  end
  unless check
    exit
  end
end

#many_tags_error(tags) ⇒ Object



93
94
95
96
97
98
# File 'lib/qiita_org/error_message.rb', line 93

def many_tags_error(tags)
  if tags.count(",") >= 5
    puts "The maximum number of tag is five. Please delete some tags.".red
    exit
  end
end

#md_file_exists?(src, res) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
# File 'lib/qiita_org/error_message.rb', line 82

def md_file_exists?(src, res)
  unless File.exists?(src.gsub(".org", ".md"))
    puts "Can not convert org doc to markdown.".red
    puts 'Please confirm emacs version above 26.'.red
    puts "Next, check links in the org doc, as converting in emacs by 'ctrl+c, ctrl+e, h, o'.".red
    exit
  else
    p res
  end
end

#qiita_access_error(e) ⇒ Object



26
27
28
29
# File 'lib/qiita_org/error_message.rb', line 26

def qiita_access_error(e)
  puts "#{$!}".red
  exit
end

#qiita_post_error(response, file) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/qiita_org/error_message.rb', line 31

def qiita_post_error(response, file)
  message = response.message
  if message != "Created"
    if message != "OK"
      if message == "Unauthorized"
        puts "#{message}".red
        puts "Please check your access_token.".red
        system "rm #{file}"
        exit
      elsif message == "Forbidden"
        puts "#{message}".red
        puts "You are not authorized to access this page. please check qiita_id.".red
        system "rm #{file}"
        exit
      elsif message == "Not Found"
        puts "#{message}".red
        system "rm #{file}"
        exit
      else
        puts "#{message}".red
        system "rm #{file}"
        exit
      end
    end
  end
end

#teams_url_error(teams_url) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/qiita_org/error_message.rb', line 17

def teams_url_error(teams_url)
  if teams_url == ""
    puts "Please setting teams_url.".red
    puts "Hint: qiita config global teams_url 'https://foge.qiita.com/'.".red
    puts "Hint: qiita config local teams_url 'https://foge.qiita.com/'.".red
    exit
  end
end