hoick 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjJiNTY3M2ZhZTNmYmY0YTNmMTRjODg0ZmNhYjRjOTczM2MzMjMzYQ==
5
+ data.tar.gz: !binary |-
6
+ Y2U0NDVhOTAyYzhhZjM1MmY5NzY4ZTQ0YzMxMmUzN2FkMWZlNGFmNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTZiNzllYTIyNTlhMDNhNzA4OTU5MTdmMmUwNDRhMzlhNjA1ZDFlZjA0ODM4
10
+ ZjU2YjE1NTRhYTZhODM3ZGU4MDJkZTM5NzAwMjNkZjg1NWZlYmRjMjgzYTAw
11
+ ZWJkODlhMmE5MWM0NTFjYmY2MjM3Yzk3YjM5NmIzNGMyMjU2Nzk=
12
+ data.tar.gz: !binary |-
13
+ ZmZkZDM0MWUzMDM3NTBhY2E5M2Y3YWRhYWE5MjljNWViMThkMTk1NDdmYzI0
14
+ MTY1YTFmNmE2ZWNkOTE4ZTA2OTliN2RjNjQwYmE5MzM5YzFkMTRhNjBlZTFj
15
+ ZDlmYTNhY2E1OTIyYjQ2YTBiN2M4Y2JlNTEyMTNjOTViZDQ1ZWY=
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ .rbenv-*
4
+ Gemfile.lock
5
+ pkg
6
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hoick.gemspec
4
+ gemspec
5
+
6
+ gem "rake"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mike Williams
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
+ # Hoick
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hoick'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hoick
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,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :build
data/bin/hoick ADDED
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+
5
+ $: << File.expand_path("../../lib", __FILE__)
6
+ require "hoick/command"
7
+
8
+ Hoick::Command.run
data/hoick.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hoick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hoick"
8
+ spec.version = Hoick::VERSION
9
+ spec.authors = ["Mike Williams"]
10
+ spec.email = ["mdub@dogbiscuit.org"]
11
+ spec.description = %q{A command-line HTTP client}
12
+ spec.summary = %q{A command-line HTTP client}
13
+ spec.homepage = "https://github.com/mdub/hoick"
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
+ end
@@ -0,0 +1,97 @@
1
+ require "clamp"
2
+ require "net/http"
3
+
4
+ module Hoick
5
+
6
+ class Command < Clamp::Command
7
+
8
+ option ["-b", "--[no-]body"], :flag, "display response body", :default => true
9
+ option ["-h", "--[no-]headers"], :flag, "display response status and headers"
10
+
11
+ option ["--debug"], :flag, "debug"
12
+
13
+ subcommand ["get", "GET"], "HTTP GET" do
14
+
15
+ option ["--follow"], :flag, "follow redirects"
16
+
17
+ parameter "URL", "address"
18
+
19
+ def execute
20
+ get_with_redirects(url) do |response|
21
+ display_response(response)
22
+ end
23
+ end
24
+
25
+ def get_with_redirects(url, &callback)
26
+ with_connection_to(url) do |http, uri|
27
+ http.request_get(uri.request_uri) do |response|
28
+ if follow? && response.kind_of?(Net::HTTPRedirection)
29
+ get_with_redirects(response['location'], &callback)
30
+ else
31
+ callback.call(response)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ subcommand ["put", "PUT"], "HTTP PUT" do
40
+
41
+ parameter "URL", "address"
42
+ parameter "[FILE]", "file to upload"
43
+
44
+ def execute
45
+ content = read_content
46
+ with_connection_to(url) do |http, uri|
47
+ put = Net::HTTP::Put.new(uri.request_uri)
48
+ put.body = content
49
+ put["Content-Type"] = "application/octet-stream"
50
+ http.request(put) do |response|
51
+ display_response(response)
52
+ end
53
+ end
54
+ end
55
+
56
+ def read_content
57
+ if file
58
+ File.read(file)
59
+ else
60
+ $stdin.read
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ private
67
+
68
+ def with_connection_to(url)
69
+ uri = URI(url)
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ http.set_debug_output($stderr) if debug?
72
+ http.start do
73
+ yield http, uri
74
+ end
75
+ end
76
+
77
+ def display_response(response)
78
+ if headers?
79
+ puts "HTTP/#{response.http_version} #{response.code} #{response.message}"
80
+ response.each_capitalized do |header, value|
81
+ puts("#{header}: #{value}")
82
+ end
83
+ puts ""
84
+ end
85
+ if body?
86
+ response.read_body do |chunk|
87
+ print chunk
88
+ end
89
+ end
90
+ unless response.kind_of?(Net::HTTPSuccess)
91
+ exit(response.code.to_i / 100)
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,3 @@
1
+ module Hoick
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ prerelease: false
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ name: bundler
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: '1.3'
26
+ type: :development
27
+ description: A command-line HTTP client
28
+ email:
29
+ - mdub@dogbiscuit.org
30
+ executables:
31
+ - hoick
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/hoick
41
+ - hoick.gemspec
42
+ - lib/hoick/command.rb
43
+ - lib/hoick/version.rb
44
+ homepage: https://github.com/mdub/hoick
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.0.0
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A command-line HTTP client
68
+ test_files: []