package_cloud 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/package_cloud +4 -0
- data/lib/package_cloud.rb +11 -0
- data/lib/package_cloud/auth.rb +12 -0
- data/lib/package_cloud/cli.rb +22 -0
- data/lib/package_cloud/client.rb +22 -0
- data/lib/package_cloud/config_file.rb +54 -0
- data/lib/package_cloud/object.rb +15 -0
- data/lib/package_cloud/repository.rb +26 -0
- data/lib/package_cloud/version.rb +3 -0
- data/package_cloud.gemspec +29 -0
- metadata +145 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 James Golick
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# PackageCloud
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'package_cloud'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install package_cloud
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/package_cloud
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "package_cloud/version"
|
2
|
+
require "cgi"
|
3
|
+
|
4
|
+
module PackageCloud
|
5
|
+
autoload :Auth, "package_cloud/auth"
|
6
|
+
autoload :CLI, "package_cloud/cli"
|
7
|
+
autoload :Client, "package_cloud/client"
|
8
|
+
autoload :ConfigFile, "package_cloud/config_file"
|
9
|
+
autoload :Object, "package_cloud/object"
|
10
|
+
autoload :Repository, "package_cloud/repository"
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "thor"
|
3
|
+
|
4
|
+
module PackageCloud
|
5
|
+
class CLI < Thor
|
6
|
+
option "config"
|
7
|
+
option "url"
|
8
|
+
desc "push user/repo /path/to/package",
|
9
|
+
"push package to repository"
|
10
|
+
def push(repo, package_file)
|
11
|
+
config = ConfigFile.new(options[:config] || "~/.packagecloud",
|
12
|
+
options[:url] || "packagecloud.io")
|
13
|
+
config.read_or_create
|
14
|
+
client = Client.new(config)
|
15
|
+
print "Trying to find a repository at #{repo}... "
|
16
|
+
repo = client.repository(repo)
|
17
|
+
print "success!\n"
|
18
|
+
print "Pushing package #{package_file}... "
|
19
|
+
repo.create_package(package_file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "json"
|
2
|
+
require "rest_client"
|
3
|
+
|
4
|
+
module PackageCloud
|
5
|
+
class Client
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def repository(name)
|
11
|
+
base_url = @config.base_url
|
12
|
+
user, repo = name.split("/")
|
13
|
+
begin
|
14
|
+
attrs = JSON.parse(RestClient.get("#{base_url}/#{user}/#{repo}.json"))
|
15
|
+
Repository.new(attrs, @config)
|
16
|
+
rescue RestClient::ResourceNotFound => e
|
17
|
+
print "failed!\n".red
|
18
|
+
exit(127)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "highline/import"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module PackageCloud
|
5
|
+
class ConfigFile
|
6
|
+
attr_reader :token
|
7
|
+
|
8
|
+
def initialize(filename = "~/.packagecloud", url = "packagecloud.io")
|
9
|
+
@filename = File.expand_path(filename)
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_or_create
|
14
|
+
if File.exist?(@filename)
|
15
|
+
attrs = JSON.parse(File.read(@filename))
|
16
|
+
@token = attrs["token"] if attrs.has_key?("token")
|
17
|
+
@url = attrs["url"] if attrs.has_key?("url")
|
18
|
+
else
|
19
|
+
puts "No config file exists at #{@filename}. Login to create one."
|
20
|
+
|
21
|
+
@token = login_from_console
|
22
|
+
write
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
@url ||= "packagecloud.io"
|
28
|
+
end
|
29
|
+
|
30
|
+
def base_url(username = token, password = "")
|
31
|
+
"https://#{CGI.escape(username)}:#{CGI.escape(password)}@#{url}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def login_from_console
|
36
|
+
e = ask("Email:")
|
37
|
+
p = ask("Password:") { |q| q.echo = false }
|
38
|
+
|
39
|
+
begin
|
40
|
+
PackageCloud::Auth.get_token(base_url(e, p))
|
41
|
+
rescue RestClient::Unauthorized => e
|
42
|
+
puts "Sorry, but we couldn't find you. Give it another try."
|
43
|
+
login_from_console
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def write
|
48
|
+
print "Got your token. Writing a config file to #{@filename}... "
|
49
|
+
attrs = {url: @url, token: @token}
|
50
|
+
File.open(@filename, "w", 0600) { |f| f << JSON.dump(attrs); f << "\r\n" }
|
51
|
+
puts "success!"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PackageCloud
|
2
|
+
class Object
|
3
|
+
def respond_to?(method, include_priv=false)
|
4
|
+
@attrs.has_key?(method.to_s) || super
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
if @attrs.has_key?(method.to_s)
|
9
|
+
@attrs[method.to_s]
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PackageCloud
|
2
|
+
class Repository < Object
|
3
|
+
def initialize(attrs, config)
|
4
|
+
@attrs = attrs
|
5
|
+
@config = config
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_package(file_path)
|
9
|
+
file_data = File.new(file_path, 'rb')
|
10
|
+
base_url = @config.base_url
|
11
|
+
url = base_url + paths["create_package"]
|
12
|
+
begin
|
13
|
+
RestClient.post(url, package: {package_file: file_data})
|
14
|
+
print "success!\n".green
|
15
|
+
rescue RestClient::UnprocessableEntity => e
|
16
|
+
print "error:\n".red
|
17
|
+
json = JSON.parse(e.response)
|
18
|
+
json.each do |k,v|
|
19
|
+
puts "\n\t#{k}: #{v.join(", ")}\n"
|
20
|
+
end
|
21
|
+
puts ""
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'package_cloud/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "package_cloud"
|
8
|
+
spec.version = PackageCloud::VERSION
|
9
|
+
spec.authors = ["James Golick"]
|
10
|
+
spec.email = ["jamesgolick@gmail.com"]
|
11
|
+
spec.description = %q{https://packagecloud.io}
|
12
|
+
spec.summary = %q{https://packagecloud.io}
|
13
|
+
spec.homepage = "https://packagecloud.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "thor", "0.18.1"
|
22
|
+
spec.add_runtime_dependency "highline", "1.6.20"
|
23
|
+
spec.add_runtime_dependency "rest-client", "1.6.7"
|
24
|
+
spec.add_runtime_dependency "json", "1.8.1"
|
25
|
+
spec.add_runtime_dependency "colorize", "0.6.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: package_cloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Golick
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2014-01-15 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thor
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.18.1
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: highline
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - "="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.20
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rest-client
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.7
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: json
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - "="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.8.1
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: colorize
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - "="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.6.0
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "1.3"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
description: https://packagecloud.io
|
93
|
+
email:
|
94
|
+
- jamesgolick@gmail.com
|
95
|
+
executables:
|
96
|
+
- package_cloud
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/package_cloud
|
108
|
+
- lib/package_cloud.rb
|
109
|
+
- lib/package_cloud/auth.rb
|
110
|
+
- lib/package_cloud/cli.rb
|
111
|
+
- lib/package_cloud/client.rb
|
112
|
+
- lib/package_cloud/config_file.rb
|
113
|
+
- lib/package_cloud/object.rb
|
114
|
+
- lib/package_cloud/repository.rb
|
115
|
+
- lib/package_cloud/version.rb
|
116
|
+
- package_cloud.gemspec
|
117
|
+
homepage: https://packagecloud.io
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: "0"
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.23
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: https://packagecloud.io
|
144
|
+
test_files: []
|
145
|
+
|