httpshell 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c699194a6aad7815fdea2439d1e35824eec2f61
4
+ data.tar.gz: af73922d868145d4de1de95d7fdd55f69fba40b3
5
+ SHA512:
6
+ metadata.gz: 90b761efc9bc1f94384a67a16c298c3633d7a70fc00f31a6ba68d8dbe8477185a9e541f1787fe1546387f6474c9a7f60c96c75f4528288e1b59a374c3e5d106c
7
+ data.tar.gz: 87e5c0fc7221aab72dd2e91aef9600142115352a4f34e5d6b30e8944cb1de447dbf2e958a79dabf9cb4e754660279771c56e82b275ebca5b3afa5897b3b6e230
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in httpshell.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sorpa'as plat
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.
@@ -0,0 +1,36 @@
1
+ # HTTPShell
2
+
3
+ HTTPShell is a simple console program that makes curl commands shorter and easier. It makes you able to directly run get/post/put/delete request in a line and with relative path.
4
+
5
+ ## Installation
6
+
7
+ Run this line in your console.
8
+
9
+ gem install httpshell
10
+
11
+ ## Usage
12
+
13
+ To change the working path, do:
14
+
15
+ http:/// > cd example
16
+
17
+ Run http request:
18
+
19
+ http://example.com/ > post sessions
20
+ # => {"uuid":"f64ff663-0df2-4954-89ee-f78e38ac284f","pairs":[]}
21
+
22
+ Using pipes to write variables:
23
+
24
+ http://example.com/ > post sessions | $session_token
25
+ http://example.com/session > debug
26
+ # => session_token: {"uuid":"f64ff663-0df2-4954-89ee-f78e38ac284f","pairs":[]}
27
+
28
+ Have fun playing!
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/[my-github-username]/httpshell/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require 'httpshell'
5
+ require "net/http"
6
+ require "uri"
7
+
8
+ def http_request(method, path)
9
+ uri = URI.parse(path)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.request(method.new(uri.request_uri))
12
+ end
13
+
14
+ @spec = Gem::Specification::load("httpshell.gemspec")
15
+ @env = HTTPShell::Environment.new
16
+ @commands = {
17
+ cd: lambda do |env|
18
+ #do nothing
19
+ nil
20
+ end,
21
+
22
+ get: lambda do |env|
23
+ http_request(Net::HTTP::Get, env.working_path).body
24
+ end,
25
+
26
+ post: lambda do |env|
27
+ http_request(Net::HTTP::Post, env.working_path).body
28
+ end,
29
+
30
+ put: lambda do |env|
31
+ http_request(Net::HTTP::Put, env.working_path).body
32
+ end,
33
+
34
+ delete: lambda do |env|
35
+ http_request(Net::HTTP::Delete, env.working_path).body
36
+ end,
37
+
38
+ debug: lambda do |env|
39
+ puts "Debug Information: "
40
+ puts "Working Path:\t#{env.working_path}"
41
+ env.variables.each do |key, value|
42
+ puts "#{key}:\t#{value}"
43
+ end
44
+ puts ""
45
+ nil
46
+ end
47
+ }
48
+
49
+ puts "#{@spec.name} #{@spec.version}"
50
+ puts "By #{@spec.author} <#{@spec.email[0]}>"
51
+ puts ""
52
+
53
+ while true
54
+ print "#{@env.working_path}/ > "
55
+ command = gets.strip
56
+
57
+ if command == 'exit' or command == 'quit'
58
+ break
59
+ end
60
+
61
+ sub_commands = command.split('|').map { |c| c.strip }
62
+
63
+ current_output = nil
64
+ sub_commands.each do |sub_command|
65
+ #first to see whether it is a variable
66
+ if sub_command.start_with? '$'
67
+ if current_output
68
+ @env.variables[sub_command.sub(/^\$/, '')] = current_output
69
+ current_output = current_output
70
+ else
71
+ current_output = @env.variables[sub_command.sub(/^\$/, '')]
72
+ end
73
+ next
74
+ end
75
+
76
+ params = sub_command.split(' ').map { |p| p.strip }
77
+ params.delete("")
78
+
79
+ #then check whether it is blank
80
+ if params.length == 0
81
+ next
82
+ end
83
+
84
+ #or a command
85
+ exec_com = @commands[:"#{params[0]}"]
86
+ if params.length <= 2 and exec_com != nil
87
+ #if it is, then run it.
88
+ if params[1]
89
+ @env.cd(params[1])
90
+ end
91
+ current_output = exec_com.call(@env)
92
+ next
93
+ end
94
+
95
+ #then we don't know how to deal with it.
96
+ puts 'error: do not know how to deal with it. '
97
+ end
98
+
99
+ if not (current_output == nil or current_output.to_s.strip == '')
100
+ puts current_output.to_s.strip
101
+ puts ""
102
+ end
103
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'httpshell/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "httpshell"
8
+ spec.version = Httpshell::VERSION
9
+ spec.authors = ["sorpa'as plat"]
10
+ spec.email = ["sorpaas@gmail.com"]
11
+ spec.summary = %q{Shell console specificly for http request. }
12
+ spec.description = %q{A simple shell console for running http request. }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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
+ spec.executables = ["httpshell"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,47 @@
1
+ require 'httpshell/version'
2
+
3
+ module HTTPShell
4
+ class Environment
5
+ attr_reader :variables
6
+ attr_accessor :working_path
7
+
8
+ def initialize
9
+ @variables = {}
10
+ @working_path = "http://"
11
+ end
12
+
13
+ def cd(path)
14
+ if /^(http|https|file):\/\//i =~ path
15
+ cd_absolutely(path)
16
+ else
17
+ cd_relatively(path)
18
+ end
19
+ end
20
+
21
+ private
22
+ def cd_relatively(path)
23
+ path = path.sub /^\/+/, ''
24
+ path = path.sub /\/+$/, ''
25
+
26
+ if path == '..'
27
+ @working_path = @working_path.sub /\/[^\/]+$/, ''
28
+ elsif path == '.'
29
+ @working_path = @working_path
30
+ else
31
+ if /^(http|https|file):\/\/$/i =~ @working_path
32
+ @working_path = "#{@working_path}#{path}"
33
+ else
34
+ @working_path = "#{@working_path}/#{path}"
35
+ end
36
+ end
37
+ end
38
+
39
+ def cd_absolutely(path)
40
+ if not /^(http|https|file):\/\/$/i =~ path
41
+ path = path.sub /\/$/, ''
42
+ end
43
+
44
+ @working_path = path
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Httpshell
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpshell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - sorpa'as plat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-05 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description: 'A simple shell console for running http request. '
42
+ email:
43
+ - sorpaas@gmail.com
44
+ executables:
45
+ - httpshell
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/httpshell
55
+ - httpshell.gemspec
56
+ - lib/httpshell.rb
57
+ - lib/httpshell/version.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Shell console specificly for http request.
82
+ test_files: []