package_cloud 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/package_cloud/config_file.rb +11 -6
- data/lib/package_cloud/version.rb +1 -1
- metadata +2 -2
@@ -1,20 +1,22 @@
|
|
1
1
|
require "highline/import"
|
2
2
|
require "json"
|
3
|
+
require "uri"
|
4
|
+
require "cgi"
|
3
5
|
|
4
6
|
module PackageCloud
|
5
7
|
class ConfigFile
|
6
8
|
attr_reader :token
|
7
9
|
|
8
|
-
def initialize(filename = "~/.packagecloud", url = "packagecloud.io")
|
10
|
+
def initialize(filename = "~/.packagecloud", url = "https://packagecloud.io")
|
9
11
|
@filename = File.expand_path(filename)
|
10
|
-
@url = url
|
12
|
+
@url = URI(url)
|
11
13
|
end
|
12
14
|
|
13
15
|
def read_or_create
|
14
16
|
if File.exist?(@filename)
|
15
17
|
attrs = JSON.parse(File.read(@filename))
|
16
18
|
@token = attrs["token"] if attrs.has_key?("token")
|
17
|
-
@url = attrs["url"] if attrs.has_key?("url")
|
19
|
+
@url = URI(attrs["url"]) if attrs.has_key?("url")
|
18
20
|
else
|
19
21
|
puts "No config file exists at #{@filename}. Login to create one."
|
20
22
|
|
@@ -24,11 +26,14 @@ module PackageCloud
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def url
|
27
|
-
@url ||= "packagecloud.io"
|
29
|
+
@url ||= URI("https://packagecloud.io")
|
28
30
|
end
|
29
31
|
|
30
32
|
def base_url(username = token, password = "")
|
31
|
-
|
33
|
+
u = url.dup
|
34
|
+
u.user = CGI.escape(username)
|
35
|
+
u.password = CGI.escape(password)
|
36
|
+
u.to_s
|
32
37
|
end
|
33
38
|
|
34
39
|
private
|
@@ -46,7 +51,7 @@ module PackageCloud
|
|
46
51
|
|
47
52
|
def write
|
48
53
|
print "Got your token. Writing a config file to #{@filename}... "
|
49
|
-
attrs = {url:
|
54
|
+
attrs = {url: url.to_s, token: @token}
|
50
55
|
File.open(@filename, "w", 0600) { |f| f << JSON.dump(attrs); f << "\r\n" }
|
51
56
|
puts "success!"
|
52
57
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: package_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Golick
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2014-02-
|
13
|
+
date: 2014-02-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|