pcurl 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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/bin/pcurl +9 -0
- data/lib/pcurl.rb +8 -0
- data/lib/pcurl/request.rb +31 -0
- data/lib/pcurl/version.rb +3 -0
- data/pcurl.gemspec +25 -0
- data/spec/request_spec.rb +35 -0
- data/spec/spec_helper.rb +4 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5fff727b6586017bc153193450a77fbcaaa451c7
|
4
|
+
data.tar.gz: a28898ad585e51a56b4905b93cba3a318d0ca6ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8b7bb9c97b22a8a462fb7769c373ef6f322c549336e7c2fc950db95a856d6da5ab8fab7301dc31f8dca7e3d16f707fa7063b6fb0f7d8390a5c710763d3f65ee
|
7
|
+
data.tar.gz: 96d22d77c851b79e7ce951a5ca07f5be2c5548676af74103276bee41aa3b2c91cb85fb9baebe1df4a19483be7de06c01fbd35fc32251848b8505b5fc83a13ffa
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ben Snape
|
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
|
+
# Pcurl
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pcurl'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pcurl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/pcurl/fork )
|
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
data/bin/pcurl
ADDED
data/lib/pcurl.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module PcURL
|
2
|
+
|
3
|
+
class Request
|
4
|
+
|
5
|
+
def request(url)
|
6
|
+
response = get url
|
7
|
+
parsed_response = parse_response response
|
8
|
+
pretty_response = prettify(parsed_response)
|
9
|
+
puts pretty_response
|
10
|
+
pretty_response
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(url)
|
14
|
+
Curl.get(url).body_str
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_response(response)
|
18
|
+
begin
|
19
|
+
JSON.parse response
|
20
|
+
rescue
|
21
|
+
raise "JSON parsing exception for response: #{response}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def prettify(response)
|
26
|
+
JSON.pretty_generate response
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/pcurl.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pcurl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pcurl'
|
8
|
+
spec.version = PcURL::VERSION
|
9
|
+
spec.authors = ['Ben Snape']
|
10
|
+
spec.email = ['bsnape@gmail.com']
|
11
|
+
spec.summary = %q{Pretty print cURL responses in your terminal.}
|
12
|
+
spec.homepage = 'http://www.bensnape.com'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = ['pcurl']
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'rspec', '~> 2.14'
|
21
|
+
spec.add_dependency 'curb', '~> 0.8'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe PcURL::Request do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@pcurl = PcURL::Request.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should pretty print a JSON response' do
|
10
|
+
json = {
|
11
|
+
'menu' => {
|
12
|
+
'id' => 'file',
|
13
|
+
'value' => 'File',
|
14
|
+
'popup' => {
|
15
|
+
'menuitem' => [
|
16
|
+
{'value' => 'New', 'onclick' => 'CreateNewDoc()'},
|
17
|
+
{'value' => 'Open', 'onclick' => 'OpenDoc()'},
|
18
|
+
{'value' => 'Close', 'onclick' => 'CloseDoc()'}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}.to_json
|
23
|
+
|
24
|
+
@pcurl.stub(:get).and_return(json)
|
25
|
+
@pcurl.request('http://some/test/url').should_not == json # pretty != unpretty
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should raise a useful error if the response is not valid JSON' do
|
29
|
+
invalid_json = "({'something': 'invalid'})"
|
30
|
+
|
31
|
+
@pcurl.stub(:get).and_return(invalid_json)
|
32
|
+
expect { @pcurl.request('http://some/test/url') }.to raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pcurl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Snape
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: curb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- bsnape@gmail.com
|
72
|
+
executables:
|
73
|
+
- pcurl
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/pcurl
|
83
|
+
- lib/pcurl.rb
|
84
|
+
- lib/pcurl/request.rb
|
85
|
+
- lib/pcurl/version.rb
|
86
|
+
- pcurl.gemspec
|
87
|
+
- spec/request_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: http://www.bensnape.com
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.0
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Pretty print cURL responses in your terminal.
|
113
|
+
test_files:
|
114
|
+
- spec/request_spec.rb
|
115
|
+
- spec/spec_helper.rb
|