Module: PostyCli::Util

Defined in:
lib/posty_cli/util.rb,
lib/posty_cli/util/user.rb,
lib/posty_cli/util/alias.rb,
lib/posty_cli/util/domain.rb

Defined Under Namespace

Classes: Alias, Domain, User

Class Method Summary collapse

Class Method Details

.build_uri(name) ⇒ Object



16
17
18
# File 'lib/posty_cli/util.rb', line 16

def self.build_uri(name)
	URI.join(PostyCli::Config[:posty_api_url], PostyCli::Config[:posty_api_version] + "/", name).to_s
end

.check_name(name) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/posty_cli/util.rb', line 20

def self.check_name(name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3)
		return true
	else 
		return false
	end
end

.check_response_code(response, mes) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/posty_cli/util.rb', line 35

def self.check_response_code(response, mes)
	

	if response =~ /401/
		## Unauthorized 
		puts "User token was not present or is not valid."
		exit 1 
	elsif response =~ /400/
		##name already taken
		mes = JSON.parse(mes)
		mes["error"].each do |key, value|
			value.each do |value|
				puts key + ": " + value
			end
		end
	elsif response =~ /403/ 
		## Forbidden 
		puts "You are not authorized to complete this action"
		exit 1 
	elsif response =~ /404/ 
		## Not found 
		
		if(mes =~ /\{/)
			mes2 = JSON.parse(mes)
			puts "an error occurred: " + mes2["error"]
			exit 1
		else
			puts "URL " + mes 
			exit 1
		end


	elsif response =~ /405/ 
		## Method not allowed 
		puts "This request is not supported."
		exit 1 
	elsif response =~ /409/
		## Conflicting resource  
		puts "A conflicting resource already exists."
		exit 1 
	elsif response =~ /500/
		## Server error
		puts "Oops.  Something went wrong. Please try again."
	end
end

.check_url(domain) ⇒ Object



29
30
31
# File 'lib/posty_cli/util.rb', line 29

def self.check_url(domain)
	puts "You have to enter a valid URL. You should read http://de.wikipedia.org/wiki/Uniform_Resource_Locator. Because #{domain} cant be a valid domain name"
end