SimpleRequest 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.
- data/lib/SimpleRequest.rb +36 -0
- metadata +64 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
class SimpleRequest
|
4
|
+
attr_accessor :params,:url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@params={}
|
8
|
+
end
|
9
|
+
|
10
|
+
def post(format="normal")
|
11
|
+
url=URI(@url)
|
12
|
+
res=""
|
13
|
+
http=Net::HTTP
|
14
|
+
if format=="normal"
|
15
|
+
res=http.post_form(url,@params)
|
16
|
+
elsif format=="json"
|
17
|
+
json_data=JSON.generate(@params)
|
18
|
+
res=http.post_form(url,'json'=>json_data)
|
19
|
+
end
|
20
|
+
res.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(format="normal")
|
24
|
+
url=URI(@url)
|
25
|
+
res=Net::HTTP.get(url)
|
26
|
+
if format=="normal"
|
27
|
+
return res
|
28
|
+
elsif format=="json"
|
29
|
+
return JSON.parse(res)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_params
|
34
|
+
@params={}
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SimpleRequest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- YongYe Song
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-12-12 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A simple gem
|
22
|
+
email: terrorgeek@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/SimpleRequest.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://rubygems.org/gems/hola
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Simple, easy to use
|
63
|
+
test_files: []
|
64
|
+
|