pkghub-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/bin/pkghub +57 -0
- data/lib/pkghub/api/package.rb +65 -0
- data/lib/pkghub/api/version.rb +5 -0
- data/lib/pkghub/api.rb +7 -0
- data/pkghub-api.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e16bd1a24d8ba4ffbce4e5bf81b481e20fafb6e
|
4
|
+
data.tar.gz: 5865c895bb1875783016776fe30976c43cd7bb41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 026455860c9af89387011fd73b1500fed49906ab7b932124ced464066c43d3c7180c4991ec9affae4e43e7b8fe031d6e7e42c838e39ee89c2d799f1aa267d7f7
|
7
|
+
data.tar.gz: 9fcc20bbde00acb20fbb3ad964766494b30f1d7024e5dd059c3d7dff4314fd010731a19482eae98aac65aab581b6315b2b72e58263c610a84beefe633389493f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andy Sykes
|
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,51 @@
|
|
1
|
+
# Pkghub::API
|
2
|
+
|
3
|
+
This gem lets you interact with the [pkghub.io](pkghub.io) API. pkghub.io is a SaaS platform
|
4
|
+
for hosting Ubuntu packages either publically or privately.
|
5
|
+
|
6
|
+
pkghub.io is currently undergoing active development and is not feature-complete.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'pkghub-api'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install pkghub-api
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
The gem has a binary called `pkghub`, which will have several commands it can
|
25
|
+
execute. Right now, it can only upload packages.
|
26
|
+
|
27
|
+
To upload a package:
|
28
|
+
|
29
|
+
pkghub upload --token [yourtoken] \
|
30
|
+
--distro precise \
|
31
|
+
--project my_first_project \
|
32
|
+
--file /path/to/package.deb
|
33
|
+
|
34
|
+
If it succeeds you'll see:
|
35
|
+
|
36
|
+
Success
|
37
|
+
|
38
|
+
You can find your API token on your profile page, which is located at: `https://pkghub.io/users/yourusername`,
|
39
|
+
or can be found by logging in and clicking the "Your Profile" link in the top right. Don't reveal this
|
40
|
+
token to others, as it can be used to modify your repositories.
|
41
|
+
|
42
|
+
You can also use the gem programmatically - look at the `pkghub` command source code to see
|
43
|
+
how it works.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/pkghub
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pkghub/api'
|
4
|
+
require 'pkghub/api/version'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'commander'
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'commander/import'
|
10
|
+
|
11
|
+
program :name, 'pkghub'
|
12
|
+
program :version, Pkghub::API::VERSION
|
13
|
+
program :description, 'Tool to interact with the pkghub.io API'
|
14
|
+
|
15
|
+
command :upload do |c|
|
16
|
+
c.syntax = 'pkghub upload [options]'
|
17
|
+
c.description = 'Uploads a package to a project on pkghub.io'
|
18
|
+
c.option '--token TOKEN', String, 'API token with access to given project'
|
19
|
+
c.option '--project PROJECT', String, 'Project to upload to'
|
20
|
+
c.option '--distro DISTRO', String, 'Name of distro package is for (e.g. precise)'
|
21
|
+
c.option '--file FILE', String, 'File to upload'
|
22
|
+
c.action do |args, options|
|
23
|
+
|
24
|
+
if options.token == nil
|
25
|
+
puts "You must specify a token with --token"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
29
|
+
if options.project == nil
|
30
|
+
puts "You must specify a project with --project"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
if options.distro == nil
|
35
|
+
puts "You must specify a distro with --distro"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
if options.file == nil
|
40
|
+
puts "You must specify a file with --file"
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
pkg = Pkghub::API::Package.new({
|
45
|
+
:path => options.file,
|
46
|
+
:distro => options.distro
|
47
|
+
})
|
48
|
+
|
49
|
+
# begin
|
50
|
+
pkg.upload(options.project, options.token)
|
51
|
+
# rescue => e
|
52
|
+
# puts "Error: #{e.message}"
|
53
|
+
# exit 2
|
54
|
+
# end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http/post/multipart'
|
5
|
+
|
6
|
+
|
7
|
+
module Pkghub
|
8
|
+
module API
|
9
|
+
|
10
|
+
class Package
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
|
14
|
+
# Validate options
|
15
|
+
missing_options = [:path, :distro].reject do |option|
|
16
|
+
options.has_key?(option)
|
17
|
+
end
|
18
|
+
|
19
|
+
if missing_options.size > 0
|
20
|
+
raise "Missing options: #{missing_options.join(", ")}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Default to making package active if not told otherwise
|
24
|
+
options[:active] = true if options[:active].nil?
|
25
|
+
|
26
|
+
# Check file is there
|
27
|
+
@path = options[:path]
|
28
|
+
@distro = options[:distro]
|
29
|
+
raise "Couldn't find file #{@path}" unless File.exists?(@path)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
# Upload file to pkghub.io
|
34
|
+
|
35
|
+
def upload(project, token)
|
36
|
+
|
37
|
+
uri = URI.parse("https://pkghub.io/api/v1/upload")
|
38
|
+
puts uri.inspect
|
39
|
+
n = Net::HTTP.new(uri.host, uri.port)
|
40
|
+
n.use_ssl = true
|
41
|
+
|
42
|
+
File.open(@path) do |package_file|
|
43
|
+
req = Net::HTTP::Post::Multipart.new uri.path,
|
44
|
+
"token" => token,
|
45
|
+
"project" => project,
|
46
|
+
"distro" => @distro,
|
47
|
+
"file" => UploadIO.new(package_file, "application/x-deb", File.basename(@path))
|
48
|
+
|
49
|
+
res = n.start do |http|
|
50
|
+
http.request(req)
|
51
|
+
end
|
52
|
+
|
53
|
+
if res.code == "200"
|
54
|
+
raise "Error uploading to pkghub.io API, code: #{res.code} body: #{res.body}"
|
55
|
+
else
|
56
|
+
puts "Success"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/pkghub/api.rb
ADDED
data/pkghub-api.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pkghub/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pkghub-api"
|
8
|
+
spec.version = Pkghub::API::VERSION
|
9
|
+
spec.authors = ["Andy Sykes"]
|
10
|
+
spec.email = ["github@tinycat.co.uk"]
|
11
|
+
spec.description = %q{Gem for accessing the pkghub.io API}
|
12
|
+
spec.summary = %q{Gem for accessing the pkghub.io API, uploading packages and making changes}
|
13
|
+
spec.homepage = "https://pkghub.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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "multipart-post"
|
25
|
+
spec.add_dependency "commander"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pkghub-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Sykes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multipart-post
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: commander
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Gem for accessing the pkghub.io API
|
70
|
+
email:
|
71
|
+
- github@tinycat.co.uk
|
72
|
+
executables:
|
73
|
+
- pkghub
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/pkghub
|
83
|
+
- lib/pkghub/api.rb
|
84
|
+
- lib/pkghub/api/package.rb
|
85
|
+
- lib/pkghub/api/version.rb
|
86
|
+
- pkghub-api.gemspec
|
87
|
+
homepage: https://pkghub.io
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.1.9
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Gem for accessing the pkghub.io API, uploading packages and making changes
|
111
|
+
test_files: []
|