nettle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +18 -0
- data/Rakefile +4 -0
- data/lib/nettle.rb +30 -0
- data/lib/nettle/verbs.rb +44 -0
- data/nettle.gemspec +15 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lee Jarvis
|
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,18 @@
|
|
1
|
+
# Nettle
|
2
|
+
|
3
|
+
A wrapper around `net/http` for a simplified API. Extremely feature lacking at
|
4
|
+
the moment.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install nettle
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
response = Nettle.get("http://google.com")
|
14
|
+
response.body #=> lots of html
|
15
|
+
|
16
|
+
response = Nettle.post("http://google.com", foo: "bar")
|
17
|
+
response.code #=> "405"
|
18
|
+
```
|
data/Rakefile
ADDED
data/lib/nettle.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'nettle/verbs'
|
5
|
+
|
6
|
+
module Nettle
|
7
|
+
module_function
|
8
|
+
|
9
|
+
include Verbs
|
10
|
+
extend Verbs
|
11
|
+
|
12
|
+
def request(method, url, options = {})
|
13
|
+
uri = URI.parse(url)
|
14
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
request = make_request(method, uri, options)
|
16
|
+
yield request if block_given?
|
17
|
+
response = http.request(request)
|
18
|
+
Array(options[:response_extensions]).each { |ext| response.extend(ext) }
|
19
|
+
response
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_request(method, uri, options)
|
23
|
+
klass = Net::HTTP.const_get(method.to_s.downcase.capitalize)
|
24
|
+
request = klass.new(uri.request_uri)
|
25
|
+
request
|
26
|
+
rescue NameError
|
27
|
+
raise NameError, "Unknown request method #{method}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/nettle/verbs.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Nettle
|
2
|
+
module Verbs
|
3
|
+
def get(url, options = {}, &block)
|
4
|
+
request(:Get, url, options, &block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def head(url, options = {}, &block)
|
8
|
+
request(:Head, url, options, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(url, params = {}, options = {}, &block)
|
12
|
+
request(:Post, url, options) do |req|
|
13
|
+
req.set_form_data params
|
14
|
+
yield req if block_given?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(url, params = {}, options = {}, &block)
|
19
|
+
request(:Put, url, options) do |req|
|
20
|
+
req.set_form_data params
|
21
|
+
yield req if block_given?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def patch(url, params = {}, options = {}, &block)
|
26
|
+
request(:Patch, url, options) do |req|
|
27
|
+
req.set_form_data params
|
28
|
+
yield req if block_given?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(url, options = {}, &block)
|
33
|
+
request(:Delete, url, options, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def trace(url, options = {}, &block)
|
37
|
+
request(:Trace, url, options, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def options(url, options = {}, &block)
|
41
|
+
request(:Options, url, options, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/nettle.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = 'nettle'
|
4
|
+
gem.version = '0.0.1'
|
5
|
+
gem.authors = ['Lee Jarvis']
|
6
|
+
gem.email = ['ljjarvis@gmail.com']
|
7
|
+
gem.description = 'A wrapper around net/http for a simplified API (feature lacking)'
|
8
|
+
gem.summary = 'A tiny wrapper around net/http'
|
9
|
+
gem.homepage = 'https://github.com/injekt/nettle'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($/)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nettle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Jarvis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A wrapper around net/http for a simplified API (feature lacking)
|
15
|
+
email:
|
16
|
+
- ljjarvis@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/nettle.rb
|
27
|
+
- lib/nettle/verbs.rb
|
28
|
+
- nettle.gemspec
|
29
|
+
homepage: https://github.com/injekt/nettle
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.23
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: A tiny wrapper around net/http
|
53
|
+
test_files: []
|