hung_secondGem 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hung_secondGem.rb +4 -0
- data/lib/hung_secondGem/orange.rb +95 -0
- data/lib/hung_secondGem/version.rb +146 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0660f1104c04bb60d6e0013abff93b7ca6b03540
|
4
|
+
data.tar.gz: 393cf25b128f98ba0ce788bef34cdc2144a60b0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 121f681dfd1dee20c405f942a391a06b63d2e4541d76aa2d6fbcae29e03e38429aa543115948d10f1d28bb4db4bea22dcd4b3a604fc8312e9a9d68401df7ce4f
|
7
|
+
data.tar.gz: b2523358a1a49e89e24189a6ff2a3f9601fed766d796cc0db461d30934685f754da5d7fc6b52ffc96b739dca9ea72094af4f06766684d197d32ba27443130319
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Orange
|
4
|
+
class Error < StandardError; end
|
5
|
+
class Rest
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
attr_reader :response;
|
9
|
+
attr_reader :request
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(opts={})
|
15
|
+
mergeOpt opts
|
16
|
+
end
|
17
|
+
|
18
|
+
def mergeOpt(opts={})
|
19
|
+
self.class.default_options = self.class.default_options.merge(opts.to_hash)
|
20
|
+
puts self.class.default_options
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform_request(http_method, path, options={}, &block) #:nodoc:
|
24
|
+
method = eval("Net::HTTP::#{http_method.to_s.capitalize}")
|
25
|
+
options = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options.to_hash)
|
26
|
+
begin
|
27
|
+
if (!options[:debug_request].nil? && options[:debug_request].to_s.downcase.eql?("true"))
|
28
|
+
options = debugPass options
|
29
|
+
end
|
30
|
+
|
31
|
+
if (!options[:debug_request].nil? && options[:debug_request].to_s.downcase.eql?("false"))
|
32
|
+
options = debugErr options
|
33
|
+
end
|
34
|
+
|
35
|
+
process_headers(options)
|
36
|
+
process_cookies(options)
|
37
|
+
puts options
|
38
|
+
@response = HTTParty::Request.new(method, path, options).perform(&block)
|
39
|
+
|
40
|
+
rescue => e
|
41
|
+
puts "Rescued #{e.inspect}"
|
42
|
+
end
|
43
|
+
|
44
|
+
@response
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def response
|
49
|
+
raise Orange::Error.new('@response is null') if @response.nil?
|
50
|
+
@response
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_headers(options)
|
54
|
+
if options[:headers] && headers.any?
|
55
|
+
options[:headers] = headers.merge(options[:headers])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_cookies(options) #:nodoc:
|
60
|
+
return unless options[:cookies] || self.class.default_cookies.any?
|
61
|
+
options[:headers] ||= headers.dup
|
62
|
+
options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
|
63
|
+
end
|
64
|
+
|
65
|
+
def headers(h = {})
|
66
|
+
raise ArgumentError, 'Headers must an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
67
|
+
self.class.default_options[:headers] ||= {}
|
68
|
+
self.class.default_options[:headers].merge!(h.to_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def setHost(host)
|
72
|
+
self.class.base_uri host
|
73
|
+
end
|
74
|
+
|
75
|
+
def Host
|
76
|
+
self.class.base_uri
|
77
|
+
end
|
78
|
+
|
79
|
+
def setFollowRedirect(flag)
|
80
|
+
self.class.follow_redirects flag
|
81
|
+
end
|
82
|
+
|
83
|
+
def debugPass(opts={})
|
84
|
+
self.class.default_options[:debug_output] = $stdout
|
85
|
+
opts = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(opts.to_hash)
|
86
|
+
opts
|
87
|
+
end
|
88
|
+
|
89
|
+
def debugErr(opts={})
|
90
|
+
self.class.default_options[:debug_output] = $stderr
|
91
|
+
opts = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(opts.to_hash)
|
92
|
+
opts
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require_relative 'orange'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module HungSecondGem
|
6
|
+
|
7
|
+
VERSION = "0.1.1"
|
8
|
+
|
9
|
+
class Hola
|
10
|
+
include HTTParty
|
11
|
+
base_uri "http://192.168.86.154:9200"
|
12
|
+
default_timeout 10
|
13
|
+
attr_accessor :last_res
|
14
|
+
attr_reader :response
|
15
|
+
attr_reader :resquest
|
16
|
+
|
17
|
+
def initialize()
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(opts={})
|
21
|
+
mergeOpt opts
|
22
|
+
end
|
23
|
+
|
24
|
+
def mergeOpt(opts={})
|
25
|
+
self.class.default_options.merge(opts)
|
26
|
+
puts self.class.default_options
|
27
|
+
end
|
28
|
+
|
29
|
+
def setDebug
|
30
|
+
self.class.debug_output $stdout
|
31
|
+
self.class.debug_output $stderr
|
32
|
+
end
|
33
|
+
|
34
|
+
def perform_request(http_method, path, options={}, &block) #:nodoc:
|
35
|
+
method = eval("Net::HTTP::#{http_method.to_s.capitalize}")
|
36
|
+
options = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options)
|
37
|
+
|
38
|
+
process_headers(options)
|
39
|
+
process_cookies(options)
|
40
|
+
puts options
|
41
|
+
begin
|
42
|
+
@response = HTTParty::Request.new(method, path, options).perform(&block)
|
43
|
+
|
44
|
+
setDebug
|
45
|
+
rescue => e
|
46
|
+
puts "Rescued #{e.inspect}"
|
47
|
+
setDebug
|
48
|
+
end
|
49
|
+
|
50
|
+
@response
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_headers(options)
|
54
|
+
if options[:headers] && headers.any?
|
55
|
+
options[:headers] = headers.merge(options[:headers])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_cookies(options) #:nodoc:
|
60
|
+
return unless options[:cookies] || self.class.default_cookies.any?
|
61
|
+
options[:headers] ||= headers.dup
|
62
|
+
options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
|
63
|
+
end
|
64
|
+
|
65
|
+
def hello
|
66
|
+
puts "Hello Hung"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def foo
|
72
|
+
puts "Hello foo"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.included(base)
|
76
|
+
base.extend(ClassMethods)
|
77
|
+
end
|
78
|
+
|
79
|
+
module ClassMethods
|
80
|
+
def bar
|
81
|
+
puts 'class method'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
class Baz
|
88
|
+
include HungSecondGem
|
89
|
+
end
|
90
|
+
object = HungSecondGem::Hola.new
|
91
|
+
# object.mergeOpt(
|
92
|
+
# {
|
93
|
+
# host_name:'Cubert',
|
94
|
+
# base_uri: "http://abc",
|
95
|
+
# content_type: 'application/json',
|
96
|
+
# maintain_method_across_redirects: true,
|
97
|
+
# timeout: 30
|
98
|
+
# }
|
99
|
+
# )
|
100
|
+
#object.hello
|
101
|
+
|
102
|
+
#object.sendGet
|
103
|
+
object.perform_request "get", "/pe_log/pe_log/_search"
|
104
|
+
|
105
|
+
# Baz.bar
|
106
|
+
# response = HungSecondGem::Hola.get("http://192.168.86.154:9200/pe_log/pe_log/_search")
|
107
|
+
# puts response
|
108
|
+
#
|
109
|
+
# a_hash = Hash.new
|
110
|
+
# a_hash['a']=1
|
111
|
+
# a_hash['b']=2
|
112
|
+
# puts a_hash
|
113
|
+
|
114
|
+
orange = Orange::Rest.new({
|
115
|
+
base_uri: "http://192.168.86.154:9200",
|
116
|
+
content_type: 'application/json',
|
117
|
+
timeout: 60
|
118
|
+
})
|
119
|
+
|
120
|
+
key = 'content-type'
|
121
|
+
value = 'application/json'
|
122
|
+
h = Hash.new
|
123
|
+
h[key] = value
|
124
|
+
|
125
|
+
query = Hash.new
|
126
|
+
query['quantity'] = 12
|
127
|
+
query['nameSupplier'] = 'MONTHLY'
|
128
|
+
query['startTime'] = 1469790205194
|
129
|
+
query['endTime'] = 1483009405414
|
130
|
+
|
131
|
+
body = "{ \"endTime\": \"1480417405279\" }"
|
132
|
+
body_hash = JSON.parse(body)
|
133
|
+
|
134
|
+
opts = Hash.new
|
135
|
+
opts['query'] = query
|
136
|
+
opts['body'] = body_hash
|
137
|
+
# orange.headers({
|
138
|
+
# content_type: 'application/json'
|
139
|
+
# })
|
140
|
+
orange.headers(h)
|
141
|
+
orange.perform_request "get", "/pe_log/pe_log/_search", {}
|
142
|
+
puts orange.response.body
|
143
|
+
|
144
|
+
orange.setHost "http://192.168.86.154:9082"
|
145
|
+
orange.perform_request "put", "/logger/pe/prepareLogTables", opts
|
146
|
+
puts orange.response.body
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hung_secondGem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hung Thanh Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.10'
|
19
|
+
name: bundler
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.0'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.13'
|
47
|
+
name: httparty
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.5'
|
61
|
+
name: jsonpath
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
description: 'description: create second gem'
|
70
|
+
email:
|
71
|
+
- hungtnguyen@kms-technology.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/hung_secondGem.rb
|
77
|
+
- lib/hung_secondGem/orange.rb
|
78
|
+
- lib/hung_secondGem/version.rb
|
79
|
+
homepage: http://hungnguyen.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.5
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: create second gem
|
103
|
+
test_files: []
|