rest_request 0.0.2 → 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.
Files changed (2) hide show
  1. data/lib/rest_request.rb +36 -7
  2. metadata +4 -4
data/lib/rest_request.rb CHANGED
@@ -1,9 +1,35 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Copyright (c) 2012 Hector Reyes Aleman <birkoff.h@gmail.com.com>
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.
23
+
24
+
1
25
  require 'rubygems'
2
26
  require 'net/http'
27
+ require 'uri'
3
28
 
4
29
  class RestRequest
5
-
6
- def send_request(method, url, data = nil)
30
+
31
+ def self.send_request(method, url, data = nil)
32
+ url = URI.parse(url)
7
33
  case method
8
34
  when "GET"
9
35
  req = Net::HTTP::Get.new(url.path)
@@ -15,14 +41,12 @@ class RestRequest
15
41
  req = Net::HTTP::Delete.new(url.path)
16
42
  end
17
43
 
18
- req.add_field "Accept", "application/json"
44
+ req.add_field "Accept", "application/json"
19
45
 
20
46
  if(defined? @headers) then
21
47
  @headers.each {|key, value| req.add_field key, value }
22
48
  end
23
49
 
24
- #req.add_field "Referer", $referer
25
-
26
50
  if(defined? data) then
27
51
  req.body = data
28
52
  end
@@ -34,11 +58,16 @@ class RestRequest
34
58
  return res.body
35
59
  end
36
60
 
37
- def set_header(name, value)
61
+ def self.set_header(name, value)
62
+ unless defined? @headers : @headers = Hash.new end
38
63
  @headers[name] = value
39
64
  end
65
+
66
+ def self.clear_headers
67
+ @headers = nil
68
+ end
40
69
 
41
- def print_json(data)
70
+ def self.print_json(data)
42
71
  level = 0
43
72
  arr = data.split("")
44
73
  i = 0
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hector Reyes Aleman
@@ -18,7 +18,7 @@ cert_chain: []
18
18
  date: 2012-07-09 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
- description: Simple tool to create Rest Request and print the JSON response
21
+ description: Simple tool to create any Rest Requests and print the JSON response
22
22
  email: birkoff.h@gmail.com
23
23
  executables: []
24
24
 
@@ -60,7 +60,7 @@ rubyforge_project:
60
60
  rubygems_version: 1.8.24
61
61
  signing_key:
62
62
  specification_version: 3
63
- summary: Simple tool to create Rest Request and print the JSON response
63
+ summary: Simple tool to create any Rest Requests and print the JSON response
64
64
  test_files: []
65
65
 
66
66
  has_rdoc: