simple_http_client 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 +21 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +37 -0
- data/LICENSE +24 -0
- data/Makefile +24 -0
- data/README.md +23 -0
- data/lib/simple_http_client.rb +53 -0
- data/simple_http_client.gemspec +24 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 972e1463ba8977345f5fdea6a25fb83bcf95da2e
|
4
|
+
data.tar.gz: 9fb213129122b78aa2b08bd86a51bf8200462013
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7abc1f8605d099ba78014247bb7ba8d5cf886ad68fde55954d538edf2a334c8c4fbbcda3efa7b1dfe9acf3a015a1f8e1a973de28700b5ba713a1a4e626fa00e
|
7
|
+
data.tar.gz: 114c0d69a76f6758aa7cbafc3fb99c718c5c065e45f788feceb47d53d14ef073b42f712a5a1db37fada4189b321dc59696ca0e8dfa5ab8923891888ef82b1ed1
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# Ignore the default SQLite database.
|
16
|
+
/db/*.sqlite3
|
17
|
+
|
18
|
+
# YARD artifacts
|
19
|
+
.yardoc
|
20
|
+
_yardoc
|
21
|
+
doc/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_http_client (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rack (1.6.4)
|
11
|
+
rspec (3.3.0)
|
12
|
+
rspec-core (~> 3.3.0)
|
13
|
+
rspec-expectations (~> 3.3.0)
|
14
|
+
rspec-mocks (~> 3.3.0)
|
15
|
+
rspec-core (3.3.2)
|
16
|
+
rspec-support (~> 3.3.0)
|
17
|
+
rspec-expectations (3.3.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.3.0)
|
20
|
+
rspec-mocks (3.3.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.3.0)
|
23
|
+
rspec-support (3.3.0)
|
24
|
+
spork (0.9.2)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.10)
|
31
|
+
rack (~> 1.6)
|
32
|
+
rspec (~> 3.3)
|
33
|
+
simple_http_client!
|
34
|
+
spork (~> 0.9)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.10.3
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/Makefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH := $(PATH)
|
2
|
+
SHELL := /usr/bin/env bash
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
project_dir := $(notdir $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
|
5
|
+
installed := $(TMPDIR).$(project_dir)
|
6
|
+
|
7
|
+
.PHONY: default
|
8
|
+
default: spec
|
9
|
+
|
10
|
+
.PHONY: install
|
11
|
+
install: $(installed)
|
12
|
+
|
13
|
+
$(installed): Gemfile.lock Gemfile simple_http_client.gemspec
|
14
|
+
@gem list bundler -i > /dev/null || gem install bundler
|
15
|
+
@bundle install
|
16
|
+
@touch $@
|
17
|
+
|
18
|
+
.PHONY: clean
|
19
|
+
clean:
|
20
|
+
@rm $(installed)
|
21
|
+
|
22
|
+
.PHONY: spec
|
23
|
+
spec: $(installed)
|
24
|
+
@bundle exec rspec spec
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Install
|
2
|
+
|
3
|
+
## On Gemfile
|
4
|
+
`gem 'simple_http_client'`
|
5
|
+
|
6
|
+
## Manually
|
7
|
+
`gem install simple_http_client`
|
8
|
+
|
9
|
+
# Usage
|
10
|
+
```
|
11
|
+
require 'simple_http_client'
|
12
|
+
|
13
|
+
http_client = SimpleHttpClient.new 'http://host:port'
|
14
|
+
http_client.get('/path', { 'Header-Key' => 'value' })
|
15
|
+
http_client.post('/path', { 'Body' => 'Content'}, { 'Header-Key' => 'value' })
|
16
|
+
```
|
17
|
+
|
18
|
+
# Development
|
19
|
+
`make` or `make spec` or `bundle install && rspec spec`
|
20
|
+
|
21
|
+
# License
|
22
|
+
|
23
|
+
This code is in the Public Domain. See [LICENSE](./LICENSE)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class SimpleHttpClient
|
6
|
+
CONTENT_TYPE = { 'Content-Type' => 'application/json' }
|
7
|
+
ACCEPT = { 'Accept' => 'application/json' }
|
8
|
+
|
9
|
+
def initialize(base_url)
|
10
|
+
@uri = URI.parse(base_url)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, header = {})
|
14
|
+
request = Net::HTTP::Get.new("/#{path}")
|
15
|
+
non_body_request(request, header)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(path, header = {})
|
19
|
+
request = Net::HTTP::Delete.new("/#{path}")
|
20
|
+
non_body_request(request, header)
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(path, body, header = {})
|
24
|
+
request = Net::HTTP::Post.new(path)
|
25
|
+
body_request(request, body, header)
|
26
|
+
end
|
27
|
+
|
28
|
+
def put(path, body, header = {})
|
29
|
+
request = Net::HTTP::Put.new(path)
|
30
|
+
body_request(request, body, header)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def http
|
36
|
+
Net::HTTP.new(@uri.host, @uri.port)
|
37
|
+
end
|
38
|
+
|
39
|
+
def non_body_request(request, header)
|
40
|
+
request.initialize_http_header(ACCEPT.merge(header))
|
41
|
+
execute request
|
42
|
+
end
|
43
|
+
|
44
|
+
def body_request(request, body, header)
|
45
|
+
request.body = JSON.dump(body)
|
46
|
+
request.initialize_http_header(CONTENT_TYPE.merge(header))
|
47
|
+
execute request
|
48
|
+
end
|
49
|
+
|
50
|
+
def execute(request)
|
51
|
+
http.request(request)
|
52
|
+
end
|
53
|
+
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
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "simple_http_client"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["Filipe Esperandio"]
|
9
|
+
spec.email = ["filipesperandio@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Simple Http Client for a better experience on simple needs}
|
12
|
+
spec.description = %q{Simple Http Client aims to provide a simpler interface to Net:HTTP request objects}
|
13
|
+
spec.homepage = "http://github.com/filipesperandio/simple_http_client"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
21
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
22
|
+
spec.add_development_dependency 'spork', '~> 0.9'
|
23
|
+
spec.add_development_dependency 'rack', '~> 1.6'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_http_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filipe Esperandio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: spork
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
description: Simple Http Client aims to provide a simpler interface to Net:HTTP request
|
70
|
+
objects
|
71
|
+
email:
|
72
|
+
- filipesperandio@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE
|
81
|
+
- Makefile
|
82
|
+
- README.md
|
83
|
+
- lib/simple_http_client.rb
|
84
|
+
- simple_http_client.gemspec
|
85
|
+
homepage: http://github.com/filipesperandio/simple_http_client
|
86
|
+
licenses: []
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Simple Http Client for a better experience on simple needs
|
108
|
+
test_files: []
|