nice_http 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/LICENSE +21 -0
- data/README.md +217 -0
- data/lib/nice_http.rb +1083 -0
- data/lib/nice_http_utils.rb +98 -0
- metadata +71 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
module NiceHttpUtils
|
2
|
+
##################################################
|
3
|
+
# get a value of xml tag
|
4
|
+
# input:
|
5
|
+
# tag_name
|
6
|
+
# xml_string
|
7
|
+
# take_off_prefix: boolean (optional). true, false(default)
|
8
|
+
# output:
|
9
|
+
# the value or an array of all values found with this tag_name
|
10
|
+
####################################################
|
11
|
+
def self.get_value_xml_tag(tag_name, xml_string, take_off_prefix=false)
|
12
|
+
return nil if xml_string.nil?
|
13
|
+
xml_string2=xml_string.dup()
|
14
|
+
if take_off_prefix then
|
15
|
+
i=tag_name.index(":")
|
16
|
+
if !i.nil? then
|
17
|
+
tag_name=tag_name[i+1..tag_name.length]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ret=Array.new()
|
22
|
+
if xml_string2.to_s()!="" then
|
23
|
+
|
24
|
+
if take_off_prefix then
|
25
|
+
xml_string2.gsub!(/<[a-zA-Z0-9]+:#{tag_name} [^>]*>/i, "<" + tag_name + ">")
|
26
|
+
xml_string2.gsub!(/<\/[a-zA-Z0-9]+:#{tag_name}>/i, "</" + tag_name + ">")
|
27
|
+
xml_string2.gsub!(/<[a-zA-Z0-9]+:#{tag_name}>/i, "<" + tag_name + ">")
|
28
|
+
end
|
29
|
+
|
30
|
+
xml_string2.gsub!(/<#{tag_name} [^>]*>/i, "<" + tag_name + ">")
|
31
|
+
|
32
|
+
tag1="<" + tag_name + ">"
|
33
|
+
tag2="</" + tag_name + ">"
|
34
|
+
|
35
|
+
x=xml_string2.index(tag1)
|
36
|
+
if !x.nil? then
|
37
|
+
x+=tag1.size
|
38
|
+
begin
|
39
|
+
y=xml_string2.index(tag2)
|
40
|
+
if y.nil? then
|
41
|
+
ret.push("")
|
42
|
+
x=nil
|
43
|
+
else
|
44
|
+
y-=1
|
45
|
+
value=xml_string2[x..y]
|
46
|
+
ret.push(value)
|
47
|
+
xml_string2=xml_string2[y+tag2.size..xml_string2.length]
|
48
|
+
x=xml_string2.index(tag1)
|
49
|
+
if !x.nil? then
|
50
|
+
x+=tag1.size
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end while !x.nil?
|
54
|
+
else
|
55
|
+
ret.push("")
|
56
|
+
end
|
57
|
+
else
|
58
|
+
ret.push("")
|
59
|
+
end
|
60
|
+
if ret.size==1 then
|
61
|
+
return ret[0].to_s()
|
62
|
+
else
|
63
|
+
return ret
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
##################################################
|
69
|
+
# set a value on xml tag
|
70
|
+
# input:
|
71
|
+
# tag_name
|
72
|
+
# xml_string
|
73
|
+
# value
|
74
|
+
# take_off_prefix: boolean (optional). true, false(default)
|
75
|
+
# output:
|
76
|
+
# xml_string with the new value
|
77
|
+
####################################################
|
78
|
+
def self.set_value_xml_tag(tag_name, xml_string, value, take_off_prefix = false)
|
79
|
+
tag_name = tag_name.to_s
|
80
|
+
if take_off_prefix
|
81
|
+
i = tag_name.index(':')
|
82
|
+
tag_name = tag_name[i + 1..tag_name.length] unless i.nil?
|
83
|
+
end
|
84
|
+
if xml_string.to_s != ''
|
85
|
+
if take_off_prefix
|
86
|
+
old_value = NiceHttpUtils.get_value_xml_tag(tag_name, xml_string.dup, true)
|
87
|
+
xml_string.gsub!(/:#{tag_name}>#{Regexp.escape(old_value)}<\//i, ':' + tag_name + '>' + value + '</')
|
88
|
+
xml_string.gsub!(/<#{tag_name}>#{Regexp.escape(old_value)}<\//i, '<' + tag_name + '>' + value + '</')
|
89
|
+
else
|
90
|
+
xml_string.gsub!(/<#{tag_name}>.*<\/#{tag_name}>/i, '<' + tag_name + '>' + value + '</' + tag_name + '>')
|
91
|
+
end
|
92
|
+
return xml_string
|
93
|
+
else
|
94
|
+
return ''
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nice_http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mario Ruiz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nice_hash
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.0
|
33
|
+
description: Manage different hosts on the fly. Easily get the value you want from
|
34
|
+
the JSON strings. Use hashes on your requests.
|
35
|
+
email: marioruizs@gmail.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
files:
|
42
|
+
- ".yardopts"
|
43
|
+
- LICENSE
|
44
|
+
- README.md
|
45
|
+
- lib/nice_http.rb
|
46
|
+
- lib/nice_http_utils.rb
|
47
|
+
homepage: https://github.com/MarioRuiz/nice_http
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.7.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: NiceHttp -- simplest library for accessing and testing HTTP and REST resources.
|
71
|
+
test_files: []
|