Class: Gloo::Objs::HttpPost
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::HttpPost
- Defined in:
- lib/gloo/objs/web/http_post.rb
Constant Summary collapse
- KEYWORD =
'http_post'.freeze
- KEYWORD_SHORT =
'post'.freeze
- URL =
'uri'.freeze
- BODY =
'body'.freeze
- RESULT =
'result'.freeze
- SKIP_SSL_VERIFY =
'skip_ssl_verify'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.post_json(url, body, skip_ssl_verify = false) ⇒ Object
Post the content to the endpoint.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#body_as_json ⇒ Object
Get all the children of the body container and convert to JSON that will be sent in the HTTP body.
-
#msg_run ⇒ Object
Post the content to the endpoint.
-
#update_result(data) ⇒ Object
Set the result of the API call.
-
#uri_value ⇒ Object
Get the URI from the child object.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_responds_to?, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_value, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
100 101 102 |
# File 'lib/gloo/objs/web/http_post.rb', line 100 def self. return super + [ 'run' ] end |
.post_json(url, body, skip_ssl_verify = false) ⇒ Object
Post the content to the endpoint.
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gloo/objs/web/http_post.rb', line 128 def self.post_json( url, body, skip_ssl_verify = false ) uri = URI( url ) params = { use_ssl: uri.scheme == 'https' } params[ :verify_mode ] = ::OpenSSL::SSL::VERIFY_NONE if skip_ssl_verify Net::HTTP.start( uri.host, uri.port, params ) do |http| request = Net::HTTP::Post.new uri request.content_type = 'application/json' request.body = body return http.request( request ) # returns Net::HTTPResponse object end end |
.short_typename ⇒ Object
The short name of the object type.
31 32 33 |
# File 'lib/gloo/objs/web/http_post.rb', line 31 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
24 25 26 |
# File 'lib/gloo/objs/web/http_post.rb', line 24 def self.typename return KEYWORD end |
Instance Method Details
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
78 79 80 |
# File 'lib/gloo/objs/web/http_post.rb', line 78 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
87 88 89 90 91 |
# File 'lib/gloo/objs/web/http_post.rb', line 87 def add_default_children fac = @engine.factory fac.create_string URL, 'https://web.site/', self fac.create_can BODY, self end |
#body_as_json ⇒ Object
Get all the children of the body container and convert to JSON that will be sent in the HTTP body.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gloo/objs/web/http_post.rb', line 47 def body_as_json h = {} body = find_child_resolve_alias BODY body.children.each do |child| child_val = Gloo::Objs::Alias.resolve_alias( @engine, child ) h[ child.name ] = child_val.value end return h.to_json end |
#msg_run ⇒ Object
Post the content to the endpoint.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/gloo/objs/web/http_post.rb', line 107 def msg_run uri = uri_value return unless uri @engine.log.debug "posting to: #{uri}" body = self.body_as_json @engine.log.debug "posting body: #{body}" result = Gloo::Objs::HttpPost.post_json( uri, body, skip_ssl_verify? ) @engine.log.debug result.code @engine.log.debug result. self.update_result result.body end |
#update_result(data) ⇒ Object
Set the result of the API call.
62 63 64 65 66 67 |
# File 'lib/gloo/objs/web/http_post.rb', line 62 def update_result( data ) r = find_child_resolve_alias RESULT return unless r r.set_value data end |
#uri_value ⇒ Object
Get the URI from the child object. Returns nil if there is none.
39 40 41 |
# File 'lib/gloo/objs/web/http_post.rb', line 39 def uri_value return find_child_value URL end |