Class: EASY_HTTP

Inherits:
Object
  • Object
show all
Includes:
Easy_http_Request
Defined in:
lib/easy_http.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(url, options = {}) ⇒ Object

attr_accessor :url



14
15
16
17
# File 'lib/easy_http.rb', line 14

def self.get(url, options = {})
   puts 'hello'
   self.request_type Net::HTTP::Get, url, options
end

.patch(url, options = {}) ⇒ Object



27
28
29
# File 'lib/easy_http.rb', line 27

def self.patch(url, options = {})
   self.request_type Net::HTTP::Patch, url, options
end

.post(url, options = {}) ⇒ Object



19
20
21
# File 'lib/easy_http.rb', line 19

def self.post(url, options = {})
   self.request_type Net::HTTP::Post, url, options
end

.put(url, options = {}) ⇒ Object



23
24
25
# File 'lib/easy_http.rb', line 23

def self.put(url, options = {})
   self.request_type Net::HTTP::Put, url, options
end

.request_type(http_method, url, option) ⇒ Object



49
50
51
# File 'lib/easy_http.rb', line 49

def self.request_type http_method, url, option
  response =  Easy_http_Request::Request.new(http_method, url, option).connect()
end

Instance Method Details

#body_parseObject



36
37
38
# File 'lib/easy_http.rb', line 36

def body_parse
   body_parser(self.params['body'])
end

#body_parser(body = {}) ⇒ Object



45
46
47
# File 'lib/easy_http.rb', line 45

def body_parser body ={}
  body.to_json
end

#header_parse(header = {}) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
# File 'lib/easy_http.rb', line 40

def header_parse header = {}
  raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless header.respond_to?(:to_hash)
  default_options[:headers].merge!(h.to_hash)
end

#params_paserObject



32
33
34
# File 'lib/easy_http.rb', line 32

def params_paser
   header_parse(self.params['headers'])
end