repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
softlayer/softlayer-ruby | lib/softlayer/Account.rb | SoftLayer.Account.find_vlan_with_number | def find_vlan_with_number(vlan_number)
filter = SoftLayer::ObjectFilter.new() { |filter|
filter.accept('networkVlans.vlanNumber').when_it is vlan_number
}
vlan_data = self.service.object_mask("mask[id,vlanNumber,primaryRouter,networkSpace]").object_filter(filter).getNetworkVlans
return vlan_data
end | ruby | def find_vlan_with_number(vlan_number)
filter = SoftLayer::ObjectFilter.new() { |filter|
filter.accept('networkVlans.vlanNumber').when_it is vlan_number
}
vlan_data = self.service.object_mask("mask[id,vlanNumber,primaryRouter,networkSpace]").object_filter(filter).getNetworkVlans
return vlan_data
end | [
"def",
"find_vlan_with_number",
"(",
"vlan_number",
")",
"filter",
"=",
"SoftLayer",
"::",
"ObjectFilter",
".",
"new",
"(",
")",
"{",
"|",
"filter",
"|",
"filter",
".",
"accept",
"(",
"'networkVlans.vlanNumber'",
")",
".",
"when_it",
"is",
"vlan_number",
"}",
"vlan_data",
"=",
"self",
".",
"service",
".",
"object_mask",
"(",
"\"mask[id,vlanNumber,primaryRouter,networkSpace]\"",
")",
".",
"object_filter",
"(",
"filter",
")",
".",
"getNetworkVlans",
"return",
"vlan_data",
"end"
] | Searches the account's list of VLANs for the ones with the given
vlan number. This may return multiple results because a VLAN can
span different routers and you will get a separate segment for
each router.
The IDs of the different segments can be helpful for ordering
firewalls. | [
"Searches",
"the",
"account",
"s",
"list",
"of",
"VLANs",
"for",
"the",
"ones",
"with",
"the",
"given",
"vlan",
"number",
".",
"This",
"may",
"return",
"multiple",
"results",
"because",
"a",
"VLAN",
"can",
"span",
"different",
"routers",
"and",
"you",
"will",
"get",
"a",
"separate",
"segment",
"for",
"each",
"router",
"."
] | 48d7e0e36a3b02d832e7e303a513020a8fbde93b | https://github.com/softlayer/softlayer-ruby/blob/48d7e0e36a3b02d832e7e303a513020a8fbde93b/lib/softlayer/Account.rb#L267-L274 | train |
softlayer/softlayer-ruby | lib/softlayer/Client.rb | SoftLayer.Client.service_named | def service_named(service_name, service_options = {})
raise ArgumentError,"Please provide a service name" if service_name.nil? || service_name.empty?
# Strip whitespace from service_name and ensure that it starts with "SoftLayer_".
# If it does not, then add the prefix.
full_name = service_name.to_s.strip
if not full_name =~ /\ASoftLayer_/
full_name = "SoftLayer_#{service_name}"
end
# if we've already created this service, just return it
# otherwise create a new service
service_key = full_name.to_sym
if [email protected]_key?(service_key)
@services[service_key] = SoftLayer::Service.new(full_name, {:client => self}.merge(service_options))
end
@services[service_key]
end | ruby | def service_named(service_name, service_options = {})
raise ArgumentError,"Please provide a service name" if service_name.nil? || service_name.empty?
# Strip whitespace from service_name and ensure that it starts with "SoftLayer_".
# If it does not, then add the prefix.
full_name = service_name.to_s.strip
if not full_name =~ /\ASoftLayer_/
full_name = "SoftLayer_#{service_name}"
end
# if we've already created this service, just return it
# otherwise create a new service
service_key = full_name.to_sym
if [email protected]_key?(service_key)
@services[service_key] = SoftLayer::Service.new(full_name, {:client => self}.merge(service_options))
end
@services[service_key]
end | [
"def",
"service_named",
"(",
"service_name",
",",
"service_options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"\"Please provide a service name\"",
"if",
"service_name",
".",
"nil?",
"||",
"service_name",
".",
"empty?",
"full_name",
"=",
"service_name",
".",
"to_s",
".",
"strip",
"if",
"not",
"full_name",
"=~",
"/",
"\\A",
"/",
"full_name",
"=",
"\"SoftLayer_#{service_name}\"",
"end",
"service_key",
"=",
"full_name",
".",
"to_sym",
"if",
"!",
"@services",
".",
"has_key?",
"(",
"service_key",
")",
"@services",
"[",
"service_key",
"]",
"=",
"SoftLayer",
"::",
"Service",
".",
"new",
"(",
"full_name",
",",
"{",
":client",
"=>",
"self",
"}",
".",
"merge",
"(",
"service_options",
")",
")",
"end",
"@services",
"[",
"service_key",
"]",
"end"
] | Returns a service with the given name.
If a service has already been created by this client that same service
will be returned each time it is called for by name. Otherwise the system
will try to construct a new service object and return that.
If the service has to be created then the service_options will be passed
along to the creative function. However, when returning a previously created
Service, the service_options will be ignored.
If the service_name provided does not start with 'SoftLayer_' that prefix
will be added | [
"Returns",
"a",
"service",
"with",
"the",
"given",
"name",
"."
] | 48d7e0e36a3b02d832e7e303a513020a8fbde93b | https://github.com/softlayer/softlayer-ruby/blob/48d7e0e36a3b02d832e7e303a513020a8fbde93b/lib/softlayer/Client.rb#L170-L188 | train |
softlayer/softlayer-ruby | lib/softlayer/Service.rb | SoftLayer.Service.call_softlayer_api_with_params | def call_softlayer_api_with_params(method_name, parameters, args)
additional_headers = {};
# The client knows about authentication, so ask him for the auth headers
authentication_headers = self.client.authentication_headers
additional_headers.merge!(authentication_headers)
if parameters && parameters.server_object_filter
additional_headers.merge!("#{@service_name}ObjectFilter" => parameters.server_object_filter)
end
# Object masks go into the headers too.
if parameters && parameters.server_object_mask
object_mask = parameters.server_object_mask
additional_headers.merge!("SoftLayer_ObjectMask" => { "mask" => object_mask }) unless object_mask.empty?
end
# Result limits go into the headers
if (parameters && parameters.server_result_limit)
additional_headers.merge!("resultLimit" => { "limit" => parameters.server_result_limit, "offset" => (parameters.server_result_offset || 0) })
end
# Add an object id to the headers.
if parameters && parameters.server_object_id
additional_headers.merge!("#{@service_name}InitParameters" => { "id" => parameters.server_object_id })
end
# This is a workaround for a potential problem that arises from mis-using the
# API. If you call SoftLayer_Virtual_Guest and you call the getObject method
# but pass a virtual guest as a parameter, what happens is the getObject method
# is called through an HTTP POST verb and the API creates a new VirtualServer that
# is a copy of the one you passed in.
#
# The counter-intuitive creation of a new Virtual Server is unexpected and, even worse,
# is something you can be billed for. To prevent that, we ignore the request
# body on a "getObject" call and print out a warning.
if (method_name == :getObject) && (nil != args) && (!args.empty?) then
$stderr.puts "Warning - The getObject method takes no parameters. The parameters you have provided will be ignored."
args = nil
end
# Collect all the different header pieces into a single hash that
# will become the first argument to the call.
call_headers = {
"headers" => additional_headers
}
begin
call_value = xmlrpc_client.call(method_name.to_s, call_headers, *args)
rescue XMLRPC::FaultException => e
puts "A XMLRPC Fault was returned #{e}" if $DEBUG
raise
end
return call_value
end | ruby | def call_softlayer_api_with_params(method_name, parameters, args)
additional_headers = {};
# The client knows about authentication, so ask him for the auth headers
authentication_headers = self.client.authentication_headers
additional_headers.merge!(authentication_headers)
if parameters && parameters.server_object_filter
additional_headers.merge!("#{@service_name}ObjectFilter" => parameters.server_object_filter)
end
# Object masks go into the headers too.
if parameters && parameters.server_object_mask
object_mask = parameters.server_object_mask
additional_headers.merge!("SoftLayer_ObjectMask" => { "mask" => object_mask }) unless object_mask.empty?
end
# Result limits go into the headers
if (parameters && parameters.server_result_limit)
additional_headers.merge!("resultLimit" => { "limit" => parameters.server_result_limit, "offset" => (parameters.server_result_offset || 0) })
end
# Add an object id to the headers.
if parameters && parameters.server_object_id
additional_headers.merge!("#{@service_name}InitParameters" => { "id" => parameters.server_object_id })
end
# This is a workaround for a potential problem that arises from mis-using the
# API. If you call SoftLayer_Virtual_Guest and you call the getObject method
# but pass a virtual guest as a parameter, what happens is the getObject method
# is called through an HTTP POST verb and the API creates a new VirtualServer that
# is a copy of the one you passed in.
#
# The counter-intuitive creation of a new Virtual Server is unexpected and, even worse,
# is something you can be billed for. To prevent that, we ignore the request
# body on a "getObject" call and print out a warning.
if (method_name == :getObject) && (nil != args) && (!args.empty?) then
$stderr.puts "Warning - The getObject method takes no parameters. The parameters you have provided will be ignored."
args = nil
end
# Collect all the different header pieces into a single hash that
# will become the first argument to the call.
call_headers = {
"headers" => additional_headers
}
begin
call_value = xmlrpc_client.call(method_name.to_s, call_headers, *args)
rescue XMLRPC::FaultException => e
puts "A XMLRPC Fault was returned #{e}" if $DEBUG
raise
end
return call_value
end | [
"def",
"call_softlayer_api_with_params",
"(",
"method_name",
",",
"parameters",
",",
"args",
")",
"additional_headers",
"=",
"{",
"}",
";",
"authentication_headers",
"=",
"self",
".",
"client",
".",
"authentication_headers",
"additional_headers",
".",
"merge!",
"(",
"authentication_headers",
")",
"if",
"parameters",
"&&",
"parameters",
".",
"server_object_filter",
"additional_headers",
".",
"merge!",
"(",
"\"#{@service_name}ObjectFilter\"",
"=>",
"parameters",
".",
"server_object_filter",
")",
"end",
"if",
"parameters",
"&&",
"parameters",
".",
"server_object_mask",
"object_mask",
"=",
"parameters",
".",
"server_object_mask",
"additional_headers",
".",
"merge!",
"(",
"\"SoftLayer_ObjectMask\"",
"=>",
"{",
"\"mask\"",
"=>",
"object_mask",
"}",
")",
"unless",
"object_mask",
".",
"empty?",
"end",
"if",
"(",
"parameters",
"&&",
"parameters",
".",
"server_result_limit",
")",
"additional_headers",
".",
"merge!",
"(",
"\"resultLimit\"",
"=>",
"{",
"\"limit\"",
"=>",
"parameters",
".",
"server_result_limit",
",",
"\"offset\"",
"=>",
"(",
"parameters",
".",
"server_result_offset",
"||",
"0",
")",
"}",
")",
"end",
"if",
"parameters",
"&&",
"parameters",
".",
"server_object_id",
"additional_headers",
".",
"merge!",
"(",
"\"#{@service_name}InitParameters\"",
"=>",
"{",
"\"id\"",
"=>",
"parameters",
".",
"server_object_id",
"}",
")",
"end",
"if",
"(",
"method_name",
"==",
":getObject",
")",
"&&",
"(",
"nil",
"!=",
"args",
")",
"&&",
"(",
"!",
"args",
".",
"empty?",
")",
"then",
"$stderr",
".",
"puts",
"\"Warning - The getObject method takes no parameters. The parameters you have provided will be ignored.\"",
"args",
"=",
"nil",
"end",
"call_headers",
"=",
"{",
"\"headers\"",
"=>",
"additional_headers",
"}",
"begin",
"call_value",
"=",
"xmlrpc_client",
".",
"call",
"(",
"method_name",
".",
"to_s",
",",
"call_headers",
",",
"*",
"args",
")",
"rescue",
"XMLRPC",
"::",
"FaultException",
"=>",
"e",
"puts",
"\"A XMLRPC Fault was returned #{e}\"",
"if",
"$DEBUG",
"raise",
"end",
"return",
"call_value",
"end"
] | Issue an HTTP request to call the given method from the SoftLayer API with
the parameters and arguments given.
Parameters are information _about_ the call, the object mask or the
particular object in the SoftLayer API you are calling.
Arguments are the arguments to the SoftLayer method that you wish to
invoke.
This is intended to be used in the internal
processing of method_missing and need not be called directly. | [
"Issue",
"an",
"HTTP",
"request",
"to",
"call",
"the",
"given",
"method",
"from",
"the",
"SoftLayer",
"API",
"with",
"the",
"parameters",
"and",
"arguments",
"given",
"."
] | 48d7e0e36a3b02d832e7e303a513020a8fbde93b | https://github.com/softlayer/softlayer-ruby/blob/48d7e0e36a3b02d832e7e303a513020a8fbde93b/lib/softlayer/Service.rb#L221-L276 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.set_bios_settings | def set_bios_settings(options, system_id = 1)
r = response_handler(rest_patch("/redfish/v1/Systems/#{system_id}/bios/Settings/", body: options))
@logger.warn(r) if r['error']
true
end | ruby | def set_bios_settings(options, system_id = 1)
r = response_handler(rest_patch("/redfish/v1/Systems/#{system_id}/bios/Settings/", body: options))
@logger.warn(r) if r['error']
true
end | [
"def",
"set_bios_settings",
"(",
"options",
",",
"system_id",
"=",
"1",
")",
"r",
"=",
"response_handler",
"(",
"rest_patch",
"(",
"\"/redfish/v1/Systems/#{system_id}/bios/Settings/\"",
",",
"body",
":",
"options",
")",
")",
"@logger",
".",
"warn",
"(",
"r",
")",
"if",
"r",
"[",
"'error'",
"]",
"true",
"end"
] | Set BIOS settings
@param options [Hash] Hash of options to set
@param system_id [Integer, String] ID of the system
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"BIOS",
"settings"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L28-L32 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.set_uefi_shell_startup | def set_uefi_shell_startup(uefi_shell_startup, uefi_shell_startup_location, uefi_shell_startup_url)
new_action = {
'UefiShellStartup' => uefi_shell_startup,
'UefiShellStartupLocation' => uefi_shell_startup_location,
'UefiShellStartupUrl' => uefi_shell_startup_url
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | ruby | def set_uefi_shell_startup(uefi_shell_startup, uefi_shell_startup_location, uefi_shell_startup_url)
new_action = {
'UefiShellStartup' => uefi_shell_startup,
'UefiShellStartupLocation' => uefi_shell_startup_location,
'UefiShellStartupUrl' => uefi_shell_startup_url
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_uefi_shell_startup",
"(",
"uefi_shell_startup",
",",
"uefi_shell_startup_location",
",",
"uefi_shell_startup_url",
")",
"new_action",
"=",
"{",
"'UefiShellStartup'",
"=>",
"uefi_shell_startup",
",",
"'UefiShellStartupLocation'",
"=>",
"uefi_shell_startup_location",
",",
"'UefiShellStartupUrl'",
"=>",
"uefi_shell_startup_url",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/bios/Settings/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the UEFI shell start up
@param uefi_shell_startup [String, Symbol]
@param uefi_shell_startup_location [String, Symbol]
@param uefi_shell_startup_url [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"UEFI",
"shell",
"start",
"up"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L71-L80 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.get_bios_dhcp | def get_bios_dhcp
response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
bios = response_handler(response)
{
'Dhcpv4' => bios['Dhcpv4'],
'Ipv4Address' => bios['Ipv4Address'],
'Ipv4Gateway' => bios['Ipv4Gateway'],
'Ipv4PrimaryDNS' => bios['Ipv4PrimaryDNS'],
'Ipv4SecondaryDNS' => bios['Ipv4SecondaryDNS'],
'Ipv4SubnetMask' => bios['Ipv4SubnetMask']
}
end | ruby | def get_bios_dhcp
response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
bios = response_handler(response)
{
'Dhcpv4' => bios['Dhcpv4'],
'Ipv4Address' => bios['Ipv4Address'],
'Ipv4Gateway' => bios['Ipv4Gateway'],
'Ipv4PrimaryDNS' => bios['Ipv4PrimaryDNS'],
'Ipv4SecondaryDNS' => bios['Ipv4SecondaryDNS'],
'Ipv4SubnetMask' => bios['Ipv4SubnetMask']
}
end | [
"def",
"get_bios_dhcp",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Systems/1/bios/Settings/'",
")",
"bios",
"=",
"response_handler",
"(",
"response",
")",
"{",
"'Dhcpv4'",
"=>",
"bios",
"[",
"'Dhcpv4'",
"]",
",",
"'Ipv4Address'",
"=>",
"bios",
"[",
"'Ipv4Address'",
"]",
",",
"'Ipv4Gateway'",
"=>",
"bios",
"[",
"'Ipv4Gateway'",
"]",
",",
"'Ipv4PrimaryDNS'",
"=>",
"bios",
"[",
"'Ipv4PrimaryDNS'",
"]",
",",
"'Ipv4SecondaryDNS'",
"=>",
"bios",
"[",
"'Ipv4SecondaryDNS'",
"]",
",",
"'Ipv4SubnetMask'",
"=>",
"bios",
"[",
"'Ipv4SubnetMask'",
"]",
"}",
"end"
] | Get the BIOS DHCP
@raise [RuntimeError] if the request failed
@return [String] bios_dhcp | [
"Get",
"the",
"BIOS",
"DHCP"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L85-L96 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.set_bios_dhcp | def set_bios_dhcp(dhcpv4, ipv4_address = '', ipv4_gateway = '', ipv4_primary_dns = '', ipv4_secondary_dns = '', ipv4_subnet_mask = '')
new_action = {
'Dhcpv4' => dhcpv4,
'Ipv4Address' => ipv4_address,
'Ipv4Gateway' => ipv4_gateway,
'Ipv4PrimaryDNS' => ipv4_primary_dns,
'Ipv4SecondaryDNS' => ipv4_secondary_dns,
'Ipv4SubnetMask' => ipv4_subnet_mask
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | ruby | def set_bios_dhcp(dhcpv4, ipv4_address = '', ipv4_gateway = '', ipv4_primary_dns = '', ipv4_secondary_dns = '', ipv4_subnet_mask = '')
new_action = {
'Dhcpv4' => dhcpv4,
'Ipv4Address' => ipv4_address,
'Ipv4Gateway' => ipv4_gateway,
'Ipv4PrimaryDNS' => ipv4_primary_dns,
'Ipv4SecondaryDNS' => ipv4_secondary_dns,
'Ipv4SubnetMask' => ipv4_subnet_mask
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_bios_dhcp",
"(",
"dhcpv4",
",",
"ipv4_address",
"=",
"''",
",",
"ipv4_gateway",
"=",
"''",
",",
"ipv4_primary_dns",
"=",
"''",
",",
"ipv4_secondary_dns",
"=",
"''",
",",
"ipv4_subnet_mask",
"=",
"''",
")",
"new_action",
"=",
"{",
"'Dhcpv4'",
"=>",
"dhcpv4",
",",
"'Ipv4Address'",
"=>",
"ipv4_address",
",",
"'Ipv4Gateway'",
"=>",
"ipv4_gateway",
",",
"'Ipv4PrimaryDNS'",
"=>",
"ipv4_primary_dns",
",",
"'Ipv4SecondaryDNS'",
"=>",
"ipv4_secondary_dns",
",",
"'Ipv4SubnetMask'",
"=>",
"ipv4_subnet_mask",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/bios/Settings/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the BIOS DHCP
@param dhcpv4 [String, Symbol]
@param ipv4_address [String, Symbol]
@param ipv4_gateway [String, Symbol]
@param ipv4_primary_dns [String, Symbol]
@param ipv4_secondary_dns [String, Symbol]
@param ipv4_subnet_mask [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"BIOS",
"DHCP"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L107-L119 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.set_url_boot_file | def set_url_boot_file(url_boot_file)
new_action = { 'UrlBootFile' => url_boot_file }
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | ruby | def set_url_boot_file(url_boot_file)
new_action = { 'UrlBootFile' => url_boot_file }
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_url_boot_file",
"(",
"url_boot_file",
")",
"new_action",
"=",
"{",
"'UrlBootFile'",
"=>",
"url_boot_file",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/bios/Settings/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the URL boot file
@param url_boot_file [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"URL",
"boot",
"file"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L133-L138 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/bios_helper.rb | ILO_SDK.BiosHelper.set_bios_service | def set_bios_service(name, email)
new_action = {
'ServiceName' => name,
'ServiceEmail' => email
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | ruby | def set_bios_service(name, email)
new_action = {
'ServiceName' => name,
'ServiceEmail' => email
}
response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_bios_service",
"(",
"name",
",",
"email",
")",
"new_action",
"=",
"{",
"'ServiceName'",
"=>",
"name",
",",
"'ServiceEmail'",
"=>",
"email",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/bios/Settings/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the BIOS service
@param name [String, Symbol]
@param email [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"BIOS",
"service"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/bios_helper.rb#L157-L165 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/log_entry_helper.rb | ILO_SDK.LogEntryHelper.clear_logs | def clear_logs(log_type)
new_action = { 'Action' => 'ClearLog' }
response = rest_post(uri_for_log_type(log_type), body: new_action)
response_handler(response)
true
end | ruby | def clear_logs(log_type)
new_action = { 'Action' => 'ClearLog' }
response = rest_post(uri_for_log_type(log_type), body: new_action)
response_handler(response)
true
end | [
"def",
"clear_logs",
"(",
"log_type",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'ClearLog'",
"}",
"response",
"=",
"rest_post",
"(",
"uri_for_log_type",
"(",
"log_type",
")",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Clear the specified logs
@param [String, Symbol] log_type
@raise [RuntimeError] if the request failed
@return true | [
"Clear",
"the",
"specified",
"logs"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/log_entry_helper.rb#L34-L39 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/log_entry_helper.rb | ILO_SDK.LogEntryHelper.get_logs | def get_logs(severity_level, duration, log_type)
response = rest_get("#{uri_for_log_type(log_type)}Entries/")
entries = response_handler(response)['Items']
start_time = Time.now.utc - (duration * 3600)
if severity_level.nil?
entries.select { |e| Time.parse(e['Created']) > start_time }
else
entries.select { |e| severity_level.to_s.casecmp(e['Severity']) == 0 && Time.parse(e['Created']) > start_time }
end
end | ruby | def get_logs(severity_level, duration, log_type)
response = rest_get("#{uri_for_log_type(log_type)}Entries/")
entries = response_handler(response)['Items']
start_time = Time.now.utc - (duration * 3600)
if severity_level.nil?
entries.select { |e| Time.parse(e['Created']) > start_time }
else
entries.select { |e| severity_level.to_s.casecmp(e['Severity']) == 0 && Time.parse(e['Created']) > start_time }
end
end | [
"def",
"get_logs",
"(",
"severity_level",
",",
"duration",
",",
"log_type",
")",
"response",
"=",
"rest_get",
"(",
"\"#{uri_for_log_type(log_type)}Entries/\"",
")",
"entries",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"start_time",
"=",
"Time",
".",
"now",
".",
"utc",
"-",
"(",
"duration",
"*",
"3600",
")",
"if",
"severity_level",
".",
"nil?",
"entries",
".",
"select",
"{",
"|",
"e",
"|",
"Time",
".",
"parse",
"(",
"e",
"[",
"'Created'",
"]",
")",
">",
"start_time",
"}",
"else",
"entries",
".",
"select",
"{",
"|",
"e",
"|",
"severity_level",
".",
"to_s",
".",
"casecmp",
"(",
"e",
"[",
"'Severity'",
"]",
")",
"==",
"0",
"&&",
"Time",
".",
"parse",
"(",
"e",
"[",
"'Created'",
"]",
")",
">",
"start_time",
"}",
"end",
"end"
] | Get the specified logs
@param [String, Symbol, NilClass] severity_level Set to nil to get all logs
@param [String, Symbol] duration Up to this many hours ago
@param [String, Symbol] log_type IEL or IML
@raise [RuntimeError] if the request failed
@return [Array] log entries | [
"Get",
"the",
"specified",
"logs"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/log_entry_helper.rb#L56-L65 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/computer_details_helper.rb | ILO_SDK.ComputerDetailsHelper.get_computer_details | def get_computer_details
general_computer_details = get_general_computer_details
computer_network_details = get_computer_network_details
array_controller_details = get_array_controller_details
general_computer_details.merge(computer_network_details).merge(array_controller_details)
end | ruby | def get_computer_details
general_computer_details = get_general_computer_details
computer_network_details = get_computer_network_details
array_controller_details = get_array_controller_details
general_computer_details.merge(computer_network_details).merge(array_controller_details)
end | [
"def",
"get_computer_details",
"general_computer_details",
"=",
"get_general_computer_details",
"computer_network_details",
"=",
"get_computer_network_details",
"array_controller_details",
"=",
"get_array_controller_details",
"general_computer_details",
".",
"merge",
"(",
"computer_network_details",
")",
".",
"merge",
"(",
"array_controller_details",
")",
"end"
] | Get all of the computer details
@raise [RuntimeError] if the request failed
@return [Hash] computer_details | [
"Get",
"all",
"of",
"the",
"computer",
"details"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/computer_details_helper.rb#L18-L23 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/computer_details_helper.rb | ILO_SDK.ComputerDetailsHelper.get_general_computer_details | def get_general_computer_details
response = rest_get('/redfish/v1/Systems/1/')
details = response_handler(response)
{
'GeneralDetails' => {
'manufacturer' => details['Manufacturer'],
'model' => details['Model'],
'AssetTag' => details['AssetTag'],
'bios_version' => details['Bios']['Current']['VersionString'],
'memory' => details['Memory']['TotalSystemMemoryGB'].to_s + ' GB',
'processors' => details['Processors']['Count'].to_s + ' x ' + details['Processors']['ProcessorFamily'].to_s
}
}
end | ruby | def get_general_computer_details
response = rest_get('/redfish/v1/Systems/1/')
details = response_handler(response)
{
'GeneralDetails' => {
'manufacturer' => details['Manufacturer'],
'model' => details['Model'],
'AssetTag' => details['AssetTag'],
'bios_version' => details['Bios']['Current']['VersionString'],
'memory' => details['Memory']['TotalSystemMemoryGB'].to_s + ' GB',
'processors' => details['Processors']['Count'].to_s + ' x ' + details['Processors']['ProcessorFamily'].to_s
}
}
end | [
"def",
"get_general_computer_details",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Systems/1/'",
")",
"details",
"=",
"response_handler",
"(",
"response",
")",
"{",
"'GeneralDetails'",
"=>",
"{",
"'manufacturer'",
"=>",
"details",
"[",
"'Manufacturer'",
"]",
",",
"'model'",
"=>",
"details",
"[",
"'Model'",
"]",
",",
"'AssetTag'",
"=>",
"details",
"[",
"'AssetTag'",
"]",
",",
"'bios_version'",
"=>",
"details",
"[",
"'Bios'",
"]",
"[",
"'Current'",
"]",
"[",
"'VersionString'",
"]",
",",
"'memory'",
"=>",
"details",
"[",
"'Memory'",
"]",
"[",
"'TotalSystemMemoryGB'",
"]",
".",
"to_s",
"+",
"' GB'",
",",
"'processors'",
"=>",
"details",
"[",
"'Processors'",
"]",
"[",
"'Count'",
"]",
".",
"to_s",
"+",
"' x '",
"+",
"details",
"[",
"'Processors'",
"]",
"[",
"'ProcessorFamily'",
"]",
".",
"to_s",
"}",
"}",
"end"
] | Get the general computer details
@raise [RuntimeError] if the request failed
@return [Fixnum] general_computer_details | [
"Get",
"the",
"general",
"computer",
"details"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/computer_details_helper.rb#L28-L41 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/computer_details_helper.rb | ILO_SDK.ComputerDetailsHelper.get_computer_network_details | def get_computer_network_details
network_adapters = []
response = rest_get('/redfish/v1/Systems/1/NetworkAdapters/')
networks = response_handler(response)['links']['Member']
networks.each do |network|
response = rest_get(network['href'])
detail = response_handler(response)
physical_ports = []
detail['PhysicalPorts'].each do |port|
n = {
'Name' => port['Name'],
'StructuredName' => port['Oem']['Hp']['StructuredName'],
'MacAddress' => port['MacAddress'],
'State' => port['Status']['State']
}
physical_ports.push(n)
end
nets = {
'Name' => detail['Name'],
'StructuredName' => detail['StructuredName'],
'PartNumber' => detail['PartNumber'],
'State' => detail['Status']['State'],
'Health' => detail['Status']['Health'],
'PhysicalPorts' => physical_ports
}
network_adapters.push(nets)
end
{
'NetworkAdapters' => network_adapters
}
end | ruby | def get_computer_network_details
network_adapters = []
response = rest_get('/redfish/v1/Systems/1/NetworkAdapters/')
networks = response_handler(response)['links']['Member']
networks.each do |network|
response = rest_get(network['href'])
detail = response_handler(response)
physical_ports = []
detail['PhysicalPorts'].each do |port|
n = {
'Name' => port['Name'],
'StructuredName' => port['Oem']['Hp']['StructuredName'],
'MacAddress' => port['MacAddress'],
'State' => port['Status']['State']
}
physical_ports.push(n)
end
nets = {
'Name' => detail['Name'],
'StructuredName' => detail['StructuredName'],
'PartNumber' => detail['PartNumber'],
'State' => detail['Status']['State'],
'Health' => detail['Status']['Health'],
'PhysicalPorts' => physical_ports
}
network_adapters.push(nets)
end
{
'NetworkAdapters' => network_adapters
}
end | [
"def",
"get_computer_network_details",
"network_adapters",
"=",
"[",
"]",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Systems/1/NetworkAdapters/'",
")",
"networks",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'links'",
"]",
"[",
"'Member'",
"]",
"networks",
".",
"each",
"do",
"|",
"network",
"|",
"response",
"=",
"rest_get",
"(",
"network",
"[",
"'href'",
"]",
")",
"detail",
"=",
"response_handler",
"(",
"response",
")",
"physical_ports",
"=",
"[",
"]",
"detail",
"[",
"'PhysicalPorts'",
"]",
".",
"each",
"do",
"|",
"port",
"|",
"n",
"=",
"{",
"'Name'",
"=>",
"port",
"[",
"'Name'",
"]",
",",
"'StructuredName'",
"=>",
"port",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'StructuredName'",
"]",
",",
"'MacAddress'",
"=>",
"port",
"[",
"'MacAddress'",
"]",
",",
"'State'",
"=>",
"port",
"[",
"'Status'",
"]",
"[",
"'State'",
"]",
"}",
"physical_ports",
".",
"push",
"(",
"n",
")",
"end",
"nets",
"=",
"{",
"'Name'",
"=>",
"detail",
"[",
"'Name'",
"]",
",",
"'StructuredName'",
"=>",
"detail",
"[",
"'StructuredName'",
"]",
",",
"'PartNumber'",
"=>",
"detail",
"[",
"'PartNumber'",
"]",
",",
"'State'",
"=>",
"detail",
"[",
"'Status'",
"]",
"[",
"'State'",
"]",
",",
"'Health'",
"=>",
"detail",
"[",
"'Status'",
"]",
"[",
"'Health'",
"]",
",",
"'PhysicalPorts'",
"=>",
"physical_ports",
"}",
"network_adapters",
".",
"push",
"(",
"nets",
")",
"end",
"{",
"'NetworkAdapters'",
"=>",
"network_adapters",
"}",
"end"
] | Get the computer network details
@raise [RuntimeError] if the request failed
@return [Hash] computer_network_details | [
"Get",
"the",
"computer",
"network",
"details"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/computer_details_helper.rb#L46-L76 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/firmware_update.rb | ILO_SDK.FirmwareUpdateHelper.set_fw_upgrade | def set_fw_upgrade(uri, tpm_override_flag = true)
new_action = { 'Action' => 'InstallFromURI', 'FirmwareURI' => uri, 'TPMOverrideFlag' => tpm_override_flag }
response = rest_post('/redfish/v1/Managers/1/UpdateService/', body: new_action)
response_handler(response)
true
end | ruby | def set_fw_upgrade(uri, tpm_override_flag = true)
new_action = { 'Action' => 'InstallFromURI', 'FirmwareURI' => uri, 'TPMOverrideFlag' => tpm_override_flag }
response = rest_post('/redfish/v1/Managers/1/UpdateService/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_fw_upgrade",
"(",
"uri",
",",
"tpm_override_flag",
"=",
"true",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'InstallFromURI'",
",",
"'FirmwareURI'",
"=>",
"uri",
",",
"'TPMOverrideFlag'",
"=>",
"tpm_override_flag",
"}",
"response",
"=",
"rest_post",
"(",
"'/redfish/v1/Managers/1/UpdateService/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the Firmware Upgrade
@param [String, Symbol] uri
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"Firmware",
"Upgrade"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/firmware_update.rb#L27-L32 | train |
petebrowne/sprockets-helpers | lib/sprockets/helpers.rb | Sprockets.Helpers.asset_path | def asset_path(source, options = {})
uri = URI.parse(source)
return source if uri.absolute?
options[:prefix] = Sprockets::Helpers.prefix unless options[:prefix]
if Helpers.debug || options[:debug]
options[:manifest] = false
options[:digest] = false
options[:asset_host] = false
end
source_ext = File.extname(source)
if options[:ext] && source_ext != ".#{options[:ext]}"
uri.path << ".#{options[:ext]}"
end
path = find_asset_path(uri, source, options)
if options[:expand] && path.respond_to?(:to_a)
path.to_a
else
path.to_s
end
end | ruby | def asset_path(source, options = {})
uri = URI.parse(source)
return source if uri.absolute?
options[:prefix] = Sprockets::Helpers.prefix unless options[:prefix]
if Helpers.debug || options[:debug]
options[:manifest] = false
options[:digest] = false
options[:asset_host] = false
end
source_ext = File.extname(source)
if options[:ext] && source_ext != ".#{options[:ext]}"
uri.path << ".#{options[:ext]}"
end
path = find_asset_path(uri, source, options)
if options[:expand] && path.respond_to?(:to_a)
path.to_a
else
path.to_s
end
end | [
"def",
"asset_path",
"(",
"source",
",",
"options",
"=",
"{",
"}",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"source",
")",
"return",
"source",
"if",
"uri",
".",
"absolute?",
"options",
"[",
":prefix",
"]",
"=",
"Sprockets",
"::",
"Helpers",
".",
"prefix",
"unless",
"options",
"[",
":prefix",
"]",
"if",
"Helpers",
".",
"debug",
"||",
"options",
"[",
":debug",
"]",
"options",
"[",
":manifest",
"]",
"=",
"false",
"options",
"[",
":digest",
"]",
"=",
"false",
"options",
"[",
":asset_host",
"]",
"=",
"false",
"end",
"source_ext",
"=",
"File",
".",
"extname",
"(",
"source",
")",
"if",
"options",
"[",
":ext",
"]",
"&&",
"source_ext",
"!=",
"\".#{options[:ext]}\"",
"uri",
".",
"path",
"<<",
"\".#{options[:ext]}\"",
"end",
"path",
"=",
"find_asset_path",
"(",
"uri",
",",
"source",
",",
"options",
")",
"if",
"options",
"[",
":expand",
"]",
"&&",
"path",
".",
"respond_to?",
"(",
":to_a",
")",
"path",
".",
"to_a",
"else",
"path",
".",
"to_s",
"end",
"end"
] | Returns the path to an asset either in the Sprockets environment
or the public directory. External URIs are untouched.
==== Options
* <tt>:ext</tt> - The extension to append if the source does not have one.
* <tt>:dir</tt> - The directory to prepend if the file is in the public directory.
* <tt>:digest</tt> - Wether or not use the digest paths for assets. Set Sprockets::Helpers.digest for global configuration.
* <tt>:prefix</tt> - Use a custom prefix for the Sprockets environment. Set Sprockets::Helpers.prefix for global configuration.
* <tt>:body</tt> - Adds a ?body=1 flag that tells Sprockets to return only the body of the asset.
==== Examples
For files within Sprockets:
asset_path 'xmlhr.js' # => '/assets/xmlhr.js'
asset_path 'xmlhr', :ext => 'js' # => '/assets/xmlhr.js'
asset_path 'xmlhr.js', :digest => true # => '/assets/xmlhr-27a8f1f96afd8d4c67a59eb9447f45bd.js'
asset_path 'xmlhr.js', :prefix => '/themes' # => '/themes/xmlhr.js'
For files outside of Sprockets:
asset_path 'xmlhr' # => '/xmlhr'
asset_path 'xmlhr', :ext => 'js' # => '/xmlhr.js'
asset_path 'dir/xmlhr.js', :dir => 'javascripts' # => '/javascripts/dir/xmlhr.js'
asset_path '/dir/xmlhr.js', :dir => 'javascripts' # => '/dir/xmlhr.js'
asset_path 'http://www.example.com/js/xmlhr' # => 'http://www.example.com/js/xmlhr'
asset_path 'http://www.example.com/js/xmlhr.js' # => 'http://www.example.com/js/xmlhr.js' | [
"Returns",
"the",
"path",
"to",
"an",
"asset",
"either",
"in",
"the",
"Sprockets",
"environment",
"or",
"the",
"public",
"directory",
".",
"External",
"URIs",
"are",
"untouched",
"."
] | e3b952a392345432046ef7016bf60c502eb370ae | https://github.com/petebrowne/sprockets-helpers/blob/e3b952a392345432046ef7016bf60c502eb370ae/lib/sprockets/helpers.rb#L127-L151 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/chassis_helper.rb | ILO_SDK.ChassisHelper.get_power_metrics | def get_power_metrics
chassis = rest_get('/redfish/v1/Chassis/')
chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
power_metrics_uri = response_handler(rest_get(chassis_uri))['links']['PowerMetrics']['href']
response = rest_get(power_metrics_uri)
metrics = response_handler(response)
power_supplies = []
metrics['PowerSupplies'].each do |ps|
power_supply = {
'LineInputVoltage' => ps['LineInputVoltage'],
'LineInputVoltageType' => ps['LineInputVoltageType'],
'PowerCapacityWatts' => ps['PowerCapacityWatts'],
'PowerSupplyType' => ps['PowerSupplyType'],
'Health' => ps['Status']['Health'],
'State' => ps['Status']['State']
}
power_supplies.push(power_supply)
end
{
@host => {
'PowerCapacityWatts' => metrics['PowerCapacityWatts'],
'PowerConsumedWatts' => metrics['PowerConsumedWatts'],
'PowerSupplies' => power_supplies
}
}
end | ruby | def get_power_metrics
chassis = rest_get('/redfish/v1/Chassis/')
chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
power_metrics_uri = response_handler(rest_get(chassis_uri))['links']['PowerMetrics']['href']
response = rest_get(power_metrics_uri)
metrics = response_handler(response)
power_supplies = []
metrics['PowerSupplies'].each do |ps|
power_supply = {
'LineInputVoltage' => ps['LineInputVoltage'],
'LineInputVoltageType' => ps['LineInputVoltageType'],
'PowerCapacityWatts' => ps['PowerCapacityWatts'],
'PowerSupplyType' => ps['PowerSupplyType'],
'Health' => ps['Status']['Health'],
'State' => ps['Status']['State']
}
power_supplies.push(power_supply)
end
{
@host => {
'PowerCapacityWatts' => metrics['PowerCapacityWatts'],
'PowerConsumedWatts' => metrics['PowerConsumedWatts'],
'PowerSupplies' => power_supplies
}
}
end | [
"def",
"get_power_metrics",
"chassis",
"=",
"rest_get",
"(",
"'/redfish/v1/Chassis/'",
")",
"chassis_uri",
"=",
"response_handler",
"(",
"chassis",
")",
"[",
"'links'",
"]",
"[",
"'Member'",
"]",
"[",
"0",
"]",
"[",
"'href'",
"]",
"power_metrics_uri",
"=",
"response_handler",
"(",
"rest_get",
"(",
"chassis_uri",
")",
")",
"[",
"'links'",
"]",
"[",
"'PowerMetrics'",
"]",
"[",
"'href'",
"]",
"response",
"=",
"rest_get",
"(",
"power_metrics_uri",
")",
"metrics",
"=",
"response_handler",
"(",
"response",
")",
"power_supplies",
"=",
"[",
"]",
"metrics",
"[",
"'PowerSupplies'",
"]",
".",
"each",
"do",
"|",
"ps",
"|",
"power_supply",
"=",
"{",
"'LineInputVoltage'",
"=>",
"ps",
"[",
"'LineInputVoltage'",
"]",
",",
"'LineInputVoltageType'",
"=>",
"ps",
"[",
"'LineInputVoltageType'",
"]",
",",
"'PowerCapacityWatts'",
"=>",
"ps",
"[",
"'PowerCapacityWatts'",
"]",
",",
"'PowerSupplyType'",
"=>",
"ps",
"[",
"'PowerSupplyType'",
"]",
",",
"'Health'",
"=>",
"ps",
"[",
"'Status'",
"]",
"[",
"'Health'",
"]",
",",
"'State'",
"=>",
"ps",
"[",
"'Status'",
"]",
"[",
"'State'",
"]",
"}",
"power_supplies",
".",
"push",
"(",
"power_supply",
")",
"end",
"{",
"@host",
"=>",
"{",
"'PowerCapacityWatts'",
"=>",
"metrics",
"[",
"'PowerCapacityWatts'",
"]",
",",
"'PowerConsumedWatts'",
"=>",
"metrics",
"[",
"'PowerConsumedWatts'",
"]",
",",
"'PowerSupplies'",
"=>",
"power_supplies",
"}",
"}",
"end"
] | Get the power metrics
@raise [RuntimeError] if the request failed
@return [Hash] power_metrics | [
"Get",
"the",
"power",
"metrics"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/chassis_helper.rb#L18-L43 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/chassis_helper.rb | ILO_SDK.ChassisHelper.get_thermal_metrics | def get_thermal_metrics
chassis = rest_get('/redfish/v1/Chassis/')
chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
thermal_metrics_uri = response_handler(rest_get(chassis_uri))['links']['ThermalMetrics']['href']
response = rest_get(thermal_metrics_uri)
temperatures = response_handler(response)['Temperatures']
temp_details = []
temperatures.each do |temp|
temp_detail = {
'PhysicalContext' => temp['PhysicalContext'],
'Name' => temp['Name'],
'CurrentReading' => temp['ReadingCelsius'],
'CriticalThreshold' => temp['LowerThresholdCritical'],
'Health' => temp['Status']['Health'],
'State' => temp['Status']['State']
}
temp_details.push(temp_detail)
end
{ @host => temp_details }
end | ruby | def get_thermal_metrics
chassis = rest_get('/redfish/v1/Chassis/')
chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
thermal_metrics_uri = response_handler(rest_get(chassis_uri))['links']['ThermalMetrics']['href']
response = rest_get(thermal_metrics_uri)
temperatures = response_handler(response)['Temperatures']
temp_details = []
temperatures.each do |temp|
temp_detail = {
'PhysicalContext' => temp['PhysicalContext'],
'Name' => temp['Name'],
'CurrentReading' => temp['ReadingCelsius'],
'CriticalThreshold' => temp['LowerThresholdCritical'],
'Health' => temp['Status']['Health'],
'State' => temp['Status']['State']
}
temp_details.push(temp_detail)
end
{ @host => temp_details }
end | [
"def",
"get_thermal_metrics",
"chassis",
"=",
"rest_get",
"(",
"'/redfish/v1/Chassis/'",
")",
"chassis_uri",
"=",
"response_handler",
"(",
"chassis",
")",
"[",
"'links'",
"]",
"[",
"'Member'",
"]",
"[",
"0",
"]",
"[",
"'href'",
"]",
"thermal_metrics_uri",
"=",
"response_handler",
"(",
"rest_get",
"(",
"chassis_uri",
")",
")",
"[",
"'links'",
"]",
"[",
"'ThermalMetrics'",
"]",
"[",
"'href'",
"]",
"response",
"=",
"rest_get",
"(",
"thermal_metrics_uri",
")",
"temperatures",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Temperatures'",
"]",
"temp_details",
"=",
"[",
"]",
"temperatures",
".",
"each",
"do",
"|",
"temp",
"|",
"temp_detail",
"=",
"{",
"'PhysicalContext'",
"=>",
"temp",
"[",
"'PhysicalContext'",
"]",
",",
"'Name'",
"=>",
"temp",
"[",
"'Name'",
"]",
",",
"'CurrentReading'",
"=>",
"temp",
"[",
"'ReadingCelsius'",
"]",
",",
"'CriticalThreshold'",
"=>",
"temp",
"[",
"'LowerThresholdCritical'",
"]",
",",
"'Health'",
"=>",
"temp",
"[",
"'Status'",
"]",
"[",
"'Health'",
"]",
",",
"'State'",
"=>",
"temp",
"[",
"'Status'",
"]",
"[",
"'State'",
"]",
"}",
"temp_details",
".",
"push",
"(",
"temp_detail",
")",
"end",
"{",
"@host",
"=>",
"temp_details",
"}",
"end"
] | Get the thermal metrics
@raise [RuntimeError] if the request failed
@return [Hash] thermal_metrics | [
"Get",
"the",
"thermal",
"metrics"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/chassis_helper.rb#L48-L67 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/date_time_helper.rb | ILO_SDK.DateTimeHelper.set_time_zone | def set_time_zone(time_zone)
time_response = rest_get('/redfish/v1/Managers/1/DateTime/')
new_time_zone = response_handler(time_response)['TimeZoneList'].select { |timezone| timezone['Name'] == time_zone }
new_action = { 'TimeZone' => { 'Index' => new_time_zone[0]['Index'] } }
response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
response_handler(response)
true
end | ruby | def set_time_zone(time_zone)
time_response = rest_get('/redfish/v1/Managers/1/DateTime/')
new_time_zone = response_handler(time_response)['TimeZoneList'].select { |timezone| timezone['Name'] == time_zone }
new_action = { 'TimeZone' => { 'Index' => new_time_zone[0]['Index'] } }
response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_time_zone",
"(",
"time_zone",
")",
"time_response",
"=",
"rest_get",
"(",
"'/redfish/v1/Managers/1/DateTime/'",
")",
"new_time_zone",
"=",
"response_handler",
"(",
"time_response",
")",
"[",
"'TimeZoneList'",
"]",
".",
"select",
"{",
"|",
"timezone",
"|",
"timezone",
"[",
"'Name'",
"]",
"==",
"time_zone",
"}",
"new_action",
"=",
"{",
"'TimeZone'",
"=>",
"{",
"'Index'",
"=>",
"new_time_zone",
"[",
"0",
"]",
"[",
"'Index'",
"]",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Managers/1/DateTime/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the Time Zone
@param [Fixnum] time_zone
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"Time",
"Zone"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/date_time_helper.rb#L27-L34 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/date_time_helper.rb | ILO_SDK.DateTimeHelper.set_ntp | def set_ntp(use_ntp)
new_action = { 'Oem' => { 'Hp' => { 'DHCPv4' => { 'UseNTPServers' => use_ntp } } } }
response = rest_patch('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: new_action)
response_handler(response)
true
end | ruby | def set_ntp(use_ntp)
new_action = { 'Oem' => { 'Hp' => { 'DHCPv4' => { 'UseNTPServers' => use_ntp } } } }
response = rest_patch('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_ntp",
"(",
"use_ntp",
")",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'DHCPv4'",
"=>",
"{",
"'UseNTPServers'",
"=>",
"use_ntp",
"}",
"}",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Managers/1/EthernetInterfaces/1/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set whether or not ntp servers are being used
@param [TrueClass, FalseClass] use_ntp
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"whether",
"or",
"not",
"ntp",
"servers",
"are",
"being",
"used"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/date_time_helper.rb#L48-L53 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/date_time_helper.rb | ILO_SDK.DateTimeHelper.set_ntp_servers | def set_ntp_servers(ntp_servers)
new_action = { 'StaticNTPServers' => ntp_servers }
response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
response_handler(response)
true
end | ruby | def set_ntp_servers(ntp_servers)
new_action = { 'StaticNTPServers' => ntp_servers }
response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_ntp_servers",
"(",
"ntp_servers",
")",
"new_action",
"=",
"{",
"'StaticNTPServers'",
"=>",
"ntp_servers",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Managers/1/DateTime/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the NTP Servers
@param [Fixnum] ntp_servers
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"NTP",
"Servers"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/date_time_helper.rb#L67-L72 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/cli.rb | ILO_SDK.Cli.output | def output(data = {}, indent = 0)
case @options['format']
when 'json'
puts JSON.pretty_generate(data)
when 'yaml'
puts data.to_yaml
else
# rubocop:disable Metrics/BlockNesting
if data.class == Hash
data.each do |k, v|
if v.class == Hash || v.class == Array
puts "#{' ' * indent}#{k.nil? ? 'nil' : k}:"
output(v, indent + 2)
else
puts "#{' ' * indent}#{k.nil? ? 'nil' : k}: #{v.nil? ? 'nil' : v}"
end
end
elsif data.class == Array
data.each do |d|
if d.class == Hash || d.class == Array
output(d, indent + 2)
else
puts "#{' ' * indent}#{d.nil? ? 'nil' : d}"
end
end
puts "\nTotal: #{data.size}" if indent < 1
else
puts "#{' ' * indent}#{data.nil? ? 'nil' : data}"
end
# rubocop:enable Metrics/BlockNesting
end
end | ruby | def output(data = {}, indent = 0)
case @options['format']
when 'json'
puts JSON.pretty_generate(data)
when 'yaml'
puts data.to_yaml
else
# rubocop:disable Metrics/BlockNesting
if data.class == Hash
data.each do |k, v|
if v.class == Hash || v.class == Array
puts "#{' ' * indent}#{k.nil? ? 'nil' : k}:"
output(v, indent + 2)
else
puts "#{' ' * indent}#{k.nil? ? 'nil' : k}: #{v.nil? ? 'nil' : v}"
end
end
elsif data.class == Array
data.each do |d|
if d.class == Hash || d.class == Array
output(d, indent + 2)
else
puts "#{' ' * indent}#{d.nil? ? 'nil' : d}"
end
end
puts "\nTotal: #{data.size}" if indent < 1
else
puts "#{' ' * indent}#{data.nil? ? 'nil' : data}"
end
# rubocop:enable Metrics/BlockNesting
end
end | [
"def",
"output",
"(",
"data",
"=",
"{",
"}",
",",
"indent",
"=",
"0",
")",
"case",
"@options",
"[",
"'format'",
"]",
"when",
"'json'",
"puts",
"JSON",
".",
"pretty_generate",
"(",
"data",
")",
"when",
"'yaml'",
"puts",
"data",
".",
"to_yaml",
"else",
"if",
"data",
".",
"class",
"==",
"Hash",
"data",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"if",
"v",
".",
"class",
"==",
"Hash",
"||",
"v",
".",
"class",
"==",
"Array",
"puts",
"\"#{' ' * indent}#{k.nil? ? 'nil' : k}:\"",
"output",
"(",
"v",
",",
"indent",
"+",
"2",
")",
"else",
"puts",
"\"#{' ' * indent}#{k.nil? ? 'nil' : k}: #{v.nil? ? 'nil' : v}\"",
"end",
"end",
"elsif",
"data",
".",
"class",
"==",
"Array",
"data",
".",
"each",
"do",
"|",
"d",
"|",
"if",
"d",
".",
"class",
"==",
"Hash",
"||",
"d",
".",
"class",
"==",
"Array",
"output",
"(",
"d",
",",
"indent",
"+",
"2",
")",
"else",
"puts",
"\"#{' ' * indent}#{d.nil? ? 'nil' : d}\"",
"end",
"end",
"puts",
"\"\\nTotal: #{data.size}\"",
"if",
"indent",
"<",
"1",
"else",
"puts",
"\"#{' ' * indent}#{data.nil? ? 'nil' : data}\"",
"end",
"end",
"end"
] | Print output in a given format. | [
"Print",
"output",
"in",
"a",
"given",
"format",
"."
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/cli.rb#L223-L254 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/boot_settings_helper.rb | ILO_SDK.BootSettingsHelper.set_boot_order | def set_boot_order(boot_order)
new_action = { 'PersistentBootConfigOrder' => boot_order }
response = rest_patch('/redfish/v1/systems/1/bios/Boot/Settings/', body: new_action)
response_handler(response)
true
end | ruby | def set_boot_order(boot_order)
new_action = { 'PersistentBootConfigOrder' => boot_order }
response = rest_patch('/redfish/v1/systems/1/bios/Boot/Settings/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_boot_order",
"(",
"boot_order",
")",
"new_action",
"=",
"{",
"'PersistentBootConfigOrder'",
"=>",
"boot_order",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/systems/1/bios/Boot/Settings/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the boot order
@param [Fixnum] boot_order
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"boot",
"order"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/boot_settings_helper.rb#L45-L50 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/boot_settings_helper.rb | ILO_SDK.BootSettingsHelper.set_temporary_boot_order | def set_temporary_boot_order(boot_target)
response = rest_get('/redfish/v1/Systems/1/')
boottargets = response_handler(response)['Boot']['BootSourceOverrideSupported']
unless boottargets.include? boot_target
raise "BootSourceOverrideTarget value - #{boot_target} is not supported. Valid values are: #{boottargets}"
end
new_action = { 'Boot' => { 'BootSourceOverrideTarget' => boot_target } }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | ruby | def set_temporary_boot_order(boot_target)
response = rest_get('/redfish/v1/Systems/1/')
boottargets = response_handler(response)['Boot']['BootSourceOverrideSupported']
unless boottargets.include? boot_target
raise "BootSourceOverrideTarget value - #{boot_target} is not supported. Valid values are: #{boottargets}"
end
new_action = { 'Boot' => { 'BootSourceOverrideTarget' => boot_target } }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_temporary_boot_order",
"(",
"boot_target",
")",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Systems/1/'",
")",
"boottargets",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Boot'",
"]",
"[",
"'BootSourceOverrideSupported'",
"]",
"unless",
"boottargets",
".",
"include?",
"boot_target",
"raise",
"\"BootSourceOverrideTarget value - #{boot_target} is not supported. Valid values are: #{boottargets}\"",
"end",
"new_action",
"=",
"{",
"'Boot'",
"=>",
"{",
"'BootSourceOverrideTarget'",
"=>",
"boot_target",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the temporary boot order
@param [Fixnum] boot_target
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"temporary",
"boot",
"order"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/boot_settings_helper.rb#L64-L74 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/service_root_helper.rb | ILO_SDK.ServiceRootHelper.get_schema | def get_schema(schema_prefix)
response = rest_get('/redfish/v1/Schemas/')
schemas = response_handler(response)['Items']
schema = schemas.select { |s| s['Schema'].start_with?(schema_prefix) }
raise "NO schema found with this schema prefix : #{schema_prefix}" if schema.empty?
info = []
schema.each do |sc|
response = rest_get(sc['Location'][0]['Uri']['extref'])
schema_store = response_handler(response)
info.push(schema_store)
end
info
end | ruby | def get_schema(schema_prefix)
response = rest_get('/redfish/v1/Schemas/')
schemas = response_handler(response)['Items']
schema = schemas.select { |s| s['Schema'].start_with?(schema_prefix) }
raise "NO schema found with this schema prefix : #{schema_prefix}" if schema.empty?
info = []
schema.each do |sc|
response = rest_get(sc['Location'][0]['Uri']['extref'])
schema_store = response_handler(response)
info.push(schema_store)
end
info
end | [
"def",
"get_schema",
"(",
"schema_prefix",
")",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Schemas/'",
")",
"schemas",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"schema",
"=",
"schemas",
".",
"select",
"{",
"|",
"s",
"|",
"s",
"[",
"'Schema'",
"]",
".",
"start_with?",
"(",
"schema_prefix",
")",
"}",
"raise",
"\"NO schema found with this schema prefix : #{schema_prefix}\"",
"if",
"schema",
".",
"empty?",
"info",
"=",
"[",
"]",
"schema",
".",
"each",
"do",
"|",
"sc",
"|",
"response",
"=",
"rest_get",
"(",
"sc",
"[",
"'Location'",
"]",
"[",
"0",
"]",
"[",
"'Uri'",
"]",
"[",
"'extref'",
"]",
")",
"schema_store",
"=",
"response_handler",
"(",
"response",
")",
"info",
".",
"push",
"(",
"schema_store",
")",
"end",
"info",
"end"
] | Get the schema information with given prefix
@param [String, Symbol] schema_prefix
@raise [RuntimeError] if the request failed
@return [Array] schema | [
"Get",
"the",
"schema",
"information",
"with",
"given",
"prefix"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/service_root_helper.rb#L19-L31 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/service_root_helper.rb | ILO_SDK.ServiceRootHelper.get_registry | def get_registry(registry_prefix)
response = rest_get('/redfish/v1/Registries/')
registries = response_handler(response)['Items']
registry = registries.select { |reg| reg['Schema'].start_with?(registry_prefix) }
info = []
registry.each do |reg|
response = rest_get(reg['Location'][0]['Uri']['extref'])
registry_store = response_handler(response)
info.push(registry_store)
end
info
end | ruby | def get_registry(registry_prefix)
response = rest_get('/redfish/v1/Registries/')
registries = response_handler(response)['Items']
registry = registries.select { |reg| reg['Schema'].start_with?(registry_prefix) }
info = []
registry.each do |reg|
response = rest_get(reg['Location'][0]['Uri']['extref'])
registry_store = response_handler(response)
info.push(registry_store)
end
info
end | [
"def",
"get_registry",
"(",
"registry_prefix",
")",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Registries/'",
")",
"registries",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"registry",
"=",
"registries",
".",
"select",
"{",
"|",
"reg",
"|",
"reg",
"[",
"'Schema'",
"]",
".",
"start_with?",
"(",
"registry_prefix",
")",
"}",
"info",
"=",
"[",
"]",
"registry",
".",
"each",
"do",
"|",
"reg",
"|",
"response",
"=",
"rest_get",
"(",
"reg",
"[",
"'Location'",
"]",
"[",
"0",
"]",
"[",
"'Uri'",
"]",
"[",
"'extref'",
"]",
")",
"registry_store",
"=",
"response_handler",
"(",
"response",
")",
"info",
".",
"push",
"(",
"registry_store",
")",
"end",
"info",
"end"
] | Get the Registry with given registry_prefix
@param [String, Symbol] registry_prefix
@raise [RuntimeError] if the request failed
@return [Array] registry | [
"Get",
"the",
"Registry",
"with",
"given",
"registry_prefix"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/service_root_helper.rb#L37-L48 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/manager_network_protocol_helper.rb | ILO_SDK.ManagerNetworkProtocolHelper.set_timeout | def set_timeout(timeout)
new_action = { 'SessionTimeoutMinutes' => timeout }
response = rest_patch('/redfish/v1/Managers/1/NetworkService/', body: new_action)
response_handler(response)
true
end | ruby | def set_timeout(timeout)
new_action = { 'SessionTimeoutMinutes' => timeout }
response = rest_patch('/redfish/v1/Managers/1/NetworkService/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_timeout",
"(",
"timeout",
")",
"new_action",
"=",
"{",
"'SessionTimeoutMinutes'",
"=>",
"timeout",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Managers/1/NetworkService/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the Session Timeout Minutes
@param [Fixnum] timeout
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"Session",
"Timeout",
"Minutes"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/manager_network_protocol_helper.rb#L27-L32 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/ethernet_interface_helper.rb | ILO_SDK.EthernetInterfaceHelper.set_ilo_ipv4_dhcp | def set_ilo_ipv4_dhcp(manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => {
'Hp' => {
'DHCPv4' => {
'Enabled' => true,
'UseDNSServers' => true,
'UseDomainName' => true,
'UseGateway' => true,
'UseNTPServers' => true,
'UseStaticRoutes' => true,
'UseWINSServers' => true
}
}
}
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | ruby | def set_ilo_ipv4_dhcp(manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => {
'Hp' => {
'DHCPv4' => {
'Enabled' => true,
'UseDNSServers' => true,
'UseDomainName' => true,
'UseGateway' => true,
'UseNTPServers' => true,
'UseStaticRoutes' => true,
'UseWINSServers' => true
}
}
}
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | [
"def",
"set_ilo_ipv4_dhcp",
"(",
"manager_id",
":",
"1",
",",
"ethernet_interface",
":",
"1",
")",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'DHCPv4'",
"=>",
"{",
"'Enabled'",
"=>",
"true",
",",
"'UseDNSServers'",
"=>",
"true",
",",
"'UseDomainName'",
"=>",
"true",
",",
"'UseGateway'",
"=>",
"true",
",",
"'UseNTPServers'",
"=>",
"true",
",",
"'UseStaticRoutes'",
"=>",
"true",
",",
"'UseWINSServers'",
"=>",
"true",
"}",
"}",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"\"/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set EthernetInterface to obtain IPv4 settings from DHCP
@param manager_id [Integer, String] ID of the Manager
@param ethernet_interface [Integer, String] ID of the EthernetInterface
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"EthernetInterface",
"to",
"obtain",
"IPv4",
"settings",
"from",
"DHCP"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/ethernet_interface_helper.rb#L29-L48 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/ethernet_interface_helper.rb | ILO_SDK.EthernetInterfaceHelper.set_ilo_ipv4_static | def set_ilo_ipv4_static(ip:, netmask:, gateway: '0.0.0.0', manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => { 'Hp' => { 'DHCPv4' => { 'Enabled' => false } } },
'IPv4Addresses' => [
'Address' => ip, 'SubnetMask' => netmask, 'Gateway' => gateway
]
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | ruby | def set_ilo_ipv4_static(ip:, netmask:, gateway: '0.0.0.0', manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => { 'Hp' => { 'DHCPv4' => { 'Enabled' => false } } },
'IPv4Addresses' => [
'Address' => ip, 'SubnetMask' => netmask, 'Gateway' => gateway
]
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | [
"def",
"set_ilo_ipv4_static",
"(",
"ip",
":",
",",
"netmask",
":",
",",
"gateway",
":",
"'0.0.0.0'",
",",
"manager_id",
":",
"1",
",",
"ethernet_interface",
":",
"1",
")",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'DHCPv4'",
"=>",
"{",
"'Enabled'",
"=>",
"false",
"}",
"}",
"}",
",",
"'IPv4Addresses'",
"=>",
"[",
"'Address'",
"=>",
"ip",
",",
"'SubnetMask'",
"=>",
"netmask",
",",
"'Gateway'",
"=>",
"gateway",
"]",
"}",
"response",
"=",
"rest_patch",
"(",
"\"/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set EthernetInterface to static IPv4 address
@param ip [String] IPv4 address
@param netmask [String] IPv4 subnet mask
@param gateway [String] IPv4 default gateway
@param manager_id [Integer, String] ID of the Manager
@param ethernet_interface [Integer, String] ID of the EthernetInterface
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"EthernetInterface",
"to",
"static",
"IPv4",
"address"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/ethernet_interface_helper.rb#L58-L68 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/ethernet_interface_helper.rb | ILO_SDK.EthernetInterfaceHelper.set_ilo_ipv4_dns_servers | def set_ilo_ipv4_dns_servers(dns_servers:, manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => {
'Hp' => {
'DHCPv4' => { 'UseDNSServers' => false },
'IPv4' => { 'DNSServers' => dns_servers }
}
}
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | ruby | def set_ilo_ipv4_dns_servers(dns_servers:, manager_id: 1, ethernet_interface: 1)
new_action = {
'Oem' => {
'Hp' => {
'DHCPv4' => { 'UseDNSServers' => false },
'IPv4' => { 'DNSServers' => dns_servers }
}
}
}
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | [
"def",
"set_ilo_ipv4_dns_servers",
"(",
"dns_servers",
":",
",",
"manager_id",
":",
"1",
",",
"ethernet_interface",
":",
"1",
")",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'DHCPv4'",
"=>",
"{",
"'UseDNSServers'",
"=>",
"false",
"}",
",",
"'IPv4'",
"=>",
"{",
"'DNSServers'",
"=>",
"dns_servers",
"}",
"}",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"\"/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set EthernetInterface DNS servers
@param dns_servers [Array] list of DNS servers
@param manager_id [Integer, String] ID of the Manager
@param ethernet_interface [Integer, String] ID of the EthernetInterface
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"EthernetInterface",
"DNS",
"servers"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/ethernet_interface_helper.rb#L76-L88 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/ethernet_interface_helper.rb | ILO_SDK.EthernetInterfaceHelper.set_ilo_hostname | def set_ilo_hostname(hostname:, domain_name: nil, manager_id: 1, ethernet_interface: 1)
new_action = { 'Oem' => { 'Hp' => { 'HostName' => hostname } } }
new_action['Oem']['Hp'].merge!('DHCPv4' => {}, 'DHCPv6' => {}) if domain_name
new_action['Oem']['Hp']['DHCPv4']['UseDomainName'] = false if domain_name
new_action['Oem']['Hp']['DHCPv6']['UseDomainName'] = false if domain_name
new_action['Oem']['Hp']['DomainName'] = domain_name if domain_name
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | ruby | def set_ilo_hostname(hostname:, domain_name: nil, manager_id: 1, ethernet_interface: 1)
new_action = { 'Oem' => { 'Hp' => { 'HostName' => hostname } } }
new_action['Oem']['Hp'].merge!('DHCPv4' => {}, 'DHCPv6' => {}) if domain_name
new_action['Oem']['Hp']['DHCPv4']['UseDomainName'] = false if domain_name
new_action['Oem']['Hp']['DHCPv6']['UseDomainName'] = false if domain_name
new_action['Oem']['Hp']['DomainName'] = domain_name if domain_name
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action)
response_handler(response)
true
end | [
"def",
"set_ilo_hostname",
"(",
"hostname",
":",
",",
"domain_name",
":",
"nil",
",",
"manager_id",
":",
"1",
",",
"ethernet_interface",
":",
"1",
")",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'HostName'",
"=>",
"hostname",
"}",
"}",
"}",
"new_action",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
".",
"merge!",
"(",
"'DHCPv4'",
"=>",
"{",
"}",
",",
"'DHCPv6'",
"=>",
"{",
"}",
")",
"if",
"domain_name",
"new_action",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'DHCPv4'",
"]",
"[",
"'UseDomainName'",
"]",
"=",
"false",
"if",
"domain_name",
"new_action",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'DHCPv6'",
"]",
"[",
"'UseDomainName'",
"]",
"=",
"false",
"if",
"domain_name",
"new_action",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'DomainName'",
"]",
"=",
"domain_name",
"if",
"domain_name",
"response",
"=",
"rest_patch",
"(",
"\"/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set iLO hostname and domain name
@param hostname [String] iLO hostname
@param domain_name [String] iLO domain name
@param manager_id [Integer, String] ID of the Manager
@param ethernet_interface [Integer, String] ID of the EthernetInterface
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"iLO",
"hostname",
"and",
"domain",
"name"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/ethernet_interface_helper.rb#L97-L106 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/rest.rb | ILO_SDK.Rest.rest_api | def rest_api(type, path, options = {})
raise InvalidRequest, 'Must specify path' unless path
raise InvalidRequest, 'Must specify type' unless type
@logger.debug "Making :#{type} rest call to #{@host}#{path}"
uri = URI.parse(URI.escape("#{@host}#{path}"))
http = @disable_proxy ? Net::HTTP.new(uri.host, uri.port, nil, nil) : Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_enabled
request = build_request(type, uri, options)
response = http.request(request)
@logger.debug " Response: Code=#{response.code}. Headers=#{response.to_hash}\n Body=#{response.body}"
response
rescue OpenSSL::SSL::SSLError => e
msg = 'SSL verification failed for the request. Please either:'
msg += "\n 1. Install the necessary certificate(s) into your cert store"
msg += ". Using cert store: #{ENV['SSL_CERT_FILE']}" if ENV['SSL_CERT_FILE']
msg += "\n 2. Set the :ssl_enabled option to false for your iLO client (not recommended)"
@logger.error msg
raise e
rescue SocketError => e
e.message.prepend("Failed to connect to iLO host #{@host}!\n")
raise e
end | ruby | def rest_api(type, path, options = {})
raise InvalidRequest, 'Must specify path' unless path
raise InvalidRequest, 'Must specify type' unless type
@logger.debug "Making :#{type} rest call to #{@host}#{path}"
uri = URI.parse(URI.escape("#{@host}#{path}"))
http = @disable_proxy ? Net::HTTP.new(uri.host, uri.port, nil, nil) : Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_enabled
request = build_request(type, uri, options)
response = http.request(request)
@logger.debug " Response: Code=#{response.code}. Headers=#{response.to_hash}\n Body=#{response.body}"
response
rescue OpenSSL::SSL::SSLError => e
msg = 'SSL verification failed for the request. Please either:'
msg += "\n 1. Install the necessary certificate(s) into your cert store"
msg += ". Using cert store: #{ENV['SSL_CERT_FILE']}" if ENV['SSL_CERT_FILE']
msg += "\n 2. Set the :ssl_enabled option to false for your iLO client (not recommended)"
@logger.error msg
raise e
rescue SocketError => e
e.message.prepend("Failed to connect to iLO host #{@host}!\n")
raise e
end | [
"def",
"rest_api",
"(",
"type",
",",
"path",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"InvalidRequest",
",",
"'Must specify path'",
"unless",
"path",
"raise",
"InvalidRequest",
",",
"'Must specify type'",
"unless",
"type",
"@logger",
".",
"debug",
"\"Making :#{type} rest call to #{@host}#{path}\"",
"uri",
"=",
"URI",
".",
"parse",
"(",
"URI",
".",
"escape",
"(",
"\"#{@host}#{path}\"",
")",
")",
"http",
"=",
"@disable_proxy",
"?",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
",",
"nil",
",",
"nil",
")",
":",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"http",
".",
"use_ssl",
"=",
"true",
"if",
"uri",
".",
"scheme",
"==",
"'https'",
"http",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"unless",
"@ssl_enabled",
"request",
"=",
"build_request",
"(",
"type",
",",
"uri",
",",
"options",
")",
"response",
"=",
"http",
".",
"request",
"(",
"request",
")",
"@logger",
".",
"debug",
"\" Response: Code=#{response.code}. Headers=#{response.to_hash}\\n Body=#{response.body}\"",
"response",
"rescue",
"OpenSSL",
"::",
"SSL",
"::",
"SSLError",
"=>",
"e",
"msg",
"=",
"'SSL verification failed for the request. Please either:'",
"msg",
"+=",
"\"\\n 1. Install the necessary certificate(s) into your cert store\"",
"msg",
"+=",
"\". Using cert store: #{ENV['SSL_CERT_FILE']}\"",
"if",
"ENV",
"[",
"'SSL_CERT_FILE'",
"]",
"msg",
"+=",
"\"\\n 2. Set the :ssl_enabled option to false for your iLO client (not recommended)\"",
"@logger",
".",
"error",
"msg",
"raise",
"e",
"rescue",
"SocketError",
"=>",
"e",
"e",
".",
"message",
".",
"prepend",
"(",
"\"Failed to connect to iLO host #{@host}!\\n\"",
")",
"raise",
"e",
"end"
] | Make a restful API request to the iLO
@param [Symbol] type the rest method/type Options are :get, :post, :put, :patch, and :delete
@param [String] path the path for the request. Usually starts with "/rest/"
@param [Hash] options the options for the request
@option options [String] :body Hash to be converted into json and set as the request body
@option options [String] :Content-Type ('application/json') Set to nil or :none to have this option removed
@raise [InvalidRequest] if the request is invalid
@raise [SocketError] if a connection could not be made
@raise [OpenSSL::SSL::SSLError] if SSL validation of the iLO's certificate failed
@return [NetHTTPResponse] The response object | [
"Make",
"a",
"restful",
"API",
"request",
"to",
"the",
"iLO"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/rest.rb#L30-L54 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/rest.rb | ILO_SDK.Rest.response_handler | def response_handler(response)
case response.code.to_i
when RESPONSE_CODE_OK # Synchronous read/query
begin
return JSON.parse(response.body)
rescue JSON::ParserError => e
@logger.warn "Failed to parse JSON response. #{e}"
return response.body
end
when RESPONSE_CODE_CREATED # Synchronous add
return JSON.parse(response.body)
when RESPONSE_CODE_ACCEPTED # Asynchronous add, update or delete
return JSON.parse(response.body) # TODO: Remove when tested
# TODO: Make this actually wait for the task
# @logger.debug "Waiting for task: #{response.header['location']}"
# task = wait_for(response.header['location'])
# return true unless task['associatedResource'] && task['associatedResource']['resourceUri']
# resource_data = rest_get(task['associatedResource']['resourceUri'])
# return JSON.parse(resource_data.body)
when RESPONSE_CODE_NO_CONTENT # Synchronous delete
return {}
when RESPONSE_CODE_BAD_REQUEST
raise BadRequest, "400 BAD REQUEST #{response.body}"
when RESPONSE_CODE_UNAUTHORIZED
raise Unauthorized, "401 UNAUTHORIZED #{response.body}"
when RESPONSE_CODE_NOT_FOUND
raise NotFound, "404 NOT FOUND #{response.body}"
else
raise RequestError, "#{response.code} #{response.body}"
end
end | ruby | def response_handler(response)
case response.code.to_i
when RESPONSE_CODE_OK # Synchronous read/query
begin
return JSON.parse(response.body)
rescue JSON::ParserError => e
@logger.warn "Failed to parse JSON response. #{e}"
return response.body
end
when RESPONSE_CODE_CREATED # Synchronous add
return JSON.parse(response.body)
when RESPONSE_CODE_ACCEPTED # Asynchronous add, update or delete
return JSON.parse(response.body) # TODO: Remove when tested
# TODO: Make this actually wait for the task
# @logger.debug "Waiting for task: #{response.header['location']}"
# task = wait_for(response.header['location'])
# return true unless task['associatedResource'] && task['associatedResource']['resourceUri']
# resource_data = rest_get(task['associatedResource']['resourceUri'])
# return JSON.parse(resource_data.body)
when RESPONSE_CODE_NO_CONTENT # Synchronous delete
return {}
when RESPONSE_CODE_BAD_REQUEST
raise BadRequest, "400 BAD REQUEST #{response.body}"
when RESPONSE_CODE_UNAUTHORIZED
raise Unauthorized, "401 UNAUTHORIZED #{response.body}"
when RESPONSE_CODE_NOT_FOUND
raise NotFound, "404 NOT FOUND #{response.body}"
else
raise RequestError, "#{response.code} #{response.body}"
end
end | [
"def",
"response_handler",
"(",
"response",
")",
"case",
"response",
".",
"code",
".",
"to_i",
"when",
"RESPONSE_CODE_OK",
"begin",
"return",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"rescue",
"JSON",
"::",
"ParserError",
"=>",
"e",
"@logger",
".",
"warn",
"\"Failed to parse JSON response. #{e}\"",
"return",
"response",
".",
"body",
"end",
"when",
"RESPONSE_CODE_CREATED",
"return",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"when",
"RESPONSE_CODE_ACCEPTED",
"return",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"when",
"RESPONSE_CODE_NO_CONTENT",
"return",
"{",
"}",
"when",
"RESPONSE_CODE_BAD_REQUEST",
"raise",
"BadRequest",
",",
"\"400 BAD REQUEST #{response.body}\"",
"when",
"RESPONSE_CODE_UNAUTHORIZED",
"raise",
"Unauthorized",
",",
"\"401 UNAUTHORIZED #{response.body}\"",
"when",
"RESPONSE_CODE_NOT_FOUND",
"raise",
"NotFound",
",",
"\"404 NOT FOUND #{response.body}\"",
"else",
"raise",
"RequestError",
",",
"\"#{response.code} #{response.body}\"",
"end",
"end"
] | Handle the response for rest call.
If an asynchronous task was started, this waits for it to complete.
@param [HTTPResponse] HTTP response
@raise [ILO_SDK::BadRequest] if the request failed with a 400 status
@raise [ILO_SDK::Unauthorized] if the request failed with a 401 status
@raise [ILO_SDK::NotFound] if the request failed with a 404 status
@raise [ILO_SDK::RequestError] if the request failed with any other status
@return [Hash] The parsed JSON body | [
"Handle",
"the",
"response",
"for",
"rest",
"call",
".",
"If",
"an",
"asynchronous",
"task",
"was",
"started",
"this",
"waits",
"for",
"it",
"to",
"complete",
"."
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/rest.rb#L102-L132 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/manager_account_helper.rb | ILO_SDK.ManagerAccountHelper.get_account_privileges | def get_account_privileges(username)
response = rest_get('/redfish/v1/AccountService/Accounts/')
accounts = response_handler(response)['Items']
accounts.each do |account|
if account['Oem']['Hp']['LoginName'] == username
return account['Oem']['Hp']['Privileges']
end
end
end | ruby | def get_account_privileges(username)
response = rest_get('/redfish/v1/AccountService/Accounts/')
accounts = response_handler(response)['Items']
accounts.each do |account|
if account['Oem']['Hp']['LoginName'] == username
return account['Oem']['Hp']['Privileges']
end
end
end | [
"def",
"get_account_privileges",
"(",
"username",
")",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/AccountService/Accounts/'",
")",
"accounts",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"accounts",
".",
"each",
"do",
"|",
"account",
"|",
"if",
"account",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'LoginName'",
"]",
"==",
"username",
"return",
"account",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'Privileges'",
"]",
"end",
"end",
"end"
] | Get the Privileges for a user
@param [String, Symbol] username
@raise [RuntimeError] if the request failed
@return [Hash] privileges | [
"Get",
"the",
"Privileges",
"for",
"a",
"user"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/manager_account_helper.rb#L19-L27 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/manager_account_helper.rb | ILO_SDK.ManagerAccountHelper.set_account_privileges | def set_account_privileges(username, privileges)
response = rest_get('/redfish/v1/AccountService/Accounts/')
accounts = response_handler(response)['Items']
id = '0'
accounts.each do |account|
if account['Oem']['Hp']['LoginName'] == username
id = account['Id']
break
end
end
new_action = {
'Oem' => {
'Hp' => {
'Privileges' => privileges
}
}
}
response = rest_patch("/redfish/v1/AccountService/Accounts/#{id}/", body: new_action)
response_handler(response)
true
end | ruby | def set_account_privileges(username, privileges)
response = rest_get('/redfish/v1/AccountService/Accounts/')
accounts = response_handler(response)['Items']
id = '0'
accounts.each do |account|
if account['Oem']['Hp']['LoginName'] == username
id = account['Id']
break
end
end
new_action = {
'Oem' => {
'Hp' => {
'Privileges' => privileges
}
}
}
response = rest_patch("/redfish/v1/AccountService/Accounts/#{id}/", body: new_action)
response_handler(response)
true
end | [
"def",
"set_account_privileges",
"(",
"username",
",",
"privileges",
")",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/AccountService/Accounts/'",
")",
"accounts",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"id",
"=",
"'0'",
"accounts",
".",
"each",
"do",
"|",
"account",
"|",
"if",
"account",
"[",
"'Oem'",
"]",
"[",
"'Hp'",
"]",
"[",
"'LoginName'",
"]",
"==",
"username",
"id",
"=",
"account",
"[",
"'Id'",
"]",
"break",
"end",
"end",
"new_action",
"=",
"{",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'Privileges'",
"=>",
"privileges",
"}",
"}",
"}",
"response",
"=",
"rest_patch",
"(",
"\"/redfish/v1/AccountService/Accounts/#{id}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the privileges for a user
@param [TrueClass, FalseClass] username
@param [Hash] privileges
@option privileges [TrueClass, FalseClass] :LoginPriv
@option privileges [TrueClass, FalseClass] :RemoteConsolePriv
@option privileges [TrueClass, FalseClass] :UserConfigPriv
@option privileges [TrueClass, FalseClass] :VirtualMediaPriv
@option privileges [TrueClass, FalseClass] :VirtualPowerAndResetPriv
@option privileges [TrueClass, FalseClass] :iLOConfigPriv
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"privileges",
"for",
"a",
"user"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/manager_account_helper.rb#L40-L60 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/https_cert_helper.rb | ILO_SDK.HttpsCertHelper.get_certificate | def get_certificate
uri = URI.parse(URI.escape(@host))
options = { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
Net::HTTP.start(uri.host, uri.port, options) do |http|
http.peer_cert
end
end | ruby | def get_certificate
uri = URI.parse(URI.escape(@host))
options = { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
Net::HTTP.start(uri.host, uri.port, options) do |http|
http.peer_cert
end
end | [
"def",
"get_certificate",
"uri",
"=",
"URI",
".",
"parse",
"(",
"URI",
".",
"escape",
"(",
"@host",
")",
")",
"options",
"=",
"{",
"use_ssl",
":",
"true",
",",
"verify_mode",
":",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"}",
"Net",
"::",
"HTTP",
".",
"start",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
",",
"options",
")",
"do",
"|",
"http",
"|",
"http",
".",
"peer_cert",
"end",
"end"
] | Get the SSL Certificate
@raise [RuntimeError] if the request failed
@return [OpenSSL::X509::Certificate] x509_certificate
rubocop:disable Style/SymbolProc | [
"Get",
"the",
"SSL",
"Certificate"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/https_cert_helper.rb#L19-L25 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/https_cert_helper.rb | ILO_SDK.HttpsCertHelper.generate_csr | def generate_csr(country, state, city, org_name, org_unit, common_name)
new_action = {
'Action' => 'GenerateCSR',
'Country' => country,
'State' => state,
'City' => city,
'OrgName' => org_name,
'OrgUnit' => org_unit,
'CommonName' => common_name
}
response = rest_post('/redfish/v1/Managers/1/SecurityService/HttpsCert/', body: new_action)
response_handler(response)
true
end | ruby | def generate_csr(country, state, city, org_name, org_unit, common_name)
new_action = {
'Action' => 'GenerateCSR',
'Country' => country,
'State' => state,
'City' => city,
'OrgName' => org_name,
'OrgUnit' => org_unit,
'CommonName' => common_name
}
response = rest_post('/redfish/v1/Managers/1/SecurityService/HttpsCert/', body: new_action)
response_handler(response)
true
end | [
"def",
"generate_csr",
"(",
"country",
",",
"state",
",",
"city",
",",
"org_name",
",",
"org_unit",
",",
"common_name",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'GenerateCSR'",
",",
"'Country'",
"=>",
"country",
",",
"'State'",
"=>",
"state",
",",
"'City'",
"=>",
"city",
",",
"'OrgName'",
"=>",
"org_name",
",",
"'OrgUnit'",
"=>",
"org_unit",
",",
"'CommonName'",
"=>",
"common_name",
"}",
"response",
"=",
"rest_post",
"(",
"'/redfish/v1/Managers/1/SecurityService/HttpsCert/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Generate a Certificate Signing Request
@param [String] country
@param [String] state
@param [String] city
@param [String] orgName
@param [String] orgUnit
@param [String] commonName
@raise [RuntimeError] if the request failed
@return true | [
"Generate",
"a",
"Certificate",
"Signing",
"Request"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/https_cert_helper.rb#L51-L64 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/secure_boot_helper.rb | ILO_SDK.SecureBootHelper.set_uefi_secure_boot | def set_uefi_secure_boot(secure_boot_enable)
new_action = { 'SecureBootEnable' => secure_boot_enable }
response = rest_patch('/redfish/v1/Systems/1/SecureBoot/', body: new_action)
response_handler(response)
true
end | ruby | def set_uefi_secure_boot(secure_boot_enable)
new_action = { 'SecureBootEnable' => secure_boot_enable }
response = rest_patch('/redfish/v1/Systems/1/SecureBoot/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_uefi_secure_boot",
"(",
"secure_boot_enable",
")",
"new_action",
"=",
"{",
"'SecureBootEnable'",
"=>",
"secure_boot_enable",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/SecureBoot/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the UEFI secure boot true or false
@param [Boolean] secure_boot_enable
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"UEFI",
"secure",
"boot",
"true",
"or",
"false"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/secure_boot_helper.rb#L27-L32 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/power_helper.rb | ILO_SDK.PowerHelper.set_power_state | def set_power_state(state)
new_action = { 'Action' => 'Reset', 'ResetType' => state }
response = rest_post('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | ruby | def set_power_state(state)
new_action = { 'Action' => 'Reset', 'ResetType' => state }
response = rest_post('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_power_state",
"(",
"state",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'Reset'",
",",
"'ResetType'",
"=>",
"state",
"}",
"response",
"=",
"rest_post",
"(",
"'/redfish/v1/Systems/1/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the Power State
@param [String, Symbol] state
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"Power",
"State"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/power_helper.rb#L27-L32 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/snmp_service_helper.rb | ILO_SDK.SNMPServiceHelper.set_snmp | def set_snmp(snmp_mode, snmp_alerts)
new_action = { 'Mode' => snmp_mode, 'AlertsEnabled' => snmp_alerts }
response = rest_patch('/redfish/v1/Managers/1/SnmpService/', body: new_action)
response_handler(response)
true
end | ruby | def set_snmp(snmp_mode, snmp_alerts)
new_action = { 'Mode' => snmp_mode, 'AlertsEnabled' => snmp_alerts }
response = rest_patch('/redfish/v1/Managers/1/SnmpService/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_snmp",
"(",
"snmp_mode",
",",
"snmp_alerts",
")",
"new_action",
"=",
"{",
"'Mode'",
"=>",
"snmp_mode",
",",
"'AlertsEnabled'",
"=>",
"snmp_alerts",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Managers/1/SnmpService/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the SNMP Mode and Alerts Enabled value
@param [String, Symbol] snmp_mode
@param [Boolean] snmp_alerts
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"SNMP",
"Mode",
"and",
"Alerts",
"Enabled",
"value"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/snmp_service_helper.rb#L36-L41 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/virtual_media_helper.rb | ILO_SDK.VirtualMediaHelper.get_virtual_media | def get_virtual_media
response = rest_get('/redfish/v1/Managers/1/VirtualMedia/')
media = {}
response_handler(response)['links']['Member'].each do |vm|
response = rest_get(vm['href'])
virtual_media = response_handler(response)
media[virtual_media['Id']] = {
'Image' => virtual_media['Image'],
'MediaTypes' => virtual_media['MediaTypes']
}
end
media
end | ruby | def get_virtual_media
response = rest_get('/redfish/v1/Managers/1/VirtualMedia/')
media = {}
response_handler(response)['links']['Member'].each do |vm|
response = rest_get(vm['href'])
virtual_media = response_handler(response)
media[virtual_media['Id']] = {
'Image' => virtual_media['Image'],
'MediaTypes' => virtual_media['MediaTypes']
}
end
media
end | [
"def",
"get_virtual_media",
"response",
"=",
"rest_get",
"(",
"'/redfish/v1/Managers/1/VirtualMedia/'",
")",
"media",
"=",
"{",
"}",
"response_handler",
"(",
"response",
")",
"[",
"'links'",
"]",
"[",
"'Member'",
"]",
".",
"each",
"do",
"|",
"vm",
"|",
"response",
"=",
"rest_get",
"(",
"vm",
"[",
"'href'",
"]",
")",
"virtual_media",
"=",
"response_handler",
"(",
"response",
")",
"media",
"[",
"virtual_media",
"[",
"'Id'",
"]",
"]",
"=",
"{",
"'Image'",
"=>",
"virtual_media",
"[",
"'Image'",
"]",
",",
"'MediaTypes'",
"=>",
"virtual_media",
"[",
"'MediaTypes'",
"]",
"}",
"end",
"media",
"end"
] | Get the Virtual Media Information
@raise [RuntimeError] if the request failed
@return [String] virtual_media | [
"Get",
"the",
"Virtual",
"Media",
"Information"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/virtual_media_helper.rb#L18-L30 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/virtual_media_helper.rb | ILO_SDK.VirtualMediaHelper.insert_virtual_media | def insert_virtual_media(id, image)
new_action = {
'Action' => 'InsertVirtualMedia',
'Target' => '/Oem/Hp',
'Image' => image
}
response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
response_handler(response)
true
end | ruby | def insert_virtual_media(id, image)
new_action = {
'Action' => 'InsertVirtualMedia',
'Target' => '/Oem/Hp',
'Image' => image
}
response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
response_handler(response)
true
end | [
"def",
"insert_virtual_media",
"(",
"id",
",",
"image",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'InsertVirtualMedia'",
",",
"'Target'",
"=>",
"'/Oem/Hp'",
",",
"'Image'",
"=>",
"image",
"}",
"response",
"=",
"rest_post",
"(",
"\"/redfish/v1/Managers/1/VirtualMedia/#{id}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Insert Virtual Media
@param [String, Symbol] id
@param [String, Symbol] image
@return true | [
"Insert",
"Virtual",
"Media"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/virtual_media_helper.rb#L44-L53 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/virtual_media_helper.rb | ILO_SDK.VirtualMediaHelper.eject_virtual_media | def eject_virtual_media(id)
new_action = {
'Action' => 'EjectVirtualMedia',
'Target' => '/Oem/Hp'
}
response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
response_handler(response)
true
end | ruby | def eject_virtual_media(id)
new_action = {
'Action' => 'EjectVirtualMedia',
'Target' => '/Oem/Hp'
}
response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
response_handler(response)
true
end | [
"def",
"eject_virtual_media",
"(",
"id",
")",
"new_action",
"=",
"{",
"'Action'",
"=>",
"'EjectVirtualMedia'",
",",
"'Target'",
"=>",
"'/Oem/Hp'",
"}",
"response",
"=",
"rest_post",
"(",
"\"/redfish/v1/Managers/1/VirtualMedia/#{id}/\"",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Eject Virtual Media
@param [String, Symbol] id
@return true | [
"Eject",
"Virtual",
"Media"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/virtual_media_helper.rb#L58-L66 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/computer_system_helper.rb | ILO_SDK.ComputerSystemHelper.set_asset_tag | def set_asset_tag(asset_tag)
@logger.warn '[Deprecated] `set_asset_tag` is deprecated. Please use `set_system_settings(AssetTag: <tag>)` instead.'
new_action = { 'AssetTag' => asset_tag }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | ruby | def set_asset_tag(asset_tag)
@logger.warn '[Deprecated] `set_asset_tag` is deprecated. Please use `set_system_settings(AssetTag: <tag>)` instead.'
new_action = { 'AssetTag' => asset_tag }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_asset_tag",
"(",
"asset_tag",
")",
"@logger",
".",
"warn",
"'[Deprecated] `set_asset_tag` is deprecated. Please use `set_system_settings(AssetTag: <tag>)` instead.'",
"new_action",
"=",
"{",
"'AssetTag'",
"=>",
"asset_tag",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the Asset Tag
@deprecated Use {#set_system_settings} instead
@param asset_tag [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"Asset",
"Tag"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/computer_system_helper.rb#L48-L54 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/computer_system_helper.rb | ILO_SDK.ComputerSystemHelper.set_indicator_led | def set_indicator_led(state)
@logger.warn '[Deprecated] `set_indicator_led` is deprecated. Please use `set_system_settings(IndicatorLED: <state>)` instead.'
new_action = { 'IndicatorLED' => state }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | ruby | def set_indicator_led(state)
@logger.warn '[Deprecated] `set_indicator_led` is deprecated. Please use `set_system_settings(IndicatorLED: <state>)` instead.'
new_action = { 'IndicatorLED' => state }
response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
response_handler(response)
true
end | [
"def",
"set_indicator_led",
"(",
"state",
")",
"@logger",
".",
"warn",
"'[Deprecated] `set_indicator_led` is deprecated. Please use `set_system_settings(IndicatorLED: <state>)` instead.'",
"new_action",
"=",
"{",
"'IndicatorLED'",
"=>",
"state",
"}",
"response",
"=",
"rest_patch",
"(",
"'/redfish/v1/Systems/1/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Set the UID indicator LED
@deprecated Use {#set_system_settings} instead
@param state [String, Symbol]
@raise [RuntimeError] if the request failed
@return true | [
"Set",
"the",
"UID",
"indicator",
"LED"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/computer_system_helper.rb#L71-L77 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/account_service_helper.rb | ILO_SDK.AccountServiceHelper.userhref | def userhref(uri, username)
response = rest_get(uri)
items = response_handler(response)['Items']
items.each do |it|
return it['links']['self']['href'] if it['UserName'] == username
end
end | ruby | def userhref(uri, username)
response = rest_get(uri)
items = response_handler(response)['Items']
items.each do |it|
return it['links']['self']['href'] if it['UserName'] == username
end
end | [
"def",
"userhref",
"(",
"uri",
",",
"username",
")",
"response",
"=",
"rest_get",
"(",
"uri",
")",
"items",
"=",
"response_handler",
"(",
"response",
")",
"[",
"'Items'",
"]",
"items",
".",
"each",
"do",
"|",
"it",
"|",
"return",
"it",
"[",
"'links'",
"]",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
"if",
"it",
"[",
"'UserName'",
"]",
"==",
"username",
"end",
"end"
] | Get the HREF for a user with a specific username
@param [String, Symbol] uri
@param [String, Symbol] username
@raise [RuntimeError] if the request failed
@return [String] userhref | [
"Get",
"the",
"HREF",
"for",
"a",
"user",
"with",
"a",
"specific",
"username"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/account_service_helper.rb#L20-L26 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/account_service_helper.rb | ILO_SDK.AccountServiceHelper.create_user | def create_user(username, password)
new_action = { 'UserName' => username, 'Password' => password, 'Oem' => { 'Hp' => { 'LoginName' => username } } }
response = rest_post('/redfish/v1/AccountService/Accounts/', body: new_action)
response_handler(response)
true
end | ruby | def create_user(username, password)
new_action = { 'UserName' => username, 'Password' => password, 'Oem' => { 'Hp' => { 'LoginName' => username } } }
response = rest_post('/redfish/v1/AccountService/Accounts/', body: new_action)
response_handler(response)
true
end | [
"def",
"create_user",
"(",
"username",
",",
"password",
")",
"new_action",
"=",
"{",
"'UserName'",
"=>",
"username",
",",
"'Password'",
"=>",
"password",
",",
"'Oem'",
"=>",
"{",
"'Hp'",
"=>",
"{",
"'LoginName'",
"=>",
"username",
"}",
"}",
"}",
"response",
"=",
"rest_post",
"(",
"'/redfish/v1/AccountService/Accounts/'",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Create a user
@param [String, Symbol] username
@param [String, Symbol] password
@raise [RuntimeError] if the request failed
@return true | [
"Create",
"a",
"user"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/account_service_helper.rb#L41-L46 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/account_service_helper.rb | ILO_SDK.AccountServiceHelper.change_password | def change_password(username, password)
new_action = { 'Password' => password }
userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
response = rest_patch(userhref, body: new_action)
response_handler(response)
true
end | ruby | def change_password(username, password)
new_action = { 'Password' => password }
userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
response = rest_patch(userhref, body: new_action)
response_handler(response)
true
end | [
"def",
"change_password",
"(",
"username",
",",
"password",
")",
"new_action",
"=",
"{",
"'Password'",
"=>",
"password",
"}",
"userhref",
"=",
"userhref",
"(",
"'/redfish/v1/AccountService/Accounts/'",
",",
"username",
")",
"response",
"=",
"rest_patch",
"(",
"userhref",
",",
"body",
":",
"new_action",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Change the password for a user
@param [String, Symbol] username
@param [String, Symbol] password
@raise [RuntimeError] if the request failed
@return true | [
"Change",
"the",
"password",
"for",
"a",
"user"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/account_service_helper.rb#L53-L59 | train |
HewlettPackard/ilo-sdk-ruby | lib/ilo-sdk/helpers/account_service_helper.rb | ILO_SDK.AccountServiceHelper.delete_user | def delete_user(username)
userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
response = rest_delete(userhref)
response_handler(response)
true
end | ruby | def delete_user(username)
userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
response = rest_delete(userhref)
response_handler(response)
true
end | [
"def",
"delete_user",
"(",
"username",
")",
"userhref",
"=",
"userhref",
"(",
"'/redfish/v1/AccountService/Accounts/'",
",",
"username",
")",
"response",
"=",
"rest_delete",
"(",
"userhref",
")",
"response_handler",
"(",
"response",
")",
"true",
"end"
] | Delete a specific user
@param [String, Symbol] username
@raise [RuntimeError] if the request failed
@return true | [
"Delete",
"a",
"specific",
"user"
] | ac171cd75d070ccf64017d43777ded40a5f018f9 | https://github.com/HewlettPackard/ilo-sdk-ruby/blob/ac171cd75d070ccf64017d43777ded40a5f018f9/lib/ilo-sdk/helpers/account_service_helper.rb#L65-L70 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.templates | def templates
data = http_action_get "nodes/#{@node}/storage/local/content"
template_list = {}
data.each do |ve|
name = ve['volid'].gsub(%r{local:vztmpl\/(.*).tar.gz}, '\1')
template_list[name] = ve
end
template_list
end | ruby | def templates
data = http_action_get "nodes/#{@node}/storage/local/content"
template_list = {}
data.each do |ve|
name = ve['volid'].gsub(%r{local:vztmpl\/(.*).tar.gz}, '\1')
template_list[name] = ve
end
template_list
end | [
"def",
"templates",
"data",
"=",
"http_action_get",
"\"nodes/#{@node}/storage/local/content\"",
"template_list",
"=",
"{",
"}",
"data",
".",
"each",
"do",
"|",
"ve",
"|",
"name",
"=",
"ve",
"[",
"'volid'",
"]",
".",
"gsub",
"(",
"%r{",
"\\/",
"}",
",",
"'\\1'",
")",
"template_list",
"[",
"name",
"]",
"=",
"ve",
"end",
"template_list",
"end"
] | Get template list
:call-seq:
templates -> Hash
Return a Hash of all templates
Example:
templates
Example return:
{
'ubuntu-10.04-standard_10.04-4_i386' => {
'format' => 'tgz',
'content' => 'vztmpl',
'volid' => 'local:vztmpl/ubuntu-10.04-standard_10.04-4_i386.tar.gz',
'size' => 142126884
},
'ubuntu-12.04-standard_12.04-1_i386' => {
'format' => 'tgz',
'content' => 'vztmpl',
'volid' => 'local:vztmpl/ubuntu-12.04-standard_12.04-1_i386.tar.gz',
'size' => 130040792
}
} | [
"Get",
"template",
"list"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L108-L116 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.openvz_get | def openvz_get
data = http_action_get "nodes/#{@node}/openvz"
ve_list = {}
data.each do |ve|
ve_list[ve['vmid']] = ve
end
ve_list
end | ruby | def openvz_get
data = http_action_get "nodes/#{@node}/openvz"
ve_list = {}
data.each do |ve|
ve_list[ve['vmid']] = ve
end
ve_list
end | [
"def",
"openvz_get",
"data",
"=",
"http_action_get",
"\"nodes/#{@node}/openvz\"",
"ve_list",
"=",
"{",
"}",
"data",
".",
"each",
"do",
"|",
"ve",
"|",
"ve_list",
"[",
"ve",
"[",
"'vmid'",
"]",
"]",
"=",
"ve",
"end",
"ve_list",
"end"
] | Get CT list
:call-seq:
openvz_get -> Hash
Return a Hash of all openvz container
Example:
openvz_get
Example return:
{
'101' => {
'maxswap' => 536870912,
'disk' => 405168128,
'ip' => '192.168.1.5',
'status' => 'running',
'netout' => 272,
'maxdisk' => 4294967296,
'maxmem' => 536870912,
'uptime' => 3068073,
'swap' => 0,
'vmid' => '101',
'nproc' => '10',
'diskread' => 0,
'cpu' => 0.00031670581100007,
'netin' => 0,
'name' => 'test2.domain.com',
'failcnt' => 0,
'diskwrite' => 0,
'mem' => 22487040,
'type' => 'openvz',
'cpus' => 1
},
[...]
} | [
"Get",
"CT",
"list"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L155-L162 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.openvz_post | def openvz_post(ostemplate, vmid, config = {})
config['vmid'] = vmid
config['ostemplate'] = "local%3Avztmpl%2F#{ostemplate}.tar.gz"
vm_definition = config.to_a.map { |v| v.join '=' }.join '&'
http_action_post("nodes/#{@node}/openvz", vm_definition)
end | ruby | def openvz_post(ostemplate, vmid, config = {})
config['vmid'] = vmid
config['ostemplate'] = "local%3Avztmpl%2F#{ostemplate}.tar.gz"
vm_definition = config.to_a.map { |v| v.join '=' }.join '&'
http_action_post("nodes/#{@node}/openvz", vm_definition)
end | [
"def",
"openvz_post",
"(",
"ostemplate",
",",
"vmid",
",",
"config",
"=",
"{",
"}",
")",
"config",
"[",
"'vmid'",
"]",
"=",
"vmid",
"config",
"[",
"'ostemplate'",
"]",
"=",
"\"local%3Avztmpl%2F#{ostemplate}.tar.gz\"",
"vm_definition",
"=",
"config",
".",
"to_a",
".",
"map",
"{",
"|",
"v",
"|",
"v",
".",
"join",
"'='",
"}",
".",
"join",
"'&'",
"http_action_post",
"(",
"\"nodes/#{@node}/openvz\"",
",",
"vm_definition",
")",
"end"
] | Create CT container
:call-seq:
openvz_post(ostemplate, vmid) -> String
openvz_post(ostemplate, vmid, options) -> String
Return a String as task ID
Examples:
openvz_post('ubuntu-10.04-standard_10.04-4_i386', 200)
openvz_post('ubuntu-10.04-standard_10.04-4_i386', 200, {'hostname' => 'test.test.com', 'password' => 'testt' })
Example return:
UPID:localhost:000BC66A:1279E395:521EFC4E:vzcreate:200:root@pam: | [
"Create",
"CT",
"container"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L181-L187 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.create_ticket | def create_ticket
post_param = { username: @username, realm: @realm, password: @password }
@site['access/ticket'].post post_param do |response, _request, _result, &_block|
if response.code == 200
extract_ticket response
else
@connection_status = 'error'
end
end
end | ruby | def create_ticket
post_param = { username: @username, realm: @realm, password: @password }
@site['access/ticket'].post post_param do |response, _request, _result, &_block|
if response.code == 200
extract_ticket response
else
@connection_status = 'error'
end
end
end | [
"def",
"create_ticket",
"post_param",
"=",
"{",
"username",
":",
"@username",
",",
"realm",
":",
"@realm",
",",
"password",
":",
"@password",
"}",
"@site",
"[",
"'access/ticket'",
"]",
".",
"post",
"post_param",
"do",
"|",
"response",
",",
"_request",
",",
"_result",
",",
"&",
"_block",
"|",
"if",
"response",
".",
"code",
"==",
"200",
"extract_ticket",
"response",
"else",
"@connection_status",
"=",
"'error'",
"end",
"end",
"end"
] | Methods manages auth | [
"Methods",
"manages",
"auth"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L340-L349 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.extract_ticket | def extract_ticket(response)
data = JSON.parse(response.body)
ticket = data['data']['ticket']
csrf_prevention_token = data['data']['CSRFPreventionToken']
unless ticket.nil?
token = 'PVEAuthCookie=' + ticket.gsub!(/:/, '%3A').gsub!(/=/, '%3D')
end
@connection_status = 'connected'
{
CSRFPreventionToken: csrf_prevention_token,
cookie: token
}
end | ruby | def extract_ticket(response)
data = JSON.parse(response.body)
ticket = data['data']['ticket']
csrf_prevention_token = data['data']['CSRFPreventionToken']
unless ticket.nil?
token = 'PVEAuthCookie=' + ticket.gsub!(/:/, '%3A').gsub!(/=/, '%3D')
end
@connection_status = 'connected'
{
CSRFPreventionToken: csrf_prevention_token,
cookie: token
}
end | [
"def",
"extract_ticket",
"(",
"response",
")",
"data",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"ticket",
"=",
"data",
"[",
"'data'",
"]",
"[",
"'ticket'",
"]",
"csrf_prevention_token",
"=",
"data",
"[",
"'data'",
"]",
"[",
"'CSRFPreventionToken'",
"]",
"unless",
"ticket",
".",
"nil?",
"token",
"=",
"'PVEAuthCookie='",
"+",
"ticket",
".",
"gsub!",
"(",
"/",
"/",
",",
"'%3A'",
")",
".",
"gsub!",
"(",
"/",
"/",
",",
"'%3D'",
")",
"end",
"@connection_status",
"=",
"'connected'",
"{",
"CSRFPreventionToken",
":",
"csrf_prevention_token",
",",
"cookie",
":",
"token",
"}",
"end"
] | Method create ticket | [
"Method",
"create",
"ticket"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L352-L364 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.check_response | def check_response(response)
if response.code == 200
JSON.parse(response.body)['data']
else
'NOK: error code = ' + response.code.to_s
end
end | ruby | def check_response(response)
if response.code == 200
JSON.parse(response.body)['data']
else
'NOK: error code = ' + response.code.to_s
end
end | [
"def",
"check_response",
"(",
"response",
")",
"if",
"response",
".",
"code",
"==",
"200",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"[",
"'data'",
"]",
"else",
"'NOK: error code = '",
"+",
"response",
".",
"code",
".",
"to_s",
"end",
"end"
] | Extract data or return error | [
"Extract",
"data",
"or",
"return",
"error"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L367-L373 | train |
nledez/proxmox | lib/proxmox.rb | Proxmox.Proxmox.http_action_post | def http_action_post(url, data = {})
@site[url].post data, @auth_params do |response, _request, _result, &_block|
check_response response
end
end | ruby | def http_action_post(url, data = {})
@site[url].post data, @auth_params do |response, _request, _result, &_block|
check_response response
end
end | [
"def",
"http_action_post",
"(",
"url",
",",
"data",
"=",
"{",
"}",
")",
"@site",
"[",
"url",
"]",
".",
"post",
"data",
",",
"@auth_params",
"do",
"|",
"response",
",",
"_request",
",",
"_result",
",",
"&",
"_block",
"|",
"check_response",
"response",
"end",
"end"
] | Methods manage http dialogs | [
"Methods",
"manage",
"http",
"dialogs"
] | cc679cc69deb78b20f88074b235e172869070a0d | https://github.com/nledez/proxmox/blob/cc679cc69deb78b20f88074b235e172869070a0d/lib/proxmox.rb#L376-L380 | train |
farcaller/rly | lib/rly/lex.rb | Rly.Lex.next | def next
while @pos < @input.length
if self.class.ignores_list[@input[@pos]]
ignore_symbol
next
end
m = self.class.token_regexps.match(@input[@pos..-1])
if m && ! m[0].empty?
val = nil
type = nil
resolved_type = nil
m.names.each do |n|
if m[n]
type = n.to_sym
resolved_type = (n.start_with?('__anonymous_') ? nil : type)
val = m[n]
break
end
end
if type
tok = build_token(resolved_type, val)
@pos += m.end(0)
tok = self.class.callables[type].call(tok) if self.class.callables[type]
if tok && tok.type
return tok
else
next
end
end
end
if self.class.literals_list[@input[@pos]]
tok = build_token(@input[@pos], @input[@pos])
matched = true
@pos += 1
return tok
end
if self.class.error_hander
pos = @pos
tok = build_token(:error, @input[@pos])
tok = self.class.error_hander.call(tok)
if pos == @pos
raise LexError.new("Illegal character '#{@input[@pos]}' at index #{@pos}")
else
return tok if tok && tok.type
end
else
raise LexError.new("Illegal character '#{@input[@pos]}' at index #{@pos}")
end
end
return nil
end | ruby | def next
while @pos < @input.length
if self.class.ignores_list[@input[@pos]]
ignore_symbol
next
end
m = self.class.token_regexps.match(@input[@pos..-1])
if m && ! m[0].empty?
val = nil
type = nil
resolved_type = nil
m.names.each do |n|
if m[n]
type = n.to_sym
resolved_type = (n.start_with?('__anonymous_') ? nil : type)
val = m[n]
break
end
end
if type
tok = build_token(resolved_type, val)
@pos += m.end(0)
tok = self.class.callables[type].call(tok) if self.class.callables[type]
if tok && tok.type
return tok
else
next
end
end
end
if self.class.literals_list[@input[@pos]]
tok = build_token(@input[@pos], @input[@pos])
matched = true
@pos += 1
return tok
end
if self.class.error_hander
pos = @pos
tok = build_token(:error, @input[@pos])
tok = self.class.error_hander.call(tok)
if pos == @pos
raise LexError.new("Illegal character '#{@input[@pos]}' at index #{@pos}")
else
return tok if tok && tok.type
end
else
raise LexError.new("Illegal character '#{@input[@pos]}' at index #{@pos}")
end
end
return nil
end | [
"def",
"next",
"while",
"@pos",
"<",
"@input",
".",
"length",
"if",
"self",
".",
"class",
".",
"ignores_list",
"[",
"@input",
"[",
"@pos",
"]",
"]",
"ignore_symbol",
"next",
"end",
"m",
"=",
"self",
".",
"class",
".",
"token_regexps",
".",
"match",
"(",
"@input",
"[",
"@pos",
"..",
"-",
"1",
"]",
")",
"if",
"m",
"&&",
"!",
"m",
"[",
"0",
"]",
".",
"empty?",
"val",
"=",
"nil",
"type",
"=",
"nil",
"resolved_type",
"=",
"nil",
"m",
".",
"names",
".",
"each",
"do",
"|",
"n",
"|",
"if",
"m",
"[",
"n",
"]",
"type",
"=",
"n",
".",
"to_sym",
"resolved_type",
"=",
"(",
"n",
".",
"start_with?",
"(",
"'__anonymous_'",
")",
"?",
"nil",
":",
"type",
")",
"val",
"=",
"m",
"[",
"n",
"]",
"break",
"end",
"end",
"if",
"type",
"tok",
"=",
"build_token",
"(",
"resolved_type",
",",
"val",
")",
"@pos",
"+=",
"m",
".",
"end",
"(",
"0",
")",
"tok",
"=",
"self",
".",
"class",
".",
"callables",
"[",
"type",
"]",
".",
"call",
"(",
"tok",
")",
"if",
"self",
".",
"class",
".",
"callables",
"[",
"type",
"]",
"if",
"tok",
"&&",
"tok",
".",
"type",
"return",
"tok",
"else",
"next",
"end",
"end",
"end",
"if",
"self",
".",
"class",
".",
"literals_list",
"[",
"@input",
"[",
"@pos",
"]",
"]",
"tok",
"=",
"build_token",
"(",
"@input",
"[",
"@pos",
"]",
",",
"@input",
"[",
"@pos",
"]",
")",
"matched",
"=",
"true",
"@pos",
"+=",
"1",
"return",
"tok",
"end",
"if",
"self",
".",
"class",
".",
"error_hander",
"pos",
"=",
"@pos",
"tok",
"=",
"build_token",
"(",
":error",
",",
"@input",
"[",
"@pos",
"]",
")",
"tok",
"=",
"self",
".",
"class",
".",
"error_hander",
".",
"call",
"(",
"tok",
")",
"if",
"pos",
"==",
"@pos",
"raise",
"LexError",
".",
"new",
"(",
"\"Illegal character '#{@input[@pos]}' at index #{@pos}\"",
")",
"else",
"return",
"tok",
"if",
"tok",
"&&",
"tok",
".",
"type",
"end",
"else",
"raise",
"LexError",
".",
"new",
"(",
"\"Illegal character '#{@input[@pos]}' at index #{@pos}\"",
")",
"end",
"end",
"return",
"nil",
"end"
] | Processes the next token in input
This is the main interface to lexer. It returns next available token or **nil**
if there are no more tokens available in the input string.
{#each} Raises {LexError} if the input cannot be processed. This happens if
there were no matches by 'token' rules and no matches by 'literals' rule.
If the {.on_error} handler is not set, the exception will be raised immediately,
however, if the handler is set, the eception will be raised only if the {#pos}
after returning from error handler is still unchanged.
@api public
@raise [LexError] if the input cannot be processed
@return [LexToken] if the next chunk of input was processed successfully
@return [nil] if there are no more tokens available in input
@example
lex = MyLexer.new("hello WORLD")
t = lex.next
puts "#{tok.type} -> #{tok.value}" #=> "LOWERS -> hello"
t = lex.next
puts "#{tok.type} -> #{tok.value}" #=> "UPPERS -> WORLD"
t = lex.next # => nil | [
"Processes",
"the",
"next",
"token",
"in",
"input"
] | d5a58194f73a15adb4d7c9940557838641bb2a31 | https://github.com/farcaller/rly/blob/d5a58194f73a15adb4d7c9940557838641bb2a31/lib/rly/lex.rb#L119-L176 | train |
eltiare/carrierwave-vips | lib/carrierwave/vips.rb | CarrierWave.Vips.auto_orient | def auto_orient
manipulate! do |image|
o = image.get('exif-Orientation').to_i rescue nil
o ||= image.get('exif-ifd0-Orientation').to_i rescue 1
case o
when 1
# Do nothing, everything is peachy
when 6
image.rot270
when 8
image.rot180
when 3
image.rot90
else
raise('Invalid value for Orientation: ' + o.to_s)
end
image.set_type GObject::GSTR_TYPE, 'exif-Orientation', ''
image.set_type GObject::GSTR_TYPE, 'exif-ifd0-Orientation', ''
end
end | ruby | def auto_orient
manipulate! do |image|
o = image.get('exif-Orientation').to_i rescue nil
o ||= image.get('exif-ifd0-Orientation').to_i rescue 1
case o
when 1
# Do nothing, everything is peachy
when 6
image.rot270
when 8
image.rot180
when 3
image.rot90
else
raise('Invalid value for Orientation: ' + o.to_s)
end
image.set_type GObject::GSTR_TYPE, 'exif-Orientation', ''
image.set_type GObject::GSTR_TYPE, 'exif-ifd0-Orientation', ''
end
end | [
"def",
"auto_orient",
"manipulate!",
"do",
"|",
"image",
"|",
"o",
"=",
"image",
".",
"get",
"(",
"'exif-Orientation'",
")",
".",
"to_i",
"rescue",
"nil",
"o",
"||=",
"image",
".",
"get",
"(",
"'exif-ifd0-Orientation'",
")",
".",
"to_i",
"rescue",
"1",
"case",
"o",
"when",
"1",
"when",
"6",
"image",
".",
"rot270",
"when",
"8",
"image",
".",
"rot180",
"when",
"3",
"image",
".",
"rot90",
"else",
"raise",
"(",
"'Invalid value for Orientation: '",
"+",
"o",
".",
"to_s",
")",
"end",
"image",
".",
"set_type",
"GObject",
"::",
"GSTR_TYPE",
",",
"'exif-Orientation'",
",",
"''",
"image",
".",
"set_type",
"GObject",
"::",
"GSTR_TYPE",
",",
"'exif-ifd0-Orientation'",
",",
"''",
"end",
"end"
] | Read the camera EXIF data to determine orientation and adjust accordingly | [
"Read",
"the",
"camera",
"EXIF",
"data",
"to",
"determine",
"orientation",
"and",
"adjust",
"accordingly"
] | d09a95513e0b54dca18264b63944ae31b2368bda | https://github.com/eltiare/carrierwave-vips/blob/d09a95513e0b54dca18264b63944ae31b2368bda/lib/carrierwave/vips.rb#L55-L74 | train |
eltiare/carrierwave-vips | lib/carrierwave/vips.rb | CarrierWave.Vips.convert | def convert(f, opts = {})
opts = opts.dup
f = f.to_s.downcase
allowed = %w(jpeg jpg png)
raise ArgumentError, "Format must be one of: #{allowed.join(',')}" unless allowed.include?(f)
self.format_override = f == 'jpeg' ? 'jpg' : f
opts[:Q] = opts.delete(:quality) if opts.has_key?(:quality)
write_opts.merge!(opts)
get_image
end | ruby | def convert(f, opts = {})
opts = opts.dup
f = f.to_s.downcase
allowed = %w(jpeg jpg png)
raise ArgumentError, "Format must be one of: #{allowed.join(',')}" unless allowed.include?(f)
self.format_override = f == 'jpeg' ? 'jpg' : f
opts[:Q] = opts.delete(:quality) if opts.has_key?(:quality)
write_opts.merge!(opts)
get_image
end | [
"def",
"convert",
"(",
"f",
",",
"opts",
"=",
"{",
"}",
")",
"opts",
"=",
"opts",
".",
"dup",
"f",
"=",
"f",
".",
"to_s",
".",
"downcase",
"allowed",
"=",
"%w(",
"jpeg",
"jpg",
"png",
")",
"raise",
"ArgumentError",
",",
"\"Format must be one of: #{allowed.join(',')}\"",
"unless",
"allowed",
".",
"include?",
"(",
"f",
")",
"self",
".",
"format_override",
"=",
"f",
"==",
"'jpeg'",
"?",
"'jpg'",
":",
"f",
"opts",
"[",
":Q",
"]",
"=",
"opts",
".",
"delete",
"(",
":quality",
")",
"if",
"opts",
".",
"has_key?",
"(",
":quality",
")",
"write_opts",
".",
"merge!",
"(",
"opts",
")",
"get_image",
"end"
] | Convert the file to a different format
=== Parameters
[f (String)] the format for the file format (jpeg, png)
[opts (Hash)] options to be passed to converting function (ie, :interlace => true for png) | [
"Convert",
"the",
"file",
"to",
"a",
"different",
"format"
] | d09a95513e0b54dca18264b63944ae31b2368bda | https://github.com/eltiare/carrierwave-vips/blob/d09a95513e0b54dca18264b63944ae31b2368bda/lib/carrierwave/vips.rb#L106-L115 | train |
eltiare/carrierwave-vips | lib/carrierwave/vips.rb | CarrierWave.Vips.resize_to_fill | def resize_to_fill(new_width, new_height)
manipulate! do |image|
image = resize_image image, new_width, new_height, :max
if image.width > new_width
top = 0
left = (image.width - new_width) / 2
elsif image.height > new_height
left = 0
top = (image.height - new_height) / 2
else
left = 0
top = 0
end
# Floating point errors can sometimes chop off an extra pixel
# TODO: fix all the universe so that floating point errors never happen again
new_height = image.height if image.height < new_height
new_width = image.width if image.width < new_width
image.extract_area(left, top, new_width, new_height)
end
end | ruby | def resize_to_fill(new_width, new_height)
manipulate! do |image|
image = resize_image image, new_width, new_height, :max
if image.width > new_width
top = 0
left = (image.width - new_width) / 2
elsif image.height > new_height
left = 0
top = (image.height - new_height) / 2
else
left = 0
top = 0
end
# Floating point errors can sometimes chop off an extra pixel
# TODO: fix all the universe so that floating point errors never happen again
new_height = image.height if image.height < new_height
new_width = image.width if image.width < new_width
image.extract_area(left, top, new_width, new_height)
end
end | [
"def",
"resize_to_fill",
"(",
"new_width",
",",
"new_height",
")",
"manipulate!",
"do",
"|",
"image",
"|",
"image",
"=",
"resize_image",
"image",
",",
"new_width",
",",
"new_height",
",",
":max",
"if",
"image",
".",
"width",
">",
"new_width",
"top",
"=",
"0",
"left",
"=",
"(",
"image",
".",
"width",
"-",
"new_width",
")",
"/",
"2",
"elsif",
"image",
".",
"height",
">",
"new_height",
"left",
"=",
"0",
"top",
"=",
"(",
"image",
".",
"height",
"-",
"new_height",
")",
"/",
"2",
"else",
"left",
"=",
"0",
"top",
"=",
"0",
"end",
"new_height",
"=",
"image",
".",
"height",
"if",
"image",
".",
"height",
"<",
"new_height",
"new_width",
"=",
"image",
".",
"width",
"if",
"image",
".",
"width",
"<",
"new_width",
"image",
".",
"extract_area",
"(",
"left",
",",
"top",
",",
"new_width",
",",
"new_height",
")",
"end",
"end"
] | Resize the image to fit within the specified dimensions while retaining
the aspect ratio of the original image. If necessary, crop the image in
the larger dimension.
=== Parameters
[width (Integer)] the width to scale the image to
[height (Integer)] the height to scale the image to | [
"Resize",
"the",
"image",
"to",
"fit",
"within",
"the",
"specified",
"dimensions",
"while",
"retaining",
"the",
"aspect",
"ratio",
"of",
"the",
"original",
"image",
".",
"If",
"necessary",
"crop",
"the",
"image",
"in",
"the",
"larger",
"dimension",
"."
] | d09a95513e0b54dca18264b63944ae31b2368bda | https://github.com/eltiare/carrierwave-vips/blob/d09a95513e0b54dca18264b63944ae31b2368bda/lib/carrierwave/vips.rb#L146-L170 | train |
eltiare/carrierwave-vips | lib/carrierwave/vips.rb | CarrierWave.Vips.resize_to_limit | def resize_to_limit(new_width, new_height)
manipulate! do |image|
image = resize_image(image,new_width,new_height) if new_width < image.width || new_height < image.height
image
end
end | ruby | def resize_to_limit(new_width, new_height)
manipulate! do |image|
image = resize_image(image,new_width,new_height) if new_width < image.width || new_height < image.height
image
end
end | [
"def",
"resize_to_limit",
"(",
"new_width",
",",
"new_height",
")",
"manipulate!",
"do",
"|",
"image",
"|",
"image",
"=",
"resize_image",
"(",
"image",
",",
"new_width",
",",
"new_height",
")",
"if",
"new_width",
"<",
"image",
".",
"width",
"||",
"new_height",
"<",
"image",
".",
"height",
"image",
"end",
"end"
] | Resize the image to fit within the specified dimensions while retaining
the original aspect ratio. Will only resize the image if it is larger than the
specified dimensions. The resulting image may be shorter or narrower than specified
in the smaller dimension but will not be larger than the specified values.
=== Parameters
[width (Integer)] the width to scale the image to
[height (Integer)] the height to scale the image to | [
"Resize",
"the",
"image",
"to",
"fit",
"within",
"the",
"specified",
"dimensions",
"while",
"retaining",
"the",
"original",
"aspect",
"ratio",
".",
"Will",
"only",
"resize",
"the",
"image",
"if",
"it",
"is",
"larger",
"than",
"the",
"specified",
"dimensions",
".",
"The",
"resulting",
"image",
"may",
"be",
"shorter",
"or",
"narrower",
"than",
"specified",
"in",
"the",
"smaller",
"dimension",
"but",
"will",
"not",
"be",
"larger",
"than",
"the",
"specified",
"values",
"."
] | d09a95513e0b54dca18264b63944ae31b2368bda | https://github.com/eltiare/carrierwave-vips/blob/d09a95513e0b54dca18264b63944ae31b2368bda/lib/carrierwave/vips.rb#L183-L188 | train |
prometheus-ev/jekyll-localization | lib/jekyll/localization.rb | Jekyll.Convertible.read_yaml | def read_yaml(base, name, alt = true)
_localization_original_read_yaml(base, name)
read_alternate_language_content(base, name) if alt && content.empty?
end | ruby | def read_yaml(base, name, alt = true)
_localization_original_read_yaml(base, name)
read_alternate_language_content(base, name) if alt && content.empty?
end | [
"def",
"read_yaml",
"(",
"base",
",",
"name",
",",
"alt",
"=",
"true",
")",
"_localization_original_read_yaml",
"(",
"base",
",",
"name",
")",
"read_alternate_language_content",
"(",
"base",
",",
"name",
")",
"if",
"alt",
"&&",
"content",
".",
"empty?",
"end"
] | Overwrites the original method to optionally set the content of a
file with no content in it to the content of a file with another
language which does have content in it. | [
"Overwrites",
"the",
"original",
"method",
"to",
"optionally",
"set",
"the",
"content",
"of",
"a",
"file",
"with",
"no",
"content",
"in",
"it",
"to",
"the",
"content",
"of",
"a",
"file",
"with",
"another",
"language",
"which",
"does",
"have",
"content",
"in",
"it",
"."
] | 753a293f0efbb252a6a0e1161994ac65d0c50e60 | https://github.com/prometheus-ev/jekyll-localization/blob/753a293f0efbb252a6a0e1161994ac65d0c50e60/lib/jekyll/localization.rb#L187-L190 | train |
prometheus-ev/jekyll-localization | lib/jekyll/localization.rb | Jekyll.Page.destination | def destination(dest)
# The url needs to be unescaped in order to preserve the correct filename
path = File.join(dest, @dir, CGI.unescape(url))
if ext == '.html' && _localization_original_url !~ /\.html\z/
path.sub!(Localization::LANG_END_RE, '')
File.join(path, "index#{ext}#{@lang_ext}")
else
path
end
end | ruby | def destination(dest)
# The url needs to be unescaped in order to preserve the correct filename
path = File.join(dest, @dir, CGI.unescape(url))
if ext == '.html' && _localization_original_url !~ /\.html\z/
path.sub!(Localization::LANG_END_RE, '')
File.join(path, "index#{ext}#{@lang_ext}")
else
path
end
end | [
"def",
"destination",
"(",
"dest",
")",
"path",
"=",
"File",
".",
"join",
"(",
"dest",
",",
"@dir",
",",
"CGI",
".",
"unescape",
"(",
"url",
")",
")",
"if",
"ext",
"==",
"'.html'",
"&&",
"_localization_original_url",
"!~",
"/",
"\\.",
"\\z",
"/",
"path",
".",
"sub!",
"(",
"Localization",
"::",
"LANG_END_RE",
",",
"''",
")",
"File",
".",
"join",
"(",
"path",
",",
"\"index#{ext}#{@lang_ext}\"",
")",
"else",
"path",
"end",
"end"
] | Overwrites the original method to cater for language extension in output
file name. | [
"Overwrites",
"the",
"original",
"method",
"to",
"cater",
"for",
"language",
"extension",
"in",
"output",
"file",
"name",
"."
] | 753a293f0efbb252a6a0e1161994ac65d0c50e60 | https://github.com/prometheus-ev/jekyll-localization/blob/753a293f0efbb252a6a0e1161994ac65d0c50e60/lib/jekyll/localization.rb#L207-L217 | train |
prometheus-ev/jekyll-localization | lib/jekyll/localization.rb | Jekyll.Page.process | def process(name)
self.ext = File.extname(name)
self.basename = name[0 .. -self.ext.length-1].
sub(Localization::LANG_END_RE, '')
end | ruby | def process(name)
self.ext = File.extname(name)
self.basename = name[0 .. -self.ext.length-1].
sub(Localization::LANG_END_RE, '')
end | [
"def",
"process",
"(",
"name",
")",
"self",
".",
"ext",
"=",
"File",
".",
"extname",
"(",
"name",
")",
"self",
".",
"basename",
"=",
"name",
"[",
"0",
"..",
"-",
"self",
".",
"ext",
".",
"length",
"-",
"1",
"]",
".",
"sub",
"(",
"Localization",
"::",
"LANG_END_RE",
",",
"''",
")",
"end"
] | Overwrites the original method to filter the language extension from
basename | [
"Overwrites",
"the",
"original",
"method",
"to",
"filter",
"the",
"language",
"extension",
"from",
"basename"
] | 753a293f0efbb252a6a0e1161994ac65d0c50e60 | https://github.com/prometheus-ev/jekyll-localization/blob/753a293f0efbb252a6a0e1161994ac65d0c50e60/lib/jekyll/localization.rb#L223-L227 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.stop | def stop(wait_seconds_before_close = 2, gracefully = true)
# always signal shutdown
shutdown if gracefully
# wait if some connection(s) need(s) more time to handle shutdown
sleep wait_seconds_before_close if connections?
# drop tcp_servers while raising SmtpdStopServiceException
@connections_mutex.synchronize do
@tcp_server_threads.each do |tcp_server_thread|
tcp_server_thread.raise SmtpdStopServiceException if tcp_server_thread
end
end
# wait if some connection(s) still need(s) more time to come down
sleep wait_seconds_before_close if connections? || !stopped?
end | ruby | def stop(wait_seconds_before_close = 2, gracefully = true)
# always signal shutdown
shutdown if gracefully
# wait if some connection(s) need(s) more time to handle shutdown
sleep wait_seconds_before_close if connections?
# drop tcp_servers while raising SmtpdStopServiceException
@connections_mutex.synchronize do
@tcp_server_threads.each do |tcp_server_thread|
tcp_server_thread.raise SmtpdStopServiceException if tcp_server_thread
end
end
# wait if some connection(s) still need(s) more time to come down
sleep wait_seconds_before_close if connections? || !stopped?
end | [
"def",
"stop",
"(",
"wait_seconds_before_close",
"=",
"2",
",",
"gracefully",
"=",
"true",
")",
"shutdown",
"if",
"gracefully",
"sleep",
"wait_seconds_before_close",
"if",
"connections?",
"@connections_mutex",
".",
"synchronize",
"do",
"@tcp_server_threads",
".",
"each",
"do",
"|",
"tcp_server_thread",
"|",
"tcp_server_thread",
".",
"raise",
"SmtpdStopServiceException",
"if",
"tcp_server_thread",
"end",
"end",
"sleep",
"wait_seconds_before_close",
"if",
"connections?",
"||",
"!",
"stopped?",
"end"
] | Stop the server | [
"Stop",
"the",
"server"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L48-L61 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.on_auth_event | def on_auth_event(ctx, authorization_id, authentication_id, authentication)
# if authentification is used, override this event
# and implement your own user management.
# otherwise all authentifications are blocked per default
logger.debug("Deny access from #{ctx[:server][:remote_ip]}:#{ctx[:server][:remote_port]} for #{authentication_id}" + (authorization_id == '' ? '' : "/#{authorization_id}") + " with #{authentication}")
raise Smtpd535Exception
end | ruby | def on_auth_event(ctx, authorization_id, authentication_id, authentication)
# if authentification is used, override this event
# and implement your own user management.
# otherwise all authentifications are blocked per default
logger.debug("Deny access from #{ctx[:server][:remote_ip]}:#{ctx[:server][:remote_port]} for #{authentication_id}" + (authorization_id == '' ? '' : "/#{authorization_id}") + " with #{authentication}")
raise Smtpd535Exception
end | [
"def",
"on_auth_event",
"(",
"ctx",
",",
"authorization_id",
",",
"authentication_id",
",",
"authentication",
")",
"logger",
".",
"debug",
"(",
"\"Deny access from #{ctx[:server][:remote_ip]}:#{ctx[:server][:remote_port]} for #{authentication_id}\"",
"+",
"(",
"authorization_id",
"==",
"''",
"?",
"''",
":",
"\"/#{authorization_id}\"",
")",
"+",
"\" with #{authentication}\"",
")",
"raise",
"Smtpd535Exception",
"end"
] | check the authentification on AUTH
if any value returned, that will be used for ongoing processing
otherwise the original value will be used for authorization_id | [
"check",
"the",
"authentification",
"on",
"AUTH",
"if",
"any",
"value",
"returned",
"that",
"will",
"be",
"used",
"for",
"ongoing",
"processing",
"otherwise",
"the",
"original",
"value",
"will",
"be",
"used",
"for",
"authorization_id"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L296-L302 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.serve_service | def serve_service
raise 'Service was already started' unless stopped?
# set flag to signal shutdown by stop / shutdown command
@shutdown = false
# instantiate the service for alls @hosts and @ports
@hosts.each_with_index do |host, index|
# instantiate the service for each host and port
# if host is empty "" wildcard (all) interfaces are used
# otherwise it will be bind to single host ip only
# if ports at index is not specified, use last item
# of ports array. if multiple ports specified by
# item like 2525:3535:4545, then all are instantiated
ports_for_host = (index < @ports.length ? @ports[index] : @ports.last).to_s.split(':')
# loop all ports for that host
ports_for_host.each do |port|
serve_service_on_host_and_port(host, port)
end
end
end | ruby | def serve_service
raise 'Service was already started' unless stopped?
# set flag to signal shutdown by stop / shutdown command
@shutdown = false
# instantiate the service for alls @hosts and @ports
@hosts.each_with_index do |host, index|
# instantiate the service for each host and port
# if host is empty "" wildcard (all) interfaces are used
# otherwise it will be bind to single host ip only
# if ports at index is not specified, use last item
# of ports array. if multiple ports specified by
# item like 2525:3535:4545, then all are instantiated
ports_for_host = (index < @ports.length ? @ports[index] : @ports.last).to_s.split(':')
# loop all ports for that host
ports_for_host.each do |port|
serve_service_on_host_and_port(host, port)
end
end
end | [
"def",
"serve_service",
"raise",
"'Service was already started'",
"unless",
"stopped?",
"@shutdown",
"=",
"false",
"@hosts",
".",
"each_with_index",
"do",
"|",
"host",
",",
"index",
"|",
"ports_for_host",
"=",
"(",
"index",
"<",
"@ports",
".",
"length",
"?",
"@ports",
"[",
"index",
"]",
":",
"@ports",
".",
"last",
")",
".",
"to_s",
".",
"split",
"(",
"':'",
")",
"ports_for_host",
".",
"each",
"do",
"|",
"port",
"|",
"serve_service_on_host_and_port",
"(",
"host",
",",
"port",
")",
"end",
"end",
"end"
] | Start the listeners for all hosts | [
"Start",
"the",
"listeners",
"for",
"all",
"hosts"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L347-L367 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.serve_service_on_host_and_port | def serve_service_on_host_and_port(host, port)
# log information
logger.info('Running service on ' + (host == '' ? '<any>' : host) + ':' + port.to_s)
# instantiate the service for host and port
# if host is empty "" wildcard (all) interfaces are used
# otherwise it will be bind to single host ip only
tcp_server = TCPServer.new(host, port)
# append this server to the list of TCPServers
@tcp_servers << tcp_server
# run thread until shutdown
@tcp_server_threads << Thread.new do
begin
# always check for shutdown request
until shutdown?
# get new client and start additional thread
# to handle client process
client = tcp_server.accept
Thread.new(client) do |io|
# add to list of connections
@connections << Thread.current
# handle connection
begin
# initialize a session storage hash
Thread.current[:session] = {}
# process smtp service on io socket
io = serve_client(Thread.current[:session], io)
# save returned io value due to maybe
# established ssl io socket
rescue SmtpdStopConnectionException
# ignore this exception due to service shutdown
rescue StandardError => e
# log fatal error while handling connection
logger.fatal(e.backtrace.join("\n"))
ensure
begin
# always gracefully shutdown connection.
# if the io object was overriden by the
# result from serve_client() due to ssl
# io, the ssl + io socket will be closed
io.close
rescue StandardError
# ignore any exception from here
end
# remove closed session from connections
@connections_mutex.synchronize do
# drop this thread from connections
@connections.delete(Thread.current)
# drop this thread from processings
@processings.delete(Thread.current)
# signal mutex for next waiting thread
@connections_cv.signal
end
end
end
end
rescue SmtpdStopServiceException
# ignore this exception due to service shutdown
rescue StandardError => e
# log fatal error while starting new thread
logger.fatal(e.backtrace.join("\n"))
ensure
begin
# drop the service
tcp_server.close
# remove from list
@tcp_servers.delete(tcp_server)
# reset local var
tcp_server = nil
rescue StandardError
# ignor any error from here
end
if shutdown?
# wait for finishing opened connections
@connections_mutex.synchronize do
@connections_cv.wait(@connections_mutex) until @connections.empty?
end
else
# drop any open session immediately
@connections.each { |c| c.raise SmtpdStopConnectionException }
end
# remove this thread from list
@tcp_server_threads.delete(Thread.current)
end
end
end | ruby | def serve_service_on_host_and_port(host, port)
# log information
logger.info('Running service on ' + (host == '' ? '<any>' : host) + ':' + port.to_s)
# instantiate the service for host and port
# if host is empty "" wildcard (all) interfaces are used
# otherwise it will be bind to single host ip only
tcp_server = TCPServer.new(host, port)
# append this server to the list of TCPServers
@tcp_servers << tcp_server
# run thread until shutdown
@tcp_server_threads << Thread.new do
begin
# always check for shutdown request
until shutdown?
# get new client and start additional thread
# to handle client process
client = tcp_server.accept
Thread.new(client) do |io|
# add to list of connections
@connections << Thread.current
# handle connection
begin
# initialize a session storage hash
Thread.current[:session] = {}
# process smtp service on io socket
io = serve_client(Thread.current[:session], io)
# save returned io value due to maybe
# established ssl io socket
rescue SmtpdStopConnectionException
# ignore this exception due to service shutdown
rescue StandardError => e
# log fatal error while handling connection
logger.fatal(e.backtrace.join("\n"))
ensure
begin
# always gracefully shutdown connection.
# if the io object was overriden by the
# result from serve_client() due to ssl
# io, the ssl + io socket will be closed
io.close
rescue StandardError
# ignore any exception from here
end
# remove closed session from connections
@connections_mutex.synchronize do
# drop this thread from connections
@connections.delete(Thread.current)
# drop this thread from processings
@processings.delete(Thread.current)
# signal mutex for next waiting thread
@connections_cv.signal
end
end
end
end
rescue SmtpdStopServiceException
# ignore this exception due to service shutdown
rescue StandardError => e
# log fatal error while starting new thread
logger.fatal(e.backtrace.join("\n"))
ensure
begin
# drop the service
tcp_server.close
# remove from list
@tcp_servers.delete(tcp_server)
# reset local var
tcp_server = nil
rescue StandardError
# ignor any error from here
end
if shutdown?
# wait for finishing opened connections
@connections_mutex.synchronize do
@connections_cv.wait(@connections_mutex) until @connections.empty?
end
else
# drop any open session immediately
@connections.each { |c| c.raise SmtpdStopConnectionException }
end
# remove this thread from list
@tcp_server_threads.delete(Thread.current)
end
end
end | [
"def",
"serve_service_on_host_and_port",
"(",
"host",
",",
"port",
")",
"logger",
".",
"info",
"(",
"'Running service on '",
"+",
"(",
"host",
"==",
"''",
"?",
"'<any>'",
":",
"host",
")",
"+",
"':'",
"+",
"port",
".",
"to_s",
")",
"tcp_server",
"=",
"TCPServer",
".",
"new",
"(",
"host",
",",
"port",
")",
"@tcp_servers",
"<<",
"tcp_server",
"@tcp_server_threads",
"<<",
"Thread",
".",
"new",
"do",
"begin",
"until",
"shutdown?",
"client",
"=",
"tcp_server",
".",
"accept",
"Thread",
".",
"new",
"(",
"client",
")",
"do",
"|",
"io",
"|",
"@connections",
"<<",
"Thread",
".",
"current",
"begin",
"Thread",
".",
"current",
"[",
":session",
"]",
"=",
"{",
"}",
"io",
"=",
"serve_client",
"(",
"Thread",
".",
"current",
"[",
":session",
"]",
",",
"io",
")",
"rescue",
"SmtpdStopConnectionException",
"rescue",
"StandardError",
"=>",
"e",
"logger",
".",
"fatal",
"(",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"begin",
"io",
".",
"close",
"rescue",
"StandardError",
"end",
"@connections_mutex",
".",
"synchronize",
"do",
"@connections",
".",
"delete",
"(",
"Thread",
".",
"current",
")",
"@processings",
".",
"delete",
"(",
"Thread",
".",
"current",
")",
"@connections_cv",
".",
"signal",
"end",
"end",
"end",
"end",
"rescue",
"SmtpdStopServiceException",
"rescue",
"StandardError",
"=>",
"e",
"logger",
".",
"fatal",
"(",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"begin",
"tcp_server",
".",
"close",
"@tcp_servers",
".",
"delete",
"(",
"tcp_server",
")",
"tcp_server",
"=",
"nil",
"rescue",
"StandardError",
"end",
"if",
"shutdown?",
"@connections_mutex",
".",
"synchronize",
"do",
"@connections_cv",
".",
"wait",
"(",
"@connections_mutex",
")",
"until",
"@connections",
".",
"empty?",
"end",
"else",
"@connections",
".",
"each",
"{",
"|",
"c",
"|",
"c",
".",
"raise",
"SmtpdStopConnectionException",
"}",
"end",
"@tcp_server_threads",
".",
"delete",
"(",
"Thread",
".",
"current",
")",
"end",
"end",
"end"
] | Start the listener thread on single host and port | [
"Start",
"the",
"listener",
"thread",
"on",
"single",
"host",
"and",
"port"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L370-L455 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.process_reset_session | def process_reset_session(session, connection_initialize = false)
# set active command sequence info
session[:cmd_sequence] = connection_initialize ? :CMD_HELO : :CMD_RSET
# drop any auth challenge
session[:auth_challenge] = {}
# test existing of :ctx hash
session[:ctx] || session[:ctx] = {}
# reset server values (only on connection start)
if connection_initialize
# create or rebuild :ctx hash
session[:ctx].merge!(
server: {
local_host: '',
local_ip: '',
local_port: '',
local_response: '',
remote_host: '',
remote_ip: '',
remote_port: '',
helo: '',
helo_response: '',
connected: '',
exceptions: 0,
authorization_id: '',
authentication_id: '',
authenticated: '',
encrypted: ''
}
)
end
# reset envelope values
session[:ctx].merge!(
envelope: {
from: '',
to: [],
encoding_body: '',
encoding_utf8: ''
}
)
# reset message data
session[:ctx].merge!(
message: {
received: -1,
delivered: -1,
bytesize: -1,
headers: '',
crlf: "\r\n",
data: ''
}
)
end | ruby | def process_reset_session(session, connection_initialize = false)
# set active command sequence info
session[:cmd_sequence] = connection_initialize ? :CMD_HELO : :CMD_RSET
# drop any auth challenge
session[:auth_challenge] = {}
# test existing of :ctx hash
session[:ctx] || session[:ctx] = {}
# reset server values (only on connection start)
if connection_initialize
# create or rebuild :ctx hash
session[:ctx].merge!(
server: {
local_host: '',
local_ip: '',
local_port: '',
local_response: '',
remote_host: '',
remote_ip: '',
remote_port: '',
helo: '',
helo_response: '',
connected: '',
exceptions: 0,
authorization_id: '',
authentication_id: '',
authenticated: '',
encrypted: ''
}
)
end
# reset envelope values
session[:ctx].merge!(
envelope: {
from: '',
to: [],
encoding_body: '',
encoding_utf8: ''
}
)
# reset message data
session[:ctx].merge!(
message: {
received: -1,
delivered: -1,
bytesize: -1,
headers: '',
crlf: "\r\n",
data: ''
}
)
end | [
"def",
"process_reset_session",
"(",
"session",
",",
"connection_initialize",
"=",
"false",
")",
"session",
"[",
":cmd_sequence",
"]",
"=",
"connection_initialize",
"?",
":CMD_HELO",
":",
":CMD_RSET",
"session",
"[",
":auth_challenge",
"]",
"=",
"{",
"}",
"session",
"[",
":ctx",
"]",
"||",
"session",
"[",
":ctx",
"]",
"=",
"{",
"}",
"if",
"connection_initialize",
"session",
"[",
":ctx",
"]",
".",
"merge!",
"(",
"server",
":",
"{",
"local_host",
":",
"''",
",",
"local_ip",
":",
"''",
",",
"local_port",
":",
"''",
",",
"local_response",
":",
"''",
",",
"remote_host",
":",
"''",
",",
"remote_ip",
":",
"''",
",",
"remote_port",
":",
"''",
",",
"helo",
":",
"''",
",",
"helo_response",
":",
"''",
",",
"connected",
":",
"''",
",",
"exceptions",
":",
"0",
",",
"authorization_id",
":",
"''",
",",
"authentication_id",
":",
"''",
",",
"authenticated",
":",
"''",
",",
"encrypted",
":",
"''",
"}",
")",
"end",
"session",
"[",
":ctx",
"]",
".",
"merge!",
"(",
"envelope",
":",
"{",
"from",
":",
"''",
",",
"to",
":",
"[",
"]",
",",
"encoding_body",
":",
"''",
",",
"encoding_utf8",
":",
"''",
"}",
")",
"session",
"[",
":ctx",
"]",
".",
"merge!",
"(",
"message",
":",
"{",
"received",
":",
"-",
"1",
",",
"delivered",
":",
"-",
"1",
",",
"bytesize",
":",
"-",
"1",
",",
"headers",
":",
"''",
",",
"crlf",
":",
"\"\\r\\n\"",
",",
"data",
":",
"''",
"}",
")",
"end"
] | reset the context of current smtpd dialog | [
"reset",
"the",
"context",
"of",
"current",
"smtpd",
"dialog"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L1048-L1098 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server.rb | MidiSmtpServer.Smtpd.process_auth_plain | def process_auth_plain(session, encoded_auth_response)
begin
# extract auth id (and password)
@auth_values = Base64.decode64(encoded_auth_response).split("\x00")
# check for valid credentials parameters
raise Smtpd500Exception unless @auth_values.length == 3
# call event function to test credentials
return_value = on_auth_event(session[:ctx], @auth_values[0], @auth_values[1], @auth_values[2])
if return_value
# overwrite data with returned value as authorization id
@auth_values[0] = return_value
end
# save authentication information to ctx
session[:ctx][:server][:authorization_id] = @auth_values[0].to_s.empty? ? @auth_values[1] : @auth_values[0]
session[:ctx][:server][:authentication_id] = @auth_values[1]
session[:ctx][:server][:authenticated] = Time.now.utc
# response code
return '235 OK'
ensure
# whatever happens in this check, reset next sequence
session[:cmd_sequence] = :CMD_RSET
end
end | ruby | def process_auth_plain(session, encoded_auth_response)
begin
# extract auth id (and password)
@auth_values = Base64.decode64(encoded_auth_response).split("\x00")
# check for valid credentials parameters
raise Smtpd500Exception unless @auth_values.length == 3
# call event function to test credentials
return_value = on_auth_event(session[:ctx], @auth_values[0], @auth_values[1], @auth_values[2])
if return_value
# overwrite data with returned value as authorization id
@auth_values[0] = return_value
end
# save authentication information to ctx
session[:ctx][:server][:authorization_id] = @auth_values[0].to_s.empty? ? @auth_values[1] : @auth_values[0]
session[:ctx][:server][:authentication_id] = @auth_values[1]
session[:ctx][:server][:authenticated] = Time.now.utc
# response code
return '235 OK'
ensure
# whatever happens in this check, reset next sequence
session[:cmd_sequence] = :CMD_RSET
end
end | [
"def",
"process_auth_plain",
"(",
"session",
",",
"encoded_auth_response",
")",
"begin",
"@auth_values",
"=",
"Base64",
".",
"decode64",
"(",
"encoded_auth_response",
")",
".",
"split",
"(",
"\"\\x00\"",
")",
"raise",
"Smtpd500Exception",
"unless",
"@auth_values",
".",
"length",
"==",
"3",
"return_value",
"=",
"on_auth_event",
"(",
"session",
"[",
":ctx",
"]",
",",
"@auth_values",
"[",
"0",
"]",
",",
"@auth_values",
"[",
"1",
"]",
",",
"@auth_values",
"[",
"2",
"]",
")",
"if",
"return_value",
"@auth_values",
"[",
"0",
"]",
"=",
"return_value",
"end",
"session",
"[",
":ctx",
"]",
"[",
":server",
"]",
"[",
":authorization_id",
"]",
"=",
"@auth_values",
"[",
"0",
"]",
".",
"to_s",
".",
"empty?",
"?",
"@auth_values",
"[",
"1",
"]",
":",
"@auth_values",
"[",
"0",
"]",
"session",
"[",
":ctx",
"]",
"[",
":server",
"]",
"[",
":authentication_id",
"]",
"=",
"@auth_values",
"[",
"1",
"]",
"session",
"[",
":ctx",
"]",
"[",
":server",
"]",
"[",
":authenticated",
"]",
"=",
"Time",
".",
"now",
".",
"utc",
"return",
"'235 OK'",
"ensure",
"session",
"[",
":cmd_sequence",
"]",
"=",
":CMD_RSET",
"end",
"end"
] | handle plain authentification | [
"handle",
"plain",
"authentification"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server.rb#L1101-L1124 | train |
amoniacou/danthes | lib/danthes/view_helpers.rb | Danthes.ViewHelpers.subscribe_to | def subscribe_to(channel, opts = {})
js_tag = opts.delete(:include_js_tag){ true }
subscription = Danthes.subscription(channel: channel)
content = raw("if (typeof Danthes != 'undefined') { Danthes.sign(#{subscription.to_json}) }")
js_tag ? content_tag('script', content, type: 'text/javascript') : content
end | ruby | def subscribe_to(channel, opts = {})
js_tag = opts.delete(:include_js_tag){ true }
subscription = Danthes.subscription(channel: channel)
content = raw("if (typeof Danthes != 'undefined') { Danthes.sign(#{subscription.to_json}) }")
js_tag ? content_tag('script', content, type: 'text/javascript') : content
end | [
"def",
"subscribe_to",
"(",
"channel",
",",
"opts",
"=",
"{",
"}",
")",
"js_tag",
"=",
"opts",
".",
"delete",
"(",
":include_js_tag",
")",
"{",
"true",
"}",
"subscription",
"=",
"Danthes",
".",
"subscription",
"(",
"channel",
":",
"channel",
")",
"content",
"=",
"raw",
"(",
"\"if (typeof Danthes != 'undefined') { Danthes.sign(#{subscription.to_json}) }\"",
")",
"js_tag",
"?",
"content_tag",
"(",
"'script'",
",",
"content",
",",
"type",
":",
"'text/javascript'",
")",
":",
"content",
"end"
] | Subscribe the client to the given channel. This generates
some JavaScript calling Danthes.sign with the subscription
options. | [
"Subscribe",
"the",
"client",
"to",
"the",
"given",
"channel",
".",
"This",
"generates",
"some",
"JavaScript",
"calling",
"Danthes",
".",
"sign",
"with",
"the",
"subscription",
"options",
"."
] | bac689d465aaf22c09b6e51fbca8a735bd8fb468 | https://github.com/amoniacou/danthes/blob/bac689d465aaf22c09b6e51fbca8a735bd8fb468/lib/danthes/view_helpers.rb#L15-L20 | train |
russ/lacquer | lib/lacquer/cache_utils.rb | Lacquer.CacheUtils.clear_cache_for | def clear_cache_for(*paths)
return unless Lacquer.configuration.enable_cache
case Lacquer.configuration.job_backend
when :delayed_job
require 'lacquer/delayed_job_job'
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(paths))
when :resque
require 'lacquer/resque_job'
Resque.enqueue(Lacquer::ResqueJob, paths)
when :sidekiq
require 'lacquer/sidekiq_worker'
Lacquer::SidekiqWorker.perform_async(paths)
when :none
Varnish.new.purge(*paths)
end
end | ruby | def clear_cache_for(*paths)
return unless Lacquer.configuration.enable_cache
case Lacquer.configuration.job_backend
when :delayed_job
require 'lacquer/delayed_job_job'
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(paths))
when :resque
require 'lacquer/resque_job'
Resque.enqueue(Lacquer::ResqueJob, paths)
when :sidekiq
require 'lacquer/sidekiq_worker'
Lacquer::SidekiqWorker.perform_async(paths)
when :none
Varnish.new.purge(*paths)
end
end | [
"def",
"clear_cache_for",
"(",
"*",
"paths",
")",
"return",
"unless",
"Lacquer",
".",
"configuration",
".",
"enable_cache",
"case",
"Lacquer",
".",
"configuration",
".",
"job_backend",
"when",
":delayed_job",
"require",
"'lacquer/delayed_job_job'",
"Delayed",
"::",
"Job",
".",
"enqueue",
"(",
"Lacquer",
"::",
"DelayedJobJob",
".",
"new",
"(",
"paths",
")",
")",
"when",
":resque",
"require",
"'lacquer/resque_job'",
"Resque",
".",
"enqueue",
"(",
"Lacquer",
"::",
"ResqueJob",
",",
"paths",
")",
"when",
":sidekiq",
"require",
"'lacquer/sidekiq_worker'",
"Lacquer",
"::",
"SidekiqWorker",
".",
"perform_async",
"(",
"paths",
")",
"when",
":none",
"Varnish",
".",
"new",
".",
"purge",
"(",
"*",
"paths",
")",
"end",
"end"
] | Sends url.purge command to varnish to clear cache.
clear_cache_for(root_path, blog_posts_path, '/other/content/*') | [
"Sends",
"url",
".",
"purge",
"command",
"to",
"varnish",
"to",
"clear",
"cache",
"."
] | 690fef73ee6f9229f0191a7d75bf6172499ffaf4 | https://github.com/russ/lacquer/blob/690fef73ee6f9229f0191a7d75bf6172499ffaf4/lib/lacquer/cache_utils.rb#L28-L43 | train |
amoniacou/danthes | lib/danthes/faye_extension.rb | Danthes.FayeExtension.incoming | def incoming(message, callback)
if message['channel'] == '/meta/subscribe'
authenticate_subscribe(message)
elsif message['channel'] !~ %r{^/meta/}
authenticate_publish(message)
end
callback.call(message)
end | ruby | def incoming(message, callback)
if message['channel'] == '/meta/subscribe'
authenticate_subscribe(message)
elsif message['channel'] !~ %r{^/meta/}
authenticate_publish(message)
end
callback.call(message)
end | [
"def",
"incoming",
"(",
"message",
",",
"callback",
")",
"if",
"message",
"[",
"'channel'",
"]",
"==",
"'/meta/subscribe'",
"authenticate_subscribe",
"(",
"message",
")",
"elsif",
"message",
"[",
"'channel'",
"]",
"!~",
"%r{",
"}",
"authenticate_publish",
"(",
"message",
")",
"end",
"callback",
".",
"call",
"(",
"message",
")",
"end"
] | Callback to handle incoming Faye messages. This authenticates both
subscribe and publish calls. | [
"Callback",
"to",
"handle",
"incoming",
"Faye",
"messages",
".",
"This",
"authenticates",
"both",
"subscribe",
"and",
"publish",
"calls",
"."
] | bac689d465aaf22c09b6e51fbca8a735bd8fb468 | https://github.com/amoniacou/danthes/blob/bac689d465aaf22c09b6e51fbca8a735bd8fb468/lib/danthes/faye_extension.rb#L7-L14 | train |
russ/lacquer | lib/lacquer/varnish.rb | Lacquer.Varnish.send_command | def send_command(command)
Lacquer.configuration.varnish_servers.collect do |server|
retries = 0
response = nil
begin
retries += 1
connection = Net::Telnet.new(
'Host' => server[:host],
'Port' => server[:port],
'Timeout' => server[:timeout] || 5)
if(server[:secret])
connection.waitfor("Match" => /^107/) do |authentication_request|
matchdata = /^107 \d{2}\s*(.{32}).*$/m.match(authentication_request) # Might be a bit ugly regex, but it works great!
salt = matchdata[1]
if(salt.empty?)
raise VarnishError, "Bad authentication request"
end
digest = OpenSSL::Digest.new('sha256')
digest << salt
digest << "\n"
digest << server[:secret]
digest << salt
digest << "\n"
connection.cmd("String" => "auth #{digest.to_s}", "Match" => /\d{3}/) do |auth_response|
if(!(/^200/ =~ auth_response))
raise AuthenticationError, "Could not authenticate"
end
end
end
end
connection.cmd('String' => command, 'Match' => /\n\n/) {|r| response = r.split("\n").first.strip}
connection.close if connection.respond_to?(:close)
rescue Exception => e
if retries < Lacquer.configuration.retries
retry
else
if Lacquer.configuration.command_error_handler
Lacquer.configuration.command_error_handler.call({
:error_class => "Varnish Error, retried #{Lacquer.configuration.retries} times",
:error_message => "Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}",
:parameters => server,
:response => response })
elsif e.kind_of?(Lacquer::AuthenticationError)
raise e
else
raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
end
end
end
response
end
end | ruby | def send_command(command)
Lacquer.configuration.varnish_servers.collect do |server|
retries = 0
response = nil
begin
retries += 1
connection = Net::Telnet.new(
'Host' => server[:host],
'Port' => server[:port],
'Timeout' => server[:timeout] || 5)
if(server[:secret])
connection.waitfor("Match" => /^107/) do |authentication_request|
matchdata = /^107 \d{2}\s*(.{32}).*$/m.match(authentication_request) # Might be a bit ugly regex, but it works great!
salt = matchdata[1]
if(salt.empty?)
raise VarnishError, "Bad authentication request"
end
digest = OpenSSL::Digest.new('sha256')
digest << salt
digest << "\n"
digest << server[:secret]
digest << salt
digest << "\n"
connection.cmd("String" => "auth #{digest.to_s}", "Match" => /\d{3}/) do |auth_response|
if(!(/^200/ =~ auth_response))
raise AuthenticationError, "Could not authenticate"
end
end
end
end
connection.cmd('String' => command, 'Match' => /\n\n/) {|r| response = r.split("\n").first.strip}
connection.close if connection.respond_to?(:close)
rescue Exception => e
if retries < Lacquer.configuration.retries
retry
else
if Lacquer.configuration.command_error_handler
Lacquer.configuration.command_error_handler.call({
:error_class => "Varnish Error, retried #{Lacquer.configuration.retries} times",
:error_message => "Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}",
:parameters => server,
:response => response })
elsif e.kind_of?(Lacquer::AuthenticationError)
raise e
else
raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
end
end
end
response
end
end | [
"def",
"send_command",
"(",
"command",
")",
"Lacquer",
".",
"configuration",
".",
"varnish_servers",
".",
"collect",
"do",
"|",
"server",
"|",
"retries",
"=",
"0",
"response",
"=",
"nil",
"begin",
"retries",
"+=",
"1",
"connection",
"=",
"Net",
"::",
"Telnet",
".",
"new",
"(",
"'Host'",
"=>",
"server",
"[",
":host",
"]",
",",
"'Port'",
"=>",
"server",
"[",
":port",
"]",
",",
"'Timeout'",
"=>",
"server",
"[",
":timeout",
"]",
"||",
"5",
")",
"if",
"(",
"server",
"[",
":secret",
"]",
")",
"connection",
".",
"waitfor",
"(",
"\"Match\"",
"=>",
"/",
"/",
")",
"do",
"|",
"authentication_request",
"|",
"matchdata",
"=",
"/",
"\\d",
"\\s",
"/m",
".",
"match",
"(",
"authentication_request",
")",
"salt",
"=",
"matchdata",
"[",
"1",
"]",
"if",
"(",
"salt",
".",
"empty?",
")",
"raise",
"VarnishError",
",",
"\"Bad authentication request\"",
"end",
"digest",
"=",
"OpenSSL",
"::",
"Digest",
".",
"new",
"(",
"'sha256'",
")",
"digest",
"<<",
"salt",
"digest",
"<<",
"\"\\n\"",
"digest",
"<<",
"server",
"[",
":secret",
"]",
"digest",
"<<",
"salt",
"digest",
"<<",
"\"\\n\"",
"connection",
".",
"cmd",
"(",
"\"String\"",
"=>",
"\"auth #{digest.to_s}\"",
",",
"\"Match\"",
"=>",
"/",
"\\d",
"/",
")",
"do",
"|",
"auth_response",
"|",
"if",
"(",
"!",
"(",
"/",
"/",
"=~",
"auth_response",
")",
")",
"raise",
"AuthenticationError",
",",
"\"Could not authenticate\"",
"end",
"end",
"end",
"end",
"connection",
".",
"cmd",
"(",
"'String'",
"=>",
"command",
",",
"'Match'",
"=>",
"/",
"\\n",
"\\n",
"/",
")",
"{",
"|",
"r",
"|",
"response",
"=",
"r",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"first",
".",
"strip",
"}",
"connection",
".",
"close",
"if",
"connection",
".",
"respond_to?",
"(",
":close",
")",
"rescue",
"Exception",
"=>",
"e",
"if",
"retries",
"<",
"Lacquer",
".",
"configuration",
".",
"retries",
"retry",
"else",
"if",
"Lacquer",
".",
"configuration",
".",
"command_error_handler",
"Lacquer",
".",
"configuration",
".",
"command_error_handler",
".",
"call",
"(",
"{",
":error_class",
"=>",
"\"Varnish Error, retried #{Lacquer.configuration.retries} times\"",
",",
":error_message",
"=>",
"\"Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}\"",
",",
":parameters",
"=>",
"server",
",",
":response",
"=>",
"response",
"}",
")",
"elsif",
"e",
".",
"kind_of?",
"(",
"Lacquer",
"::",
"AuthenticationError",
")",
"raise",
"e",
"else",
"raise",
"VarnishError",
".",
"new",
"(",
"\"Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}\"",
")",
"end",
"end",
"end",
"response",
"end",
"end"
] | Sends commands over telnet to varnish servers listed in the config. | [
"Sends",
"commands",
"over",
"telnet",
"to",
"varnish",
"servers",
"listed",
"in",
"the",
"config",
"."
] | 690fef73ee6f9229f0191a7d75bf6172499ffaf4 | https://github.com/russ/lacquer/blob/690fef73ee6f9229f0191a7d75bf6172499ffaf4/lib/lacquer/varnish.rb#L27-L82 | train |
4commerce-technologies-AG/midi-smtp-server | lib/midi-smtp-server/tls-transport.rb | MidiSmtpServer.TlsTransport.start | def start(io)
# start SSL negotiation
ssl = OpenSSL::SSL::SSLSocket.new(io, @ctx)
# connect to server socket
ssl.accept
# make sure to close also the underlying io
ssl.sync_close = true
# return as new io socket
return ssl
end | ruby | def start(io)
# start SSL negotiation
ssl = OpenSSL::SSL::SSLSocket.new(io, @ctx)
# connect to server socket
ssl.accept
# make sure to close also the underlying io
ssl.sync_close = true
# return as new io socket
return ssl
end | [
"def",
"start",
"(",
"io",
")",
"ssl",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"SSLSocket",
".",
"new",
"(",
"io",
",",
"@ctx",
")",
"ssl",
".",
"accept",
"ssl",
".",
"sync_close",
"=",
"true",
"return",
"ssl",
"end"
] | start ssl connection over existing tcpserver socket | [
"start",
"ssl",
"connection",
"over",
"existing",
"tcpserver",
"socket"
] | b86a3268ebd32b46854659a2edc1eddaf86adb7b | https://github.com/4commerce-technologies-AG/midi-smtp-server/blob/b86a3268ebd32b46854659a2edc1eddaf86adb7b/lib/midi-smtp-server/tls-transport.rb#L54-L63 | train |
johnkoht/responsive-images | lib/responsive_images/view_helpers.rb | ResponsiveImages.ViewHelpers.responsive_image_tag | def responsive_image_tag image, options={}
# Merge any options passed with the configured options
sizes = ResponsiveImages.options.deep_merge(options)
# Let's create a hash of the alternative options for our data attributes
data_sizes = alternative_sizes(image, sizes)
# Get the image source
image_src = src_path(image, sizes)
# Return the image tag with our responsive data attributes
return image_tag image_src, data_sizes.merge(options)
end | ruby | def responsive_image_tag image, options={}
# Merge any options passed with the configured options
sizes = ResponsiveImages.options.deep_merge(options)
# Let's create a hash of the alternative options for our data attributes
data_sizes = alternative_sizes(image, sizes)
# Get the image source
image_src = src_path(image, sizes)
# Return the image tag with our responsive data attributes
return image_tag image_src, data_sizes.merge(options)
end | [
"def",
"responsive_image_tag",
"image",
",",
"options",
"=",
"{",
"}",
"sizes",
"=",
"ResponsiveImages",
".",
"options",
".",
"deep_merge",
"(",
"options",
")",
"data_sizes",
"=",
"alternative_sizes",
"(",
"image",
",",
"sizes",
")",
"image_src",
"=",
"src_path",
"(",
"image",
",",
"sizes",
")",
"return",
"image_tag",
"image_src",
",",
"data_sizes",
".",
"merge",
"(",
"options",
")",
"end"
] | Create a image tag with our responsive image data attributes | [
"Create",
"a",
"image",
"tag",
"with",
"our",
"responsive",
"image",
"data",
"attributes"
] | b5449b2dcb6f96cc8d5a335e9b032858285b156a | https://github.com/johnkoht/responsive-images/blob/b5449b2dcb6f96cc8d5a335e9b032858285b156a/lib/responsive_images/view_helpers.rb#L12-L21 | train |
johnkoht/responsive-images | lib/responsive_images/view_helpers.rb | ResponsiveImages.ViewHelpers.alternative_sizes | def alternative_sizes image, sizes
data_sizes = {}
sizes[:sizes].each do |size, value|
if value.present?
data_sizes["data-#{size}-src"] = (value == :default ? image.url : image.send(value))
else
false
end
end
data_sizes
end | ruby | def alternative_sizes image, sizes
data_sizes = {}
sizes[:sizes].each do |size, value|
if value.present?
data_sizes["data-#{size}-src"] = (value == :default ? image.url : image.send(value))
else
false
end
end
data_sizes
end | [
"def",
"alternative_sizes",
"image",
",",
"sizes",
"data_sizes",
"=",
"{",
"}",
"sizes",
"[",
":sizes",
"]",
".",
"each",
"do",
"|",
"size",
",",
"value",
"|",
"if",
"value",
".",
"present?",
"data_sizes",
"[",
"\"data-#{size}-src\"",
"]",
"=",
"(",
"value",
"==",
":default",
"?",
"image",
".",
"url",
":",
"image",
".",
"send",
"(",
"value",
")",
")",
"else",
"false",
"end",
"end",
"data_sizes",
"end"
] | Loop over the images sizes and create our data attributes hash | [
"Loop",
"over",
"the",
"images",
"sizes",
"and",
"create",
"our",
"data",
"attributes",
"hash"
] | b5449b2dcb6f96cc8d5a335e9b032858285b156a | https://github.com/johnkoht/responsive-images/blob/b5449b2dcb6f96cc8d5a335e9b032858285b156a/lib/responsive_images/view_helpers.rb#L47-L57 | train |
worlddb/world.db | worlddb-models/lib/worlddb/reader.rb | WorldDb.ReaderBase.load_continent_defs | def load_continent_defs( name, more_attribs={} )
reader = create_values_reader( name, more_attribs )
reader.each_line do |attribs, values|
## check optional values
values.each_with_index do |value, index|
logger.warn "unknown type for value >#{value}<"
end
rec = Continent.find_by_key( attribs[ :key ] )
if rec.present?
logger.debug "update Continent #{rec.id}-#{rec.key}:"
else
logger.debug "create Continent:"
rec = Continent.new
end
logger.debug attribs.to_json
rec.update_attributes!( attribs )
end # each lines
end | ruby | def load_continent_defs( name, more_attribs={} )
reader = create_values_reader( name, more_attribs )
reader.each_line do |attribs, values|
## check optional values
values.each_with_index do |value, index|
logger.warn "unknown type for value >#{value}<"
end
rec = Continent.find_by_key( attribs[ :key ] )
if rec.present?
logger.debug "update Continent #{rec.id}-#{rec.key}:"
else
logger.debug "create Continent:"
rec = Continent.new
end
logger.debug attribs.to_json
rec.update_attributes!( attribs )
end # each lines
end | [
"def",
"load_continent_defs",
"(",
"name",
",",
"more_attribs",
"=",
"{",
"}",
")",
"reader",
"=",
"create_values_reader",
"(",
"name",
",",
"more_attribs",
")",
"reader",
".",
"each_line",
"do",
"|",
"attribs",
",",
"values",
"|",
"values",
".",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"logger",
".",
"warn",
"\"unknown type for value >#{value}<\"",
"end",
"rec",
"=",
"Continent",
".",
"find_by_key",
"(",
"attribs",
"[",
":key",
"]",
")",
"if",
"rec",
".",
"present?",
"logger",
".",
"debug",
"\"update Continent #{rec.id}-#{rec.key}:\"",
"else",
"logger",
".",
"debug",
"\"create Continent:\"",
"rec",
"=",
"Continent",
".",
"new",
"end",
"logger",
".",
"debug",
"attribs",
".",
"to_json",
"rec",
".",
"update_attributes!",
"(",
"attribs",
")",
"end",
"end"
] | use ContinentDef Reader | [
"use",
"ContinentDef",
"Reader"
] | 8fd44fa8d8dc47290c63b881c713634494aae291 | https://github.com/worlddb/world.db/blob/8fd44fa8d8dc47290c63b881c713634494aae291/worlddb-models/lib/worlddb/reader.rb#L198-L221 | train |
agoragames/bracket_tree | lib/bracket_tree/positional_relation.rb | BracketTree.PositionalRelation.all | def all
if @side
if @round
seats = by_round @round, @side
else
side_root = @bracket.root.send(@side)
seats = []
@bracket.top_down(side_root) do |node|
seats << node
end
end
else
if @round
seats = by_round(@round, :left) + by_round(@round, :right)
else
seats = []
@bracket.top_down(@bracket.root) do |node|
seats << node
end
end
end
seats
end | ruby | def all
if @side
if @round
seats = by_round @round, @side
else
side_root = @bracket.root.send(@side)
seats = []
@bracket.top_down(side_root) do |node|
seats << node
end
end
else
if @round
seats = by_round(@round, :left) + by_round(@round, :right)
else
seats = []
@bracket.top_down(@bracket.root) do |node|
seats << node
end
end
end
seats
end | [
"def",
"all",
"if",
"@side",
"if",
"@round",
"seats",
"=",
"by_round",
"@round",
",",
"@side",
"else",
"side_root",
"=",
"@bracket",
".",
"root",
".",
"send",
"(",
"@side",
")",
"seats",
"=",
"[",
"]",
"@bracket",
".",
"top_down",
"(",
"side_root",
")",
"do",
"|",
"node",
"|",
"seats",
"<<",
"node",
"end",
"end",
"else",
"if",
"@round",
"seats",
"=",
"by_round",
"(",
"@round",
",",
":left",
")",
"+",
"by_round",
"(",
"@round",
",",
":right",
")",
"else",
"seats",
"=",
"[",
"]",
"@bracket",
".",
"top_down",
"(",
"@bracket",
".",
"root",
")",
"do",
"|",
"node",
"|",
"seats",
"<<",
"node",
"end",
"end",
"end",
"seats",
"end"
] | Retrieves all seats based on the stored relation conditions
@return [Array<BracketTree::Node>] | [
"Retrieves",
"all",
"seats",
"based",
"on",
"the",
"stored",
"relation",
"conditions"
] | 68d90aa5c605ef2996fc7a360d4f90dcfde755ca | https://github.com/agoragames/bracket_tree/blob/68d90aa5c605ef2996fc7a360d4f90dcfde755ca/lib/bracket_tree/positional_relation.rb#L67-L91 | train |
agoragames/bracket_tree | lib/bracket_tree/positional_relation.rb | BracketTree.PositionalRelation.by_round | def by_round round, side
depth = @bracket.depth[side] - (round - 1)
seats = []
side_root = @bracket.root.send(side)
@bracket.top_down(side_root) do |node|
if node.depth == depth
seats << node
end
end
seats
end | ruby | def by_round round, side
depth = @bracket.depth[side] - (round - 1)
seats = []
side_root = @bracket.root.send(side)
@bracket.top_down(side_root) do |node|
if node.depth == depth
seats << node
end
end
seats
end | [
"def",
"by_round",
"round",
",",
"side",
"depth",
"=",
"@bracket",
".",
"depth",
"[",
"side",
"]",
"-",
"(",
"round",
"-",
"1",
")",
"seats",
"=",
"[",
"]",
"side_root",
"=",
"@bracket",
".",
"root",
".",
"send",
"(",
"side",
")",
"@bracket",
".",
"top_down",
"(",
"side_root",
")",
"do",
"|",
"node",
"|",
"if",
"node",
".",
"depth",
"==",
"depth",
"seats",
"<<",
"node",
"end",
"end",
"seats",
"end"
] | Retrieves an Array of Nodes for a given round on a given side
@param [Fixnum] round to pull
@param [Fixnum] side of the tree to pull from
@return [Array] array of Nodes from the round | [
"Retrieves",
"an",
"Array",
"of",
"Nodes",
"for",
"a",
"given",
"round",
"on",
"a",
"given",
"side"
] | 68d90aa5c605ef2996fc7a360d4f90dcfde755ca | https://github.com/agoragames/bracket_tree/blob/68d90aa5c605ef2996fc7a360d4f90dcfde755ca/lib/bracket_tree/positional_relation.rb#L108-L120 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.configure | def configure(xcodeproj_path, scheme, options: {})
require 'slather'
@project = Slather::Project.open(xcodeproj_path)
@project.scheme = scheme
@project.workspace = options[:workspace]
@project.build_directory = options[:build_directory]
@project.ignore_list = options[:ignore_list]
@project.ci_service = options[:ci_service]
@project.coverage_access_token = options[:coverage_access_token]
@project.coverage_service = options[:coverage_service] || :terminal
@project.source_directory = options[:source_directory]
@project.output_directory = options[:output_directory]
@project.input_format = options[:input_format]
@project.binary_file = options[:binary_file]
@project.decimals = options[:decimals]
@project.configure
@project.post if options[:post]
end | ruby | def configure(xcodeproj_path, scheme, options: {})
require 'slather'
@project = Slather::Project.open(xcodeproj_path)
@project.scheme = scheme
@project.workspace = options[:workspace]
@project.build_directory = options[:build_directory]
@project.ignore_list = options[:ignore_list]
@project.ci_service = options[:ci_service]
@project.coverage_access_token = options[:coverage_access_token]
@project.coverage_service = options[:coverage_service] || :terminal
@project.source_directory = options[:source_directory]
@project.output_directory = options[:output_directory]
@project.input_format = options[:input_format]
@project.binary_file = options[:binary_file]
@project.decimals = options[:decimals]
@project.configure
@project.post if options[:post]
end | [
"def",
"configure",
"(",
"xcodeproj_path",
",",
"scheme",
",",
"options",
":",
"{",
"}",
")",
"require",
"'slather'",
"@project",
"=",
"Slather",
"::",
"Project",
".",
"open",
"(",
"xcodeproj_path",
")",
"@project",
".",
"scheme",
"=",
"scheme",
"@project",
".",
"workspace",
"=",
"options",
"[",
":workspace",
"]",
"@project",
".",
"build_directory",
"=",
"options",
"[",
":build_directory",
"]",
"@project",
".",
"ignore_list",
"=",
"options",
"[",
":ignore_list",
"]",
"@project",
".",
"ci_service",
"=",
"options",
"[",
":ci_service",
"]",
"@project",
".",
"coverage_access_token",
"=",
"options",
"[",
":coverage_access_token",
"]",
"@project",
".",
"coverage_service",
"=",
"options",
"[",
":coverage_service",
"]",
"||",
":terminal",
"@project",
".",
"source_directory",
"=",
"options",
"[",
":source_directory",
"]",
"@project",
".",
"output_directory",
"=",
"options",
"[",
":output_directory",
"]",
"@project",
".",
"input_format",
"=",
"options",
"[",
":input_format",
"]",
"@project",
".",
"binary_file",
"=",
"options",
"[",
":binary_file",
"]",
"@project",
".",
"decimals",
"=",
"options",
"[",
":decimals",
"]",
"@project",
".",
"configure",
"@project",
".",
"post",
"if",
"options",
"[",
":post",
"]",
"end"
] | Required method to configure slather. It's required at least the path
to the project and the scheme used with code coverage enabled
@return [void] | [
"Required",
"method",
"to",
"configure",
"slather",
".",
"It",
"s",
"required",
"at",
"least",
"the",
"path",
"to",
"the",
"project",
"and",
"the",
"scheme",
"used",
"with",
"code",
"coverage",
"enabled"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L19-L36 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.total_coverage | def total_coverage
unless @project.nil?
@total_coverage ||= begin
total_project_lines = 0
total_project_lines_tested = 0
@project.coverage_files.each do |coverage_file|
total_project_lines_tested += coverage_file.num_lines_tested
total_project_lines += coverage_file.num_lines_testable
end
@total_coverage = (total_project_lines_tested / total_project_lines.to_f) * 100.0
end
end
end | ruby | def total_coverage
unless @project.nil?
@total_coverage ||= begin
total_project_lines = 0
total_project_lines_tested = 0
@project.coverage_files.each do |coverage_file|
total_project_lines_tested += coverage_file.num_lines_tested
total_project_lines += coverage_file.num_lines_testable
end
@total_coverage = (total_project_lines_tested / total_project_lines.to_f) * 100.0
end
end
end | [
"def",
"total_coverage",
"unless",
"@project",
".",
"nil?",
"@total_coverage",
"||=",
"begin",
"total_project_lines",
"=",
"0",
"total_project_lines_tested",
"=",
"0",
"@project",
".",
"coverage_files",
".",
"each",
"do",
"|",
"coverage_file",
"|",
"total_project_lines_tested",
"+=",
"coverage_file",
".",
"num_lines_tested",
"total_project_lines",
"+=",
"coverage_file",
".",
"num_lines_testable",
"end",
"@total_coverage",
"=",
"(",
"total_project_lines_tested",
"/",
"total_project_lines",
".",
"to_f",
")",
"*",
"100.0",
"end",
"end",
"end"
] | Total coverage of the project
@return [Float] | [
"Total",
"coverage",
"of",
"the",
"project"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L40-L52 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.notify_if_coverage_is_less_than | def notify_if_coverage_is_less_than(options)
minimum_coverage = options[:minimum_coverage]
notify_level = options[:notify_level] || :fail
if total_coverage < minimum_coverage
notify_message = "Total coverage less than #{minimum_coverage}%"
if notify_level == :fail
fail notify_message
else
warn notify_message
end
end
end | ruby | def notify_if_coverage_is_less_than(options)
minimum_coverage = options[:minimum_coverage]
notify_level = options[:notify_level] || :fail
if total_coverage < minimum_coverage
notify_message = "Total coverage less than #{minimum_coverage}%"
if notify_level == :fail
fail notify_message
else
warn notify_message
end
end
end | [
"def",
"notify_if_coverage_is_less_than",
"(",
"options",
")",
"minimum_coverage",
"=",
"options",
"[",
":minimum_coverage",
"]",
"notify_level",
"=",
"options",
"[",
":notify_level",
"]",
"||",
":fail",
"if",
"total_coverage",
"<",
"minimum_coverage",
"notify_message",
"=",
"\"Total coverage less than #{minimum_coverage}%\"",
"if",
"notify_level",
"==",
":fail",
"fail",
"notify_message",
"else",
"warn",
"notify_message",
"end",
"end",
"end"
] | Method to check if the coverage of the project is at least a minumum
@param options [Hash] a hash with the options
@option options [Float] :minimum_coverage the minimum code coverage required
@option options [Symbol] :notify_level the level of notification
@return [Array<String>] | [
"Method",
"to",
"check",
"if",
"the",
"coverage",
"of",
"the",
"project",
"is",
"at",
"least",
"a",
"minumum"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L59-L70 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.notify_if_modified_file_is_less_than | def notify_if_modified_file_is_less_than(options)
minimum_coverage = options[:minimum_coverage]
notify_level = options[:notify_level] || :fail
if all_modified_files_coverage.count > 0
files_to_notify = all_modified_files_coverage.select do |file|
file.percentage_lines_tested < minimum_coverage
end
notify_messages = files_to_notify.map do |file|
"#{file.source_file_pathname_relative_to_repo_root} has less than #{minimum_coverage}% code coverage"
end
notify_messages.each do |message|
if notify_level == :fail
fail message
else
warn message
end
end
end
end | ruby | def notify_if_modified_file_is_less_than(options)
minimum_coverage = options[:minimum_coverage]
notify_level = options[:notify_level] || :fail
if all_modified_files_coverage.count > 0
files_to_notify = all_modified_files_coverage.select do |file|
file.percentage_lines_tested < minimum_coverage
end
notify_messages = files_to_notify.map do |file|
"#{file.source_file_pathname_relative_to_repo_root} has less than #{minimum_coverage}% code coverage"
end
notify_messages.each do |message|
if notify_level == :fail
fail message
else
warn message
end
end
end
end | [
"def",
"notify_if_modified_file_is_less_than",
"(",
"options",
")",
"minimum_coverage",
"=",
"options",
"[",
":minimum_coverage",
"]",
"notify_level",
"=",
"options",
"[",
":notify_level",
"]",
"||",
":fail",
"if",
"all_modified_files_coverage",
".",
"count",
">",
"0",
"files_to_notify",
"=",
"all_modified_files_coverage",
".",
"select",
"do",
"|",
"file",
"|",
"file",
".",
"percentage_lines_tested",
"<",
"minimum_coverage",
"end",
"notify_messages",
"=",
"files_to_notify",
".",
"map",
"do",
"|",
"file",
"|",
"\"#{file.source_file_pathname_relative_to_repo_root} has less than #{minimum_coverage}% code coverage\"",
"end",
"notify_messages",
".",
"each",
"do",
"|",
"message",
"|",
"if",
"notify_level",
"==",
":fail",
"fail",
"message",
"else",
"warn",
"message",
"end",
"end",
"end",
"end"
] | Method to check if the coverage of modified files is at least a minumum
@param options [Hash] a hash with the options
@option options [Float] :minimum_coverage the minimum code coverage required for a file
@option options [Symbol] :notify_level the level of notification
@return [Array<String>] | [
"Method",
"to",
"check",
"if",
"the",
"coverage",
"of",
"modified",
"files",
"is",
"at",
"least",
"a",
"minumum"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L77-L97 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.modified_files_coverage_table | def modified_files_coverage_table
unless @project.nil?
line = ''
if all_modified_files_coverage.count > 0
line << "File | Coverage\n"
line << "-----|-----\n"
all_modified_files_coverage.each do |coverage_file|
file_name = coverage_file.source_file_pathname_relative_to_repo_root.to_s
percentage = @project.decimal_f([coverage_file.percentage_lines_tested])
line << "#{file_name} | **`#{percentage}%`**\n"
end
end
return line
end
end | ruby | def modified_files_coverage_table
unless @project.nil?
line = ''
if all_modified_files_coverage.count > 0
line << "File | Coverage\n"
line << "-----|-----\n"
all_modified_files_coverage.each do |coverage_file|
file_name = coverage_file.source_file_pathname_relative_to_repo_root.to_s
percentage = @project.decimal_f([coverage_file.percentage_lines_tested])
line << "#{file_name} | **`#{percentage}%`**\n"
end
end
return line
end
end | [
"def",
"modified_files_coverage_table",
"unless",
"@project",
".",
"nil?",
"line",
"=",
"''",
"if",
"all_modified_files_coverage",
".",
"count",
">",
"0",
"line",
"<<",
"\"File | Coverage\\n\"",
"line",
"<<",
"\"-----|-----\\n\"",
"all_modified_files_coverage",
".",
"each",
"do",
"|",
"coverage_file",
"|",
"file_name",
"=",
"coverage_file",
".",
"source_file_pathname_relative_to_repo_root",
".",
"to_s",
"percentage",
"=",
"@project",
".",
"decimal_f",
"(",
"[",
"coverage_file",
".",
"percentage_lines_tested",
"]",
")",
"line",
"<<",
"\"#{file_name} | **`#{percentage}%`**\\n\"",
"end",
"end",
"return",
"line",
"end",
"end"
] | Build a coverage markdown table of the modified files coverage
@return [String] | [
"Build",
"a",
"coverage",
"markdown",
"table",
"of",
"the",
"modified",
"files",
"coverage"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L117-L131 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.show_coverage | def show_coverage
unless @project.nil?
line = "## Code coverage\n"
line << total_coverage_markdown
line << modified_files_coverage_table
line << '> Powered by [Slather](https://github.com/SlatherOrg/slather)'
markdown line
end
end | ruby | def show_coverage
unless @project.nil?
line = "## Code coverage\n"
line << total_coverage_markdown
line << modified_files_coverage_table
line << '> Powered by [Slather](https://github.com/SlatherOrg/slather)'
markdown line
end
end | [
"def",
"show_coverage",
"unless",
"@project",
".",
"nil?",
"line",
"=",
"\"## Code coverage\\n\"",
"line",
"<<",
"total_coverage_markdown",
"line",
"<<",
"modified_files_coverage_table",
"line",
"<<",
"'> Powered by [Slather](https://github.com/SlatherOrg/slather)'",
"markdown",
"line",
"end",
"end"
] | Show a header with the total coverage and coverage table
@return [Array<String>] | [
"Show",
"a",
"header",
"with",
"the",
"total",
"coverage",
"and",
"coverage",
"table"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L143-L151 | train |
BrunoMazzo/Danger-Slather | lib/slather/plugin.rb | Danger.DangerSlather.all_modified_files_coverage | def all_modified_files_coverage
unless @project.nil?
all_modified_files_coverage ||= begin
modified_files = git.modified_files.nil? ? [] : git.modified_files
added_files = git.added_files.nil? ? [] : git.added_files
all_changed_files = modified_files | added_files
@project.coverage_files.select do |file|
all_changed_files.include? file.source_file_pathname_relative_to_repo_root.to_s
end
end
all_modified_files_coverage
end
end | ruby | def all_modified_files_coverage
unless @project.nil?
all_modified_files_coverage ||= begin
modified_files = git.modified_files.nil? ? [] : git.modified_files
added_files = git.added_files.nil? ? [] : git.added_files
all_changed_files = modified_files | added_files
@project.coverage_files.select do |file|
all_changed_files.include? file.source_file_pathname_relative_to_repo_root.to_s
end
end
all_modified_files_coverage
end
end | [
"def",
"all_modified_files_coverage",
"unless",
"@project",
".",
"nil?",
"all_modified_files_coverage",
"||=",
"begin",
"modified_files",
"=",
"git",
".",
"modified_files",
".",
"nil?",
"?",
"[",
"]",
":",
"git",
".",
"modified_files",
"added_files",
"=",
"git",
".",
"added_files",
".",
"nil?",
"?",
"[",
"]",
":",
"git",
".",
"added_files",
"all_changed_files",
"=",
"modified_files",
"|",
"added_files",
"@project",
".",
"coverage_files",
".",
"select",
"do",
"|",
"file",
"|",
"all_changed_files",
".",
"include?",
"file",
".",
"source_file_pathname_relative_to_repo_root",
".",
"to_s",
"end",
"end",
"all_modified_files_coverage",
"end",
"end"
] | Array of files that we have coverage information and was modified
@return [Array<File>] | [
"Array",
"of",
"files",
"that",
"we",
"have",
"coverage",
"information",
"and",
"was",
"modified"
] | 98be417dd89b922a20404810550a5d280d349b0e | https://github.com/BrunoMazzo/Danger-Slather/blob/98be417dd89b922a20404810550a5d280d349b0e/lib/slather/plugin.rb#L155-L168 | train |
mobomo/green_onion | lib/green_onion/compare.rb | GreenOnion.Compare.diff_iterator | def diff_iterator
@images.first.height.times do |y|
@images.first.row(y).each_with_index do |pixel, x|
unless pixel == @images.last[x,y]
@diff_index << [x,y]
pixel_difference_filter(pixel, x, y)
end
end
end
end | ruby | def diff_iterator
@images.first.height.times do |y|
@images.first.row(y).each_with_index do |pixel, x|
unless pixel == @images.last[x,y]
@diff_index << [x,y]
pixel_difference_filter(pixel, x, y)
end
end
end
end | [
"def",
"diff_iterator",
"@images",
".",
"first",
".",
"height",
".",
"times",
"do",
"|",
"y",
"|",
"@images",
".",
"first",
".",
"row",
"(",
"y",
")",
".",
"each_with_index",
"do",
"|",
"pixel",
",",
"x",
"|",
"unless",
"pixel",
"==",
"@images",
".",
"last",
"[",
"x",
",",
"y",
"]",
"@diff_index",
"<<",
"[",
"x",
",",
"y",
"]",
"pixel_difference_filter",
"(",
"pixel",
",",
"x",
",",
"y",
")",
"end",
"end",
"end",
"end"
] | Run through all of the pixels on both org image, and fresh image. Change the pixel color accordingly. | [
"Run",
"through",
"all",
"of",
"the",
"pixels",
"on",
"both",
"org",
"image",
"and",
"fresh",
"image",
".",
"Change",
"the",
"pixel",
"color",
"accordingly",
"."
] | 6e4bab440e22dab00fa3e543888c6d924e97777b | https://github.com/mobomo/green_onion/blob/6e4bab440e22dab00fa3e543888c6d924e97777b/lib/green_onion/compare.rb#L27-L36 | train |
mobomo/green_onion | lib/green_onion/compare.rb | GreenOnion.Compare.pixel_difference_filter | def pixel_difference_filter(pixel, x, y)
chans = []
[:r, :b, :g].each do |chan|
chans << channel_difference(chan, pixel, x, y)
end
@images.last[x,y] = ChunkyPNG::Color.rgb(chans[0], chans[1], chans[2])
end | ruby | def pixel_difference_filter(pixel, x, y)
chans = []
[:r, :b, :g].each do |chan|
chans << channel_difference(chan, pixel, x, y)
end
@images.last[x,y] = ChunkyPNG::Color.rgb(chans[0], chans[1], chans[2])
end | [
"def",
"pixel_difference_filter",
"(",
"pixel",
",",
"x",
",",
"y",
")",
"chans",
"=",
"[",
"]",
"[",
":r",
",",
":b",
",",
":g",
"]",
".",
"each",
"do",
"|",
"chan",
"|",
"chans",
"<<",
"channel_difference",
"(",
"chan",
",",
"pixel",
",",
"x",
",",
"y",
")",
"end",
"@images",
".",
"last",
"[",
"x",
",",
"y",
"]",
"=",
"ChunkyPNG",
"::",
"Color",
".",
"rgb",
"(",
"chans",
"[",
"0",
"]",
",",
"chans",
"[",
"1",
"]",
",",
"chans",
"[",
"2",
"]",
")",
"end"
] | Changes the pixel color to be the opposite RGB value | [
"Changes",
"the",
"pixel",
"color",
"to",
"be",
"the",
"opposite",
"RGB",
"value"
] | 6e4bab440e22dab00fa3e543888c6d924e97777b | https://github.com/mobomo/green_onion/blob/6e4bab440e22dab00fa3e543888c6d924e97777b/lib/green_onion/compare.rb#L39-L45 | train |
mobomo/green_onion | lib/green_onion/compare.rb | GreenOnion.Compare.channel_difference | def channel_difference(chan, pixel, x, y)
ChunkyPNG::Color.send(chan, pixel) + ChunkyPNG::Color.send(chan, @images.last[x,y]) - 2 * [ChunkyPNG::Color.send(chan, pixel), ChunkyPNG::Color.send(chan, @images.last[x,y])].min
end | ruby | def channel_difference(chan, pixel, x, y)
ChunkyPNG::Color.send(chan, pixel) + ChunkyPNG::Color.send(chan, @images.last[x,y]) - 2 * [ChunkyPNG::Color.send(chan, pixel), ChunkyPNG::Color.send(chan, @images.last[x,y])].min
end | [
"def",
"channel_difference",
"(",
"chan",
",",
"pixel",
",",
"x",
",",
"y",
")",
"ChunkyPNG",
"::",
"Color",
".",
"send",
"(",
"chan",
",",
"pixel",
")",
"+",
"ChunkyPNG",
"::",
"Color",
".",
"send",
"(",
"chan",
",",
"@images",
".",
"last",
"[",
"x",
",",
"y",
"]",
")",
"-",
"2",
"*",
"[",
"ChunkyPNG",
"::",
"Color",
".",
"send",
"(",
"chan",
",",
"pixel",
")",
",",
"ChunkyPNG",
"::",
"Color",
".",
"send",
"(",
"chan",
",",
"@images",
".",
"last",
"[",
"x",
",",
"y",
"]",
")",
"]",
".",
"min",
"end"
] | Interface to run the R, G, B methods on ChunkyPNG | [
"Interface",
"to",
"run",
"the",
"R",
"G",
"B",
"methods",
"on",
"ChunkyPNG"
] | 6e4bab440e22dab00fa3e543888c6d924e97777b | https://github.com/mobomo/green_onion/blob/6e4bab440e22dab00fa3e543888c6d924e97777b/lib/green_onion/compare.rb#L48-L50 | train |
mobomo/green_onion | lib/green_onion/compare.rb | GreenOnion.Compare.percentage_diff | def percentage_diff(org, fresh)
diff_images(org, fresh)
@total_px = @images.first.pixels.length
@changed_px = @diff_index.length
@percentage_changed = ( (@diff_index.length.to_f / @images.first.pixels.length) * 100 ).round(2)
end | ruby | def percentage_diff(org, fresh)
diff_images(org, fresh)
@total_px = @images.first.pixels.length
@changed_px = @diff_index.length
@percentage_changed = ( (@diff_index.length.to_f / @images.first.pixels.length) * 100 ).round(2)
end | [
"def",
"percentage_diff",
"(",
"org",
",",
"fresh",
")",
"diff_images",
"(",
"org",
",",
"fresh",
")",
"@total_px",
"=",
"@images",
".",
"first",
".",
"pixels",
".",
"length",
"@changed_px",
"=",
"@diff_index",
".",
"length",
"@percentage_changed",
"=",
"(",
"(",
"@diff_index",
".",
"length",
".",
"to_f",
"/",
"@images",
".",
"first",
".",
"pixels",
".",
"length",
")",
"*",
"100",
")",
".",
"round",
"(",
"2",
")",
"end"
] | Returns the numeric results of the diff of 2 images | [
"Returns",
"the",
"numeric",
"results",
"of",
"the",
"diff",
"of",
"2",
"images"
] | 6e4bab440e22dab00fa3e543888c6d924e97777b | https://github.com/mobomo/green_onion/blob/6e4bab440e22dab00fa3e543888c6d924e97777b/lib/green_onion/compare.rb#L53-L58 | train |
mobomo/green_onion | lib/green_onion/compare.rb | GreenOnion.Compare.save_visual_diff | def save_visual_diff(org, fresh)
x, y = @diff_index.map{ |xy| xy[0] }, @diff_index.map{ |xy| xy[1] }
@diffed_image = org.insert(-5, '_diff')
begin
@images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
rescue NoMethodError
puts "Both skins are the same.".color(:yellow)
end
@images.last.save(@diffed_image)
end | ruby | def save_visual_diff(org, fresh)
x, y = @diff_index.map{ |xy| xy[0] }, @diff_index.map{ |xy| xy[1] }
@diffed_image = org.insert(-5, '_diff')
begin
@images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
rescue NoMethodError
puts "Both skins are the same.".color(:yellow)
end
@images.last.save(@diffed_image)
end | [
"def",
"save_visual_diff",
"(",
"org",
",",
"fresh",
")",
"x",
",",
"y",
"=",
"@diff_index",
".",
"map",
"{",
"|",
"xy",
"|",
"xy",
"[",
"0",
"]",
"}",
",",
"@diff_index",
".",
"map",
"{",
"|",
"xy",
"|",
"xy",
"[",
"1",
"]",
"}",
"@diffed_image",
"=",
"org",
".",
"insert",
"(",
"-",
"5",
",",
"'_diff'",
")",
"begin",
"@images",
".",
"last",
".",
"rect",
"(",
"x",
".",
"min",
",",
"y",
".",
"min",
",",
"x",
".",
"max",
",",
"y",
".",
"max",
",",
"ChunkyPNG",
"::",
"Color",
".",
"rgb",
"(",
"0",
",",
"255",
",",
"0",
")",
")",
"rescue",
"NoMethodError",
"puts",
"\"Both skins are the same.\"",
".",
"color",
"(",
":yellow",
")",
"end",
"@images",
".",
"last",
".",
"save",
"(",
"@diffed_image",
")",
"end"
] | Saves the visual diff as a separate file | [
"Saves",
"the",
"visual",
"diff",
"as",
"a",
"separate",
"file"
] | 6e4bab440e22dab00fa3e543888c6d924e97777b | https://github.com/mobomo/green_onion/blob/6e4bab440e22dab00fa3e543888c6d924e97777b/lib/green_onion/compare.rb#L67-L78 | train |
ranjib/etcd-ruby | lib/etcd/keys.rb | Etcd.Keys.get | def get(key, opts = {})
response = api_execute(key_endpoint + key, :get, params: opts)
Response.from_http_response(response)
end | ruby | def get(key, opts = {})
response = api_execute(key_endpoint + key, :get, params: opts)
Response.from_http_response(response)
end | [
"def",
"get",
"(",
"key",
",",
"opts",
"=",
"{",
"}",
")",
"response",
"=",
"api_execute",
"(",
"key_endpoint",
"+",
"key",
",",
":get",
",",
"params",
":",
"opts",
")",
"Response",
".",
"from_http_response",
"(",
"response",
")",
"end"
] | Retrives a key with its associated data, if key is not present it will
return with message "Key Not Found"
This method takes the following parameters as arguments
* key - whose data is to be retrieved | [
"Retrives",
"a",
"key",
"with",
"its",
"associated",
"data",
"if",
"key",
"is",
"not",
"present",
"it",
"will",
"return",
"with",
"message",
"Key",
"Not",
"Found"
] | f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917 | https://github.com/ranjib/etcd-ruby/blob/f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917/lib/etcd/keys.rb#L21-L24 | train |
ranjib/etcd-ruby | lib/etcd/keys.rb | Etcd.Keys.set | def set(key, opts = nil)
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
path = key_endpoint + key
payload = {}
[:ttl, :value, :dir, :prevExist, :prevValue, :prevIndex].each do |k|
payload[k] = opts[k] if opts.key?(k)
end
response = api_execute(path, :put, params: payload)
Response.from_http_response(response)
end | ruby | def set(key, opts = nil)
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
path = key_endpoint + key
payload = {}
[:ttl, :value, :dir, :prevExist, :prevValue, :prevIndex].each do |k|
payload[k] = opts[k] if opts.key?(k)
end
response = api_execute(path, :put, params: payload)
Response.from_http_response(response)
end | [
"def",
"set",
"(",
"key",
",",
"opts",
"=",
"nil",
")",
"fail",
"ArgumentError",
",",
"'Second argument must be a hash'",
"unless",
"opts",
".",
"is_a?",
"(",
"Hash",
")",
"path",
"=",
"key_endpoint",
"+",
"key",
"payload",
"=",
"{",
"}",
"[",
":ttl",
",",
":value",
",",
":dir",
",",
":prevExist",
",",
":prevValue",
",",
":prevIndex",
"]",
".",
"each",
"do",
"|",
"k",
"|",
"payload",
"[",
"k",
"]",
"=",
"opts",
"[",
"k",
"]",
"if",
"opts",
".",
"key?",
"(",
"k",
")",
"end",
"response",
"=",
"api_execute",
"(",
"path",
",",
":put",
",",
"params",
":",
"payload",
")",
"Response",
".",
"from_http_response",
"(",
"response",
")",
"end"
] | Create or update a new key
This method takes the following parameters as arguments
* key - whose value to be set
* value - value to be set for specified key
* ttl - shelf life of a key (in seconds) (optional) | [
"Create",
"or",
"update",
"a",
"new",
"key"
] | f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917 | https://github.com/ranjib/etcd-ruby/blob/f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917/lib/etcd/keys.rb#L32-L41 | train |
ranjib/etcd-ruby | lib/etcd/keys.rb | Etcd.Keys.compare_and_swap | def compare_and_swap(key, opts = {})
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
fail ArgumentError, 'You must pass prevValue' unless opts.key?(:prevValue)
set(key, opts)
end | ruby | def compare_and_swap(key, opts = {})
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
fail ArgumentError, 'You must pass prevValue' unless opts.key?(:prevValue)
set(key, opts)
end | [
"def",
"compare_and_swap",
"(",
"key",
",",
"opts",
"=",
"{",
"}",
")",
"fail",
"ArgumentError",
",",
"'Second argument must be a hash'",
"unless",
"opts",
".",
"is_a?",
"(",
"Hash",
")",
"fail",
"ArgumentError",
",",
"'You must pass prevValue'",
"unless",
"opts",
".",
"key?",
"(",
":prevValue",
")",
"set",
"(",
"key",
",",
"opts",
")",
"end"
] | Set a new value for key if previous value of key is matched
This method takes the following parameters as arguments
* key - whose value is going to change if previous value is matched
* value - new value to be set for specified key
* prevValue - value of a key to compare with existing value of key
* ttl - shelf life of a key (in secsonds) (optional) | [
"Set",
"a",
"new",
"value",
"for",
"key",
"if",
"previous",
"value",
"of",
"key",
"is",
"matched"
] | f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917 | https://github.com/ranjib/etcd-ruby/blob/f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917/lib/etcd/keys.rb#L59-L63 | train |
ranjib/etcd-ruby | lib/etcd/keys.rb | Etcd.Keys.watch | def watch(key, opts = {})
params = { wait: true }
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
timeout = opts[:timeout] || @read_timeout
index = opts[:waitIndex] || opts[:index]
params[:waitIndex] = index unless index.nil?
params[:consistent] = opts[:consistent] if opts.key?(:consistent)
params[:recursive] = opts[:recursive] if opts.key?(:recursive)
response = api_execute(
key_endpoint + key,
:get,
timeout: timeout,
params: params
)
Response.from_http_response(response)
end | ruby | def watch(key, opts = {})
params = { wait: true }
fail ArgumentError, 'Second argument must be a hash' unless opts.is_a?(Hash)
timeout = opts[:timeout] || @read_timeout
index = opts[:waitIndex] || opts[:index]
params[:waitIndex] = index unless index.nil?
params[:consistent] = opts[:consistent] if opts.key?(:consistent)
params[:recursive] = opts[:recursive] if opts.key?(:recursive)
response = api_execute(
key_endpoint + key,
:get,
timeout: timeout,
params: params
)
Response.from_http_response(response)
end | [
"def",
"watch",
"(",
"key",
",",
"opts",
"=",
"{",
"}",
")",
"params",
"=",
"{",
"wait",
":",
"true",
"}",
"fail",
"ArgumentError",
",",
"'Second argument must be a hash'",
"unless",
"opts",
".",
"is_a?",
"(",
"Hash",
")",
"timeout",
"=",
"opts",
"[",
":timeout",
"]",
"||",
"@read_timeout",
"index",
"=",
"opts",
"[",
":waitIndex",
"]",
"||",
"opts",
"[",
":index",
"]",
"params",
"[",
":waitIndex",
"]",
"=",
"index",
"unless",
"index",
".",
"nil?",
"params",
"[",
":consistent",
"]",
"=",
"opts",
"[",
":consistent",
"]",
"if",
"opts",
".",
"key?",
"(",
":consistent",
")",
"params",
"[",
":recursive",
"]",
"=",
"opts",
"[",
":recursive",
"]",
"if",
"opts",
".",
"key?",
"(",
":recursive",
")",
"response",
"=",
"api_execute",
"(",
"key_endpoint",
"+",
"key",
",",
":get",
",",
"timeout",
":",
"timeout",
",",
"params",
":",
"params",
")",
"Response",
".",
"from_http_response",
"(",
"response",
")",
"end"
] | Gives a notification when specified key changes
This method takes the following parameters as arguments
@ key - key to be watched
@options [Hash] additional options for watching a key
@options [Fixnum] :index watch the specified key from given index
@options [Fixnum] :timeout specify http timeout | [
"Gives",
"a",
"notification",
"when",
"specified",
"key",
"changes"
] | f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917 | https://github.com/ranjib/etcd-ruby/blob/f7153c6a7829b1cd5e5a4470d7ca6f5217c4c917/lib/etcd/keys.rb#L72-L88 | train |
marcelocf/gremlin_client | lib/gremlin_client/connection.rb | GremlinClient.Connection.receive_message | def receive_message(msg)
response = Oj.load(msg.data)
# this check is important in case a request timeout and we make new ones after
if response['requestId'] == @request_id
if @response.nil?
@response = response
else
@response['result']['data'].concat response['result']['data']
@response['result']['meta'].merge! response['result']['meta']
@response['status'] = response['status']
end
end
end | ruby | def receive_message(msg)
response = Oj.load(msg.data)
# this check is important in case a request timeout and we make new ones after
if response['requestId'] == @request_id
if @response.nil?
@response = response
else
@response['result']['data'].concat response['result']['data']
@response['result']['meta'].merge! response['result']['meta']
@response['status'] = response['status']
end
end
end | [
"def",
"receive_message",
"(",
"msg",
")",
"response",
"=",
"Oj",
".",
"load",
"(",
"msg",
".",
"data",
")",
"if",
"response",
"[",
"'requestId'",
"]",
"==",
"@request_id",
"if",
"@response",
".",
"nil?",
"@response",
"=",
"response",
"else",
"@response",
"[",
"'result'",
"]",
"[",
"'data'",
"]",
".",
"concat",
"response",
"[",
"'result'",
"]",
"[",
"'data'",
"]",
"@response",
"[",
"'result'",
"]",
"[",
"'meta'",
"]",
".",
"merge!",
"response",
"[",
"'result'",
"]",
"[",
"'meta'",
"]",
"@response",
"[",
"'status'",
"]",
"=",
"response",
"[",
"'status'",
"]",
"end",
"end",
"end"
] | this has to be public so the websocket client thread sees it | [
"this",
"has",
"to",
"be",
"public",
"so",
"the",
"websocket",
"client",
"thread",
"sees",
"it"
] | 91645fd6a5e47e3faf2d925c9aebec86bb457fb1 | https://github.com/marcelocf/gremlin_client/blob/91645fd6a5e47e3faf2d925c9aebec86bb457fb1/lib/gremlin_client/connection.rb#L99-L111 | train |
marcelocf/gremlin_client | lib/gremlin_client/connection.rb | GremlinClient.Connection.treat_response | def treat_response
# note that the partial_content status should be processed differently.
# look at http://tinkerpop.apache.org/docs/3.0.1-incubating/ for more info
ok_status = [:success, :no_content, :partial_content].map { |st| STATUS[st] }
unless ok_status.include?(@response['status']['code'])
fail ::GremlinClient::ServerError.new(@response['status']['code'], @response['status']['message'])
end
@response['result']
end | ruby | def treat_response
# note that the partial_content status should be processed differently.
# look at http://tinkerpop.apache.org/docs/3.0.1-incubating/ for more info
ok_status = [:success, :no_content, :partial_content].map { |st| STATUS[st] }
unless ok_status.include?(@response['status']['code'])
fail ::GremlinClient::ServerError.new(@response['status']['code'], @response['status']['message'])
end
@response['result']
end | [
"def",
"treat_response",
"ok_status",
"=",
"[",
":success",
",",
":no_content",
",",
":partial_content",
"]",
".",
"map",
"{",
"|",
"st",
"|",
"STATUS",
"[",
"st",
"]",
"}",
"unless",
"ok_status",
".",
"include?",
"(",
"@response",
"[",
"'status'",
"]",
"[",
"'code'",
"]",
")",
"fail",
"::",
"GremlinClient",
"::",
"ServerError",
".",
"new",
"(",
"@response",
"[",
"'status'",
"]",
"[",
"'code'",
"]",
",",
"@response",
"[",
"'status'",
"]",
"[",
"'message'",
"]",
")",
"end",
"@response",
"[",
"'result'",
"]",
"end"
] | we validate our response here to make sure it is going to be
raising exceptions in the right thread | [
"we",
"validate",
"our",
"response",
"here",
"to",
"make",
"sure",
"it",
"is",
"going",
"to",
"be",
"raising",
"exceptions",
"in",
"the",
"right",
"thread"
] | 91645fd6a5e47e3faf2d925c9aebec86bb457fb1 | https://github.com/marcelocf/gremlin_client/blob/91645fd6a5e47e3faf2d925c9aebec86bb457fb1/lib/gremlin_client/connection.rb#L159-L167 | train |
yandex-money/yandex-money-sdk-ruby | lib/yandex_money/external_payment.rb | YandexMoney.ExternalPayment.request_external_payment | def request_external_payment(payment_options)
payment_options[:instance_id] = @instance_id
request = self.class.send_external_payment_request("/api/request-external-payment", payment_options)
RecursiveOpenStruct.new request.parsed_response
end | ruby | def request_external_payment(payment_options)
payment_options[:instance_id] = @instance_id
request = self.class.send_external_payment_request("/api/request-external-payment", payment_options)
RecursiveOpenStruct.new request.parsed_response
end | [
"def",
"request_external_payment",
"(",
"payment_options",
")",
"payment_options",
"[",
":instance_id",
"]",
"=",
"@instance_id",
"request",
"=",
"self",
".",
"class",
".",
"send_external_payment_request",
"(",
"\"/api/request-external-payment\"",
",",
"payment_options",
")",
"RecursiveOpenStruct",
".",
"new",
"request",
".",
"parsed_response",
"end"
] | Requests a external payment
@see http://api.yandex.com/money/doc/dg/reference/request-external-payment.xml
@see https://tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/
@param payment_options [Hash] Method's parameters. Check out docs for more information.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value.
@raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error). The application should repeat the request with the same parameters later.
@return [RecursiveOpenStruct] A struct, containing `payment_id` and additional information about a recipient and payer | [
"Requests",
"a",
"external",
"payment"
] | 5634ebc09aaad3c8f96e2cde20cc60edf6b47899 | https://github.com/yandex-money/yandex-money-sdk-ruby/blob/5634ebc09aaad3c8f96e2cde20cc60edf6b47899/lib/yandex_money/external_payment.rb#L38-L42 | train |
yandex-money/yandex-money-sdk-ruby | lib/yandex_money/external_payment.rb | YandexMoney.ExternalPayment.process_external_payment | def process_external_payment(payment_options)
payment_options[:instance_id] = @instance_id
request = self.class.send_external_payment_request("/api/process-external-payment", payment_options)
RecursiveOpenStruct.new request.parsed_response
end | ruby | def process_external_payment(payment_options)
payment_options[:instance_id] = @instance_id
request = self.class.send_external_payment_request("/api/process-external-payment", payment_options)
RecursiveOpenStruct.new request.parsed_response
end | [
"def",
"process_external_payment",
"(",
"payment_options",
")",
"payment_options",
"[",
":instance_id",
"]",
"=",
"@instance_id",
"request",
"=",
"self",
".",
"class",
".",
"send_external_payment_request",
"(",
"\"/api/process-external-payment\"",
",",
"payment_options",
")",
"RecursiveOpenStruct",
".",
"new",
"request",
".",
"parsed_response",
"end"
] | Confirms a payment that was created using the request-extenral-payment method
@see http://api.yandex.com/money/doc/dg/reference/process-external-payment.xml
@see https://tech.yandex.ru/money/doc/dg/reference/process-external-payment-docpage/
@param payment_options [Hash] Method's parameters. Check out docs for more information.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value.
@raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error). The application should repeat the request with the same parameters later.
@return [RecursiveOpenStruct] A status of payment and additional steps for authorization (if needed) | [
"Confirms",
"a",
"payment",
"that",
"was",
"created",
"using",
"the",
"request",
"-",
"extenral",
"-",
"payment",
"method"
] | 5634ebc09aaad3c8f96e2cde20cc60edf6b47899 | https://github.com/yandex-money/yandex-money-sdk-ruby/blob/5634ebc09aaad3c8f96e2cde20cc60edf6b47899/lib/yandex_money/external_payment.rb#L55-L59 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.