geminabox_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2333c860b0dba341a3a8464d811a86afa713e39
4
+ data.tar.gz: ec4a7e6e6b37180de60cdff3d1a69e2286d91b32
5
+ SHA512:
6
+ metadata.gz: 0c7e43dfd1afedc2220245bbed6b9f0a83b8f4ff319cbe3b4e71876b44ee998ef989ad89003f8bd29302de23307f95249e78e0d7babbb169c733b2d78f02346d
7
+ data.tar.gz: e2bead29dd3f93d34b23bb60388df6ce23a2ffb1b549ddbf5635de277b9d23affc495760c86544f214077998957a435cb062cde08a08a4208ece98c877a56406
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .bundle/
2
+ pkg/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geminabox_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 István Karaszi
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,54 @@
1
+ # Gem in a Box Client
2
+
3
+ [![Build Status](https://secure.travis-ci.org/raszi/geminabox_client.png)](http://travis-ci.org/raszi/geminabox_client)
4
+ [![Gem Version](https://badge.fury.io/rb/geminabox_client.png)](http://badge.fury.io/rb/geminabox_client)
5
+
6
+ This is a client for pushing gems to a GemInABox server forked from the GemInABox repository.
7
+
8
+ ## Usage
9
+
10
+ gem install geminabox
11
+
12
+ gem inabox pkg/my-awesome-gem-1.0.gem
13
+
14
+ Configure Gem in a box (interactive prompt to specify where to upload to):
15
+
16
+ gem inabox -c
17
+
18
+ Change the host to upload to:
19
+
20
+ gem inabox -g HOST
21
+
22
+ Simples!
23
+
24
+ ## Command Line Help
25
+
26
+ Usage: gem inabox GEM [options]
27
+
28
+ Options:
29
+ -c, --configure Configure GemInABox
30
+ -g, --host HOST Host to upload to.
31
+ -o, --overwrite Overwrite Gem.
32
+
33
+
34
+ Common Options:
35
+ -h, --help Get help on this command
36
+ -V, --[no-]verbose Set the verbose level of output
37
+ -q, --quiet Silence commands
38
+ --config-file FILE Use this config file instead of default
39
+ --backtrace Show stack backtrace on errors
40
+ --debug Turn on Ruby debugging
41
+
42
+
43
+ Arguments:
44
+ GEM built gem to push up
45
+
46
+ Summary:
47
+ Push a gem up to your GemInABox
48
+
49
+ Description:
50
+ Push a gem up to your GemInABox
51
+
52
+ ## Licence
53
+
54
+ MIT license.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -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 'geminabox_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geminabox_client"
8
+ spec.version = GeminaboxClient::VERSION
9
+ spec.authors = ["KARASZI István"]
10
+ spec.email = ["github@spam.raszi.hu"]
11
+ spec.description = %q{Geminabox client}
12
+ spec.summary = %q{Client for a Geminabox project}
13
+ spec.homepage = ""
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_dependency "httpclient", ">= 2.2.7"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,9 @@
1
+ require "geminabox_client/version"
2
+
3
+ module GeminaboxClient
4
+ autoload :Client, 'geminabox_client/client'
5
+ autoload :GemLocator, 'geminabox_client/gem_locator'
6
+
7
+ class GeminaboxClient::Error < RuntimeError
8
+ end
9
+ end
@@ -0,0 +1,60 @@
1
+ require 'uri'
2
+ require 'httpclient'
3
+
4
+ module GeminaboxClient
5
+ class Client
6
+ HEADERS = { 'Accept' => 'text/plain' }.freeze
7
+
8
+ attr_reader :url
9
+
10
+ def initialize(url)
11
+ extract_username_and_password_from_url!(url)
12
+ end
13
+
14
+ def push(gemfile, options={})
15
+ body = { 'file' => File.open(gemfile, 'rb'), 'overwrite' => !!options[:overwrite] }
16
+
17
+ response = http_client.post(url_for(:upload), body, HEADERS)
18
+
19
+ raise GeminaboxClient::Error, "Error (#{response.code} received)\n\n#{response.body}" if response.status > 300
20
+
21
+ response.body
22
+ end
23
+
24
+ private
25
+
26
+ def http_client
27
+ @http_client ||= initialize_client
28
+ end
29
+
30
+ def url_for(path)
31
+ @url + path.to_s
32
+ end
33
+
34
+ def initialize_client
35
+ HTTPClient.new(:agent_name => "GemClient #{VERSION}").tap do |client|
36
+ if @username or @password
37
+ client.set_auth(url_for(:upload), @username, @password)
38
+ client.www_auth.basic_auth.challenge(url_for(:upload)) # Workaround: https://github.com/nahi/httpclient/issues/63
39
+ end
40
+
41
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
+ client.send_timeout = 0
43
+ client.receive_timeout = 0
44
+ end
45
+ end
46
+
47
+ def extract_username_and_password_from_url!(url)
48
+ uri = URI.parse(url.to_s)
49
+
50
+ @username, @password = uri.user, uri.password
51
+
52
+ uri.user = uri.password = nil
53
+ uri.path = uri.path + "/" unless uri.path.end_with?("/")
54
+
55
+ @url = uri.to_s
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,19 @@
1
+ module GeminaboxClient
2
+ module GemLocator
3
+ def find_gem(dir)
4
+ gemname = File.split(dir).last
5
+ glob_matcher = "{pkg/,}#{gemname}-*.gem"
6
+ latest_gem_for(gemname, Dir.glob(glob_matcher)) or raise Gem::CommandLineError, NO_GEM_PROVIDED_ERROR_MESSAGE
7
+ end
8
+
9
+ def latest_gem_for(gemname, files)
10
+ regexp_matcher = %r{(?:pkg/)#{gemname}-(#{Gem::Version::VERSION_PATTERN})\.gem}
11
+ sorter = lambda{|v| Gem::Version.new(regexp_matcher.match(v)[1]) }
12
+ files.grep(regexp_matcher).max_by(&sorter)
13
+ end
14
+
15
+ extend self
16
+
17
+ NO_GEM_PROVIDED_ERROR_MESSAGE = "Couldn't find a gem in pkg, please specify a gem name on the command line (e.g. gem inabox GEMNAME)"
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module GeminaboxClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,91 @@
1
+ require 'rubygems/command'
2
+
3
+ class Gem::Commands::InaboxCommand < Gem::Command
4
+ def description
5
+ 'Push a gem up to your GemInABox'
6
+ end
7
+
8
+ def arguments
9
+ "GEM built gem to push up"
10
+ end
11
+
12
+ def usage
13
+ "#{program_name} GEM"
14
+ end
15
+
16
+ def initialize
17
+ super 'inabox', description
18
+
19
+ add_option('-c', '--configure', "Configure GemInABox") do |value, options|
20
+ options[:configure] = true
21
+ end
22
+
23
+ add_option('-g', '--host HOST', "Host to upload to.") do |value, options|
24
+ options[:host] = value
25
+ end
26
+
27
+ add_option('-o', '--overwrite', "Overwrite Gem.") do |value, options|
28
+ options[:overwrite] = true
29
+ end
30
+ end
31
+
32
+ def last_minute_requires!
33
+ require 'yaml'
34
+ require File.expand_path("../../../geminabox_client.rb", __FILE__)
35
+ end
36
+
37
+ def execute
38
+ last_minute_requires!
39
+ return configure if options[:configure]
40
+ configure unless geminabox_host
41
+
42
+ if options[:args].size == 0
43
+ say "You didn't specify a gem, looking for one in . and in ./pkg/..."
44
+ gemfiles = [GeminaboxClient::GemLocator.find_gem(Dir.pwd)]
45
+ else
46
+ gemfiles = get_all_gem_names
47
+ end
48
+
49
+ send_gems(gemfiles)
50
+ end
51
+
52
+ def send_gems(gemfiles)
53
+ client = GeminaboxClient::Client.new(geminabox_host)
54
+
55
+ gemfiles.each do |gemfile|
56
+ say "Pushing #{File.basename(gemfile)} to #{client.url}..."
57
+ begin
58
+ say client.push(gemfile, options)
59
+ rescue GeminaboxClient::Error => e
60
+ alert_error e.message
61
+ terminate_interaction(1)
62
+ end
63
+ end
64
+ end
65
+
66
+ def config_path
67
+ File.join(Gem.user_home, '.gem', 'geminabox')
68
+ end
69
+
70
+ def configure
71
+ say "Enter the root url for your personal geminabox instance. (E.g. http://gems/)"
72
+ host = ask("Host:")
73
+ self.geminabox_host = host
74
+ end
75
+
76
+ def geminabox_host
77
+ @geminabox_host ||= options[:host] || Gem.configuration.load_file(config_path)[:host]
78
+ end
79
+
80
+ def geminabox_host=(host)
81
+ config = Gem.configuration.load_file(config_path).merge(:host => host)
82
+
83
+ dirname = File.dirname(config_path)
84
+ Dir.mkdir(dirname) unless File.exists?(dirname)
85
+
86
+ File.open(config_path, 'w') do |f|
87
+ f.write config.to_yaml
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :inabox
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geminabox_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - KARASZI István
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Geminabox client
70
+ email:
71
+ - github@spam.raszi.hu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - geminabox_client.gemspec
83
+ - lib/geminabox_client.rb
84
+ - lib/geminabox_client/client.rb
85
+ - lib/geminabox_client/gem_locator.rb
86
+ - lib/geminabox_client/version.rb
87
+ - lib/rubygems/commands/inabox_command.rb
88
+ - lib/rubygems_plugin.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Client for a Geminabox project
114
+ test_files:
115
+ - spec/spec_helper.rb