http_connect 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/http_connect.gemspec +38 -0
- data/lib/http_connect.rb +187 -0
- data/lib/http_connect/http_delete.rb +12 -0
- data/lib/http_connect/http_get.rb +12 -0
- data/lib/http_connect/http_post.rb +12 -0
- data/lib/http_connect/http_put.rb +12 -0
- data/lib/http_connect/http_request.rb +22 -0
- data/lib/http_connect/http_response.rb +13 -0
- data/lib/http_connect/version.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f0804c4e6d31ad1428ff8d3d6f0a546004fbb051
|
|
4
|
+
data.tar.gz: 4f4f2fd187c9a8d809a40e7d45e993d9a4f71115
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d913c7ec288c7fb4a222e2fc417f374c9ed6a8c98234c5d0e3fc2e04c090ea367d5e08093ef0b8f6bdd768056aa6385ab3cd9747288de2b2a4d1d0a279f45571
|
|
7
|
+
data.tar.gz: ce3d11d88e80b2074f703dacdbca507f9618794c24240614602e238d069c2b457c374707edda283d6598ade73403c831684f19ec79903dc70636069a7771c988
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at tochemey@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# HttpConnect
|
|
2
|
+
|
|
3
|
+
A minimal ruby Rest client that uses around the ruby Net::Http library to make requests. It features a simple interface for making Web requests. It has been written and tested on an environment using ruby 2.0 or later.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
Currently the following HTTP verbs are supported
|
|
8
|
+
|
|
9
|
+
* POST
|
|
10
|
+
* GET
|
|
11
|
+
* DELETE
|
|
12
|
+
* PUT
|
|
13
|
+
|
|
14
|
+
Also it handle both https and http and one can use the basic authentication mode against a web resource
|
|
15
|
+
that accepts basic authentication mode.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'http_connect'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And then execute:
|
|
26
|
+
|
|
27
|
+
$ bundle
|
|
28
|
+
|
|
29
|
+
Or install it yourself as:
|
|
30
|
+
|
|
31
|
+
$ gem install http_connect
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Some unit tests have been provided as examples. These unit tests are done against the
|
|
36
|
+
[Hubtel Integration Platform APIs](https://developers.hubtel.com/).
|
|
37
|
+
|
|
38
|
+
## Development
|
|
39
|
+
|
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
41
|
+
|
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/http_connect. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
51
|
+
|
|
52
|
+
## Code of Conduct
|
|
53
|
+
|
|
54
|
+
Everyone interacting in the HttpConnect project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/http_connect/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "http_connect"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'http_connect/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'http_connect'
|
|
9
|
+
spec.version = HttpConnect::VERSION
|
|
10
|
+
spec.authors = ['Arsene Tochemey GANDOTE']
|
|
11
|
+
spec.email = ['tochemey@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Basic Http Client.'
|
|
14
|
+
spec.description = 'Wrapper around the ruby Net::Http library'
|
|
15
|
+
spec.homepage = 'https://github.com/Tochemey/HttpConnect'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
# if spec.respond_to?(:metadata)
|
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
|
22
|
+
# else
|
|
23
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
24
|
+
# 'public gem pushes.'
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = 'exe'
|
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ['lib']
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
37
|
+
spec.add_development_dependency 'pry', '~> 0.10.1'
|
|
38
|
+
end
|
data/lib/http_connect.rb
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require 'http_connect/version'
|
|
2
|
+
require 'Base64'
|
|
3
|
+
require 'http_connect/http_post'
|
|
4
|
+
require 'http_connect/http_get'
|
|
5
|
+
require 'http_connect/http_put'
|
|
6
|
+
require 'http_connect/http_request'
|
|
7
|
+
require 'http_connect/http_response'
|
|
8
|
+
require 'http_connect/http_delete'
|
|
9
|
+
require 'net/http'
|
|
10
|
+
require 'pry'
|
|
11
|
+
require 'json'
|
|
12
|
+
|
|
13
|
+
# HttpConnect module
|
|
14
|
+
module HttpConnect
|
|
15
|
+
# constants definition
|
|
16
|
+
DEFAULT_ACCEPT = 'application/json'.freeze
|
|
17
|
+
DEFAULT_CONTENT_TYPE = 'application/json'.freeze
|
|
18
|
+
FORM_DATA = 'application/x-www-form-urlencoded'.freeze
|
|
19
|
+
|
|
20
|
+
# BasicRestClient
|
|
21
|
+
class BasicRestClient
|
|
22
|
+
attr_reader :base_url # base url of the http request
|
|
23
|
+
attr_accessor :custom_headers # custom http headers to add to the request
|
|
24
|
+
attr_accessor :read_write_timeout # read and write http request timeout
|
|
25
|
+
attr_accessor :connection_timeout # connection timeout
|
|
26
|
+
attr_accessor :use_ssl # helps to set the request scheme to https
|
|
27
|
+
|
|
28
|
+
# initialize()
|
|
29
|
+
def initialize(base_url)
|
|
30
|
+
@base_url = base_url
|
|
31
|
+
@custom_headers = {}
|
|
32
|
+
@read_write_timeout = 8000
|
|
33
|
+
@connection_timeout = 2000
|
|
34
|
+
@use_ssl = false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# set_basic_auth()
|
|
38
|
+
# @param username the username credential
|
|
39
|
+
# @param password the password credential
|
|
40
|
+
def set_basic_auth(username, password)
|
|
41
|
+
@custom_headers['Authorization'] =
|
|
42
|
+
"Basic #{Base64.encode64(username + ':' + password)}".chomp
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# execute(). It helps execute an Http request
|
|
46
|
+
# one can use the following object:
|
|
47
|
+
# - HttpPost
|
|
48
|
+
# - HttpGet
|
|
49
|
+
# - HttpDelete
|
|
50
|
+
# - HttpPut
|
|
51
|
+
# @param http_webrequest the HttpRequest object
|
|
52
|
+
# @return HttpResponse object or an Http Error object
|
|
53
|
+
def execute(http_webrequest)
|
|
54
|
+
raise ArgumentError, 'http_webrequest is not a subclass of HttpRequest'
|
|
55
|
+
unless http_webrequest.is_a? HttpRequest
|
|
56
|
+
do_http_request(http_webrequest.path,
|
|
57
|
+
http_webrequest.http_method,
|
|
58
|
+
http_webrequest.content_type,
|
|
59
|
+
http_webrequest.accept, http_webrequest.content)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# post(). It helps send an HTTP POST request
|
|
63
|
+
# to create the specified resource
|
|
64
|
+
# @param path the resource path
|
|
65
|
+
# @param content_type the http request content type
|
|
66
|
+
# @param accept the expected mime type of the response
|
|
67
|
+
# @param content the http request payload
|
|
68
|
+
def post(path, content_type, accept, content = {})
|
|
69
|
+
execute HttpConnect::HttpPost.new(path, content_type, accept, content)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# put(). It helps send an HTTP PUT request
|
|
73
|
+
# to create or modified the specified resource
|
|
74
|
+
# @param path the resource path
|
|
75
|
+
# @param content_type the http request content type
|
|
76
|
+
# @param accept the expected mime type of the response
|
|
77
|
+
# @param content the http request payload
|
|
78
|
+
def put(path, content_type, accept, content = {})
|
|
79
|
+
execute HttpConnect::HttpPut.new(path, content_type, accept, content)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# get(). It helps send an HTTP GET request
|
|
83
|
+
# to fetch the specified resource
|
|
84
|
+
# @param path the resource path
|
|
85
|
+
# @param content_type the http request content type
|
|
86
|
+
# @param accept the expected mime type of the response
|
|
87
|
+
# @param content the http request payload
|
|
88
|
+
def get(path, accept, content = {})
|
|
89
|
+
execute HttpConnect::HttpGet.new(path, nil, accept, content)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# delete(). It helps send an HTTP DELETE request
|
|
93
|
+
# to delete the specified resource
|
|
94
|
+
# @param path the resource path
|
|
95
|
+
# @param content_type the http request content type
|
|
96
|
+
# @param accept the expected mime type of the response
|
|
97
|
+
# @param content the http request payload
|
|
98
|
+
def delete(path, accept, content = {})
|
|
99
|
+
execute HttpConnect::HttpDelete.new(path, nil, accept, content)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
# open_connection()
|
|
105
|
+
def open_connection(path)
|
|
106
|
+
URI.parse(@base_url + path)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# apply_headers().
|
|
110
|
+
# Helps apply all the custom http headers set.
|
|
111
|
+
def apply_headers(request)
|
|
112
|
+
@custom_headers.each do |key, value|
|
|
113
|
+
request.add_field key, value
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# do_http_request()
|
|
118
|
+
# Helps prepare and execute http web request
|
|
119
|
+
# @param path the resource path
|
|
120
|
+
# @param http_method the http verb used to access the resource
|
|
121
|
+
# @param content_type the content type used to access the resource
|
|
122
|
+
# @param accept the accept response header
|
|
123
|
+
# @param content the request payload
|
|
124
|
+
# @return HttpResponse instance
|
|
125
|
+
def do_http_request(path, http_method, content_type, accept, content = {})
|
|
126
|
+
uri = open_connection path
|
|
127
|
+
request = extract_request(uri, http_method)
|
|
128
|
+
request.content_type = content_type unless content_type.to_s.empty?
|
|
129
|
+
request['Accept'] = accept
|
|
130
|
+
apply_headers request
|
|
131
|
+
if (%w[POST PUT].include? http_method) && !content.empty?
|
|
132
|
+
handle_content request, content_type, content
|
|
133
|
+
end
|
|
134
|
+
fire_request(uri, request)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def handle_content(request, content_type, content)
|
|
138
|
+
case content_type
|
|
139
|
+
when DEFAULT_CONTENT_TYPE then
|
|
140
|
+
request.body = content.to_json
|
|
141
|
+
request.add_field 'Content-Length', request.body.size
|
|
142
|
+
when FORM_DATA then request.set_form_data(content)
|
|
143
|
+
else request.set_form_data(content)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# fire_request()
|
|
148
|
+
# @param uri the request URI object
|
|
149
|
+
# @param request the http request object
|
|
150
|
+
# @return HttpResponse instance
|
|
151
|
+
def fire_request(uri, request)
|
|
152
|
+
response = Net::HTTP.start(uri.host,
|
|
153
|
+
use_ssl: @use_ssl,
|
|
154
|
+
read_timeout: @read_write_timeout) do |http|
|
|
155
|
+
http.request(request)
|
|
156
|
+
end
|
|
157
|
+
extract_response response
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# extract_request()
|
|
161
|
+
# @param uri the request URI object
|
|
162
|
+
# @param http_method the request http method used
|
|
163
|
+
# @return the http request object
|
|
164
|
+
def extract_request(uri, http_method)
|
|
165
|
+
request = case http_method
|
|
166
|
+
when 'POST' then Net::HTTP::Post.new(uri)
|
|
167
|
+
when 'GET' then Net::HTTP::Get.new(uri)
|
|
168
|
+
when 'DELETE' then Net::HTTP::Delete.new(uri)
|
|
169
|
+
when 'PUT' then Net::HTTP::Put.new(uri)
|
|
170
|
+
else raise 'invalid http method'
|
|
171
|
+
end
|
|
172
|
+
request
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# extract_response()
|
|
176
|
+
# @param response the Net::HTTPResponse object to extract
|
|
177
|
+
def extract_response(response)
|
|
178
|
+
case response
|
|
179
|
+
when Net::HTTPSuccess, Net::HTTPRedirection then
|
|
180
|
+
HttpConnect::HttpResponse.new(response.code.to_i,
|
|
181
|
+
response.body, response.to_hash)
|
|
182
|
+
else
|
|
183
|
+
response.value
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'http_connect/http_request'
|
|
2
|
+
|
|
3
|
+
module HttpConnect
|
|
4
|
+
# HttpDelete class
|
|
5
|
+
class HttpDelete < HttpRequest
|
|
6
|
+
# initialize()
|
|
7
|
+
def initialize(path, content_type = 'application/json',
|
|
8
|
+
accept = 'application/json', content = {})
|
|
9
|
+
super(path, 'DELETE', content_type, accept, content)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'http_connect/http_request'
|
|
2
|
+
|
|
3
|
+
module HttpConnect
|
|
4
|
+
# HttpGet class
|
|
5
|
+
class HttpGet < HttpRequest
|
|
6
|
+
# initialize()
|
|
7
|
+
def initialize(path, content_type = 'application/json',
|
|
8
|
+
accept = 'application/json', content = {})
|
|
9
|
+
super(path, 'GET', content_type, accept, content)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'http_connect/http_request'
|
|
2
|
+
|
|
3
|
+
module HttpConnect
|
|
4
|
+
# HttpPost class
|
|
5
|
+
class HttpPost < HttpRequest
|
|
6
|
+
# initialize()
|
|
7
|
+
def initialize(path, content_type = 'application/json',
|
|
8
|
+
accept = 'application/json', content = {})
|
|
9
|
+
super(path, 'POST', content_type, accept, content)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'http_connect/http_request'
|
|
2
|
+
|
|
3
|
+
module HttpConnect
|
|
4
|
+
# HttpPut class
|
|
5
|
+
class HttpPut < HttpRequest
|
|
6
|
+
# initialize()
|
|
7
|
+
def initialize(path, content_type = 'application/json',
|
|
8
|
+
accept = 'application/json', content = {})
|
|
9
|
+
super(path, 'PUT', content_type, accept, content)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module HttpConnect
|
|
2
|
+
# HttpRequest class
|
|
3
|
+
class HttpRequest
|
|
4
|
+
attr_reader :path # resource path
|
|
5
|
+
attr_reader :http_method # http verb
|
|
6
|
+
attr_reader :accept # accept header for the response
|
|
7
|
+
attr_reader :content # payload
|
|
8
|
+
attr_reader :content_type # content type
|
|
9
|
+
|
|
10
|
+
# initialize()
|
|
11
|
+
def initialize(path, method, content_type = 'application/json',
|
|
12
|
+
accept = 'application/json', content = {})
|
|
13
|
+
@path = path
|
|
14
|
+
@http_method = method
|
|
15
|
+
@accept = accept
|
|
16
|
+
@content = content
|
|
17
|
+
@content_type = content_type
|
|
18
|
+
|
|
19
|
+
@path += '?' + URI.encode_www_form(@content) if %w[GET DELETE].include? @http_method
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module HttpConnect
|
|
2
|
+
# HttpResponse class
|
|
3
|
+
class HttpResponse
|
|
4
|
+
attr_reader :status_code # http status code
|
|
5
|
+
attr_reader :body # http response body
|
|
6
|
+
attr_reader :headers # http response headers
|
|
7
|
+
def initialize(status_code, body, headers = {})
|
|
8
|
+
@status_code = status_code
|
|
9
|
+
@body = body
|
|
10
|
+
@headers = headers
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: http_connect
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Arsene Tochemey GANDOTE
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-07-15 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.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.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: 0.10.1
|
|
69
|
+
description: Wrapper around the ruby Net::Http library
|
|
70
|
+
email:
|
|
71
|
+
- tochemey@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- .rspec
|
|
78
|
+
- .travis.yml
|
|
79
|
+
- CODE_OF_CONDUCT.md
|
|
80
|
+
- Gemfile
|
|
81
|
+
- LICENSE.txt
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- bin/console
|
|
85
|
+
- bin/setup
|
|
86
|
+
- http_connect.gemspec
|
|
87
|
+
- lib/http_connect.rb
|
|
88
|
+
- lib/http_connect/http_delete.rb
|
|
89
|
+
- lib/http_connect/http_get.rb
|
|
90
|
+
- lib/http_connect/http_post.rb
|
|
91
|
+
- lib/http_connect/http_put.rb
|
|
92
|
+
- lib/http_connect/http_request.rb
|
|
93
|
+
- lib/http_connect/http_response.rb
|
|
94
|
+
- lib/http_connect/version.rb
|
|
95
|
+
homepage: https://github.com/Tochemey/HttpConnect
|
|
96
|
+
licenses:
|
|
97
|
+
- MIT
|
|
98
|
+
metadata: {}
|
|
99
|
+
post_install_message:
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - '>='
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - '>='
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
requirements: []
|
|
114
|
+
rubyforge_project:
|
|
115
|
+
rubygems_version: 2.0.14.1
|
|
116
|
+
signing_key:
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: Basic Http Client.
|
|
119
|
+
test_files: []
|