easy_http_maker 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.
- checksums.yaml +7 -0
- data/lib/easy_http.rb +53 -0
- data/lib/easy_http/request/connection_adapter.rb +46 -0
- data/lib/easy_http/request/request_params.rb +19 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a9f5ab106f0f31b4a8080e84511edfeeaff9cf5
|
4
|
+
data.tar.gz: 330a54ab88c5c905c7721179138a4b005698a9f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29922f4d666f1619929bcfadb58a42d93f95765921bf328481fb8f3455c5fdf5c6482d245076ca83cdac5560eff9117315063c8f980f64f90298667a5ec15a59
|
7
|
+
data.tar.gz: 04cd77315b6151e8e62c1a354d0e763def732abbce1eaacc7701d9a22da32786925b9922571f3096dcefdf57306a88bf1ba80456f3b2d780a3343d5da7a06a34
|
data/lib/easy_http.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
require 'easy_http/request/connection_adapter'
|
7
|
+
require 'easy_http/request/request_params'
|
8
|
+
|
9
|
+
|
10
|
+
class EASY_HTTP
|
11
|
+
include Easy_http_Request
|
12
|
+
# attr_accessor :url
|
13
|
+
|
14
|
+
def self.get(url, options = {})
|
15
|
+
puts 'hello'
|
16
|
+
self.request_type Net::HTTP::Get, url, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.post(url, options = {})
|
20
|
+
self.request_type Net::HTTP::Post, url, options
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.put(url, options = {})
|
24
|
+
self.request_type Net::HTTP::Put, url, options
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.patch(url, options = {})
|
28
|
+
self.request_type Net::HTTP::Patch, url, options
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def params_paser
|
33
|
+
header_parse(self.params['headers'])
|
34
|
+
end
|
35
|
+
|
36
|
+
def body_parse
|
37
|
+
body_parser(self.params['body'])
|
38
|
+
end
|
39
|
+
|
40
|
+
def header_parse header = {}
|
41
|
+
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless header.respond_to?(:to_hash)
|
42
|
+
default_options[:headers].merge!(h.to_hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
def body_parser body ={}
|
46
|
+
body.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.request_type http_method, url, option
|
50
|
+
response = Easy_http_Request::Request.new(http_method, url, option).connect()
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'easy_http/response/response'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
module Send_request
|
9
|
+
class Connection_Adapter
|
10
|
+
# include Easy_http_Response
|
11
|
+
|
12
|
+
# attr_accessor :http_method, :options, :last_response, :redirect, :last_uri, :url
|
13
|
+
|
14
|
+
def self.connect http_method, url, options, limit = 10
|
15
|
+
raise ArgumentError, 'too many HTTP redirects' if limit == 0
|
16
|
+
@url = self.normalize_url url
|
17
|
+
uri = URI.parse @url
|
18
|
+
if uri.hostname.nil?
|
19
|
+
raise URI::InvalidURIError.new("bad URI(no host provided): #{url}")
|
20
|
+
end
|
21
|
+
|
22
|
+
request = http_method.new uri
|
23
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
24
|
+
http.request(request)
|
25
|
+
end
|
26
|
+
puts response['Content-Type']
|
27
|
+
case response
|
28
|
+
when Net::HTTPSuccess then self.response_parser response.body
|
29
|
+
when Net::HTTPRedirection then self.connect http_method,response['location'],nil, limit - 1
|
30
|
+
when Net::HTTPServerException then response = {'status': '405', 'message': 'Method Not Allowed'}
|
31
|
+
else
|
32
|
+
response.error!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.normalize_url url
|
37
|
+
url = 'http://' + url unless url.match(%r{\A[a-z][a-z0-9+.-]*://}i)
|
38
|
+
url
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.response_parser response
|
42
|
+
p_response = Easy_http_Response::Http_response.new(response).parse_body
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'easy_http/request/connection_adapter'
|
2
|
+
|
3
|
+
module Easy_http_Request
|
4
|
+
class Request
|
5
|
+
include Send_request
|
6
|
+
|
7
|
+
def initialize(http_method, url ,option = {})
|
8
|
+
raise ArgumentError, 'Http Method Not Found!' unless !http_method.nil?
|
9
|
+
raise ArgumentError, 'URL Not Found!' unless !url.nil?
|
10
|
+
@http_method = http_method
|
11
|
+
@option = option
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
def connect
|
16
|
+
response = Send_request::Connection_Adapter.connect(@http_method,@url,@option)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_http_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vipin Kumar
|
8
|
+
- Kushagra Sharma
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: An easy-to-use client library for making requests from Ruby. It uses
|
15
|
+
a simple method chaining system for building requests
|
16
|
+
email: vpnkumar.kumar1@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/easy_http.rb
|
22
|
+
- lib/easy_http/request/connection_adapter.rb
|
23
|
+
- lib/easy_http/request/request_params.rb
|
24
|
+
homepage: http://buffercode.in
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.6.11
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Esay Http
|
48
|
+
test_files: []
|