ruby on rails - Why am I getting this TypeError? "no implicit conversion of Module into Integer" -
i'm getting typeerror in cwintegratoraccountscontroller#create
. i'm calling script (cwgetcompanyintegrator.call
) in create
method of controller.
cwintegratoraccountscontroller:
require 'apis/cw_get_company_integrator' class cwintegratoraccountscontroller < applicationcontroller skip_before_filter :require_company, :only => [:create,:new] # /cw_integrator_accounts # /cw_integrator_accounts.json def create unless cwintegratoraccount.count >= 1 @cw_integrator_account = cwintegratoraccount.new(params[:cw_integrator_account]) respond_to |format| if @cw_integrator_account.save # run cw integrator cwgetcompanyintegrator.call format.html { redirect_to root_url, notice: 'cw_integrator success' } #format.json { render json: @cw_integrator_account, status: :created, location: @cw_integrator_account } else format.html { render action: 'new' } format.json { render json: @cw_integrator_account.errors, status: :unprocessable_entity } end end end end end
it looks it's failing when starts https
request connectwise server @ line: response = http.start {|h| h.request(request)}
cwgetcompanyintegrator script:
#!/usr/bin/env ruby require 'net/https' require 'uri' require 'nokogiri' require 'apis/cw_apis' class cwgetcompanyintegrator def self.call cw_integrator_account = cwintegratoraccount.first cw_hostname = cw_integrator_account.cw_hostname company_api_url = "https://#{cw_hostname}/v4_6_release/apis/2.0/companyapi.asmx" uri = uri.parse(company_api_url) request = net::http::post.new(uri.path) request.add_field('content-type', 'text/xml; charset=utf-8') request.add_field('soapaction', 'http://connectwise.com/getcompany') request.body = cwapis.get_company_xml_request http = net::http.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = openssl::ssl::verify_none response = http.start {|h| h.request(request)} xml_doc = nokogiri::xml(response.body).remove_namespaces! company_name = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/companyname').text company_street_addr = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/streetlines/string')[0].text begin company_street_addr2 = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/streetlines/string')[1].text end company_city = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/city').text company_state = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/state').text company_zip = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/zip').text company_country = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/country').text company_status = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/status').text company_phone = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/phonenumber').text company_fax = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/faxnumber').text company_www = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/website').text companyinfoscontroller.create!(cw_company_id: cw_integrator_account.cw_company_id, company_name: company_name, company_street_addr: company_street_addr, company_street_addr2: company_street_addr2, company_city: company_city, company_state: company_state, company_zip: company_zip, company_country:company_country, company_status: company_status, company_phone: company_phone, company_fax: company_fax, company_www: company_www) end end
this class called in cwgetcompanyintegrator
script:
#!/usr/bin/env ruby require 'builder' class cwapis def self.get_company_xml_request cw_integrator_account = cwintegratoraccount.first integrator_company_id = cw_integrator_account.integrator_company_id integrator_login_id = cw_integrator_account.integrator_login_id integrator_password = cw_integrator_account.integrator_password xml = builder::xmlmarkup.new(:indent=>2) xml.instruct! xml.tag!('soap:envelope', :'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/', :xmlns => 'http://connectwise.com'){ xml.tag!('soap:body'){ xml.tag!('getcompany'){ xml.tag!('credentials'){ xml.companyid(integrator_company_id) xml.integratorloginid(integrator_login_id) xml.integratorpassword(integrator_password) } xml.id(cw_integrator_account.cw_company_id) } } } end end
full trace:
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `initialize' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `new' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `connect' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:862:in `do_start' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:851:in `start' lib/apis/cw_get_company_integrator.rb:21:in `call' app/controllers/cw_integrator_accounts_controller.rb:54:in `block in create' actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:270:in `call' actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:270:in `retrieve_collector_from_mimes' actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:194:in `respond_to' app/controllers/cw_integrator_accounts_controller.rb:50:in `create' actionpack (3.2.14) lib/action_controller/metal/implicit_render.rb:4:in `send_action' actionpack (3.2.14) lib/abstract_controller/base.rb:167:in `process_action' actionpack (3.2.14) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (3.2.14) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.2.14) lib/active_support/callbacks.rb:447:in `_run__2237874046494148672__process_action__4163123032493016418__callbacks' activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.14) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.2.14) lib/action_controller/metal/rescue.rb:29:in `process_action' actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.2.14) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.14) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.14) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.2.14) lib/action_controller/metal/params_wrapper.rb:207:in `process_action' activerecord (3.2.14) lib/active_record/railties/controller_runtime.rb:18:in `process_action' actionpack (3.2.14) lib/abstract_controller/base.rb:121:in `process' actionpack (3.2.14) lib/abstract_controller/rendering.rb:45:in `process' rack-mini-profiler (0.9.2) lib/mini_profiler/profiling_methods.rb:108:in `block in profile_method' actionpack (3.2.14) lib/action_controller/metal.rb:203:in `dispatch' actionpack (3.2.14) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.2.14) lib/action_controller/metal.rb:246:in `block in action' actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:73:in `call' actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:36:in `call' journey (1.0.4) lib/journey/router.rb:68:in `block in call' journey (1.0.4) lib/journey/router.rb:56:in `each' journey (1.0.4) lib/journey/router.rb:56:in `call' actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:608:in `call' rack-webconsole-pry (0.1.9) lib/rack/webconsole/assets.rb:26:in `call' rack-webconsole-pry (0.1.9) lib/rack/webconsole.rb:79:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' rack (1.4.5) lib/rack/etag.rb:23:in `call' rack (1.4.5) lib/rack/conditionalget.rb:35:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/flash.rb:242:in `call' rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/cookies.rb:341:in `call' activerecord (3.2.14) lib/active_record/query_cache.rb:64:in `call' activerecord (3.2.14) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `_run__2942276951910103516__call__2669772965393719582__callbacks' activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/reloader.rb:65:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.14) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.14) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.14) lib/active_support/tagged_logging.rb:22:in `tagged' railties (3.2.14) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' rack (1.4.5) lib/rack/runtime.rb:17:in `call' activesupport (3.2.14) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.5) lib/rack/lock.rb:15:in `call' actionpack (3.2.14) lib/action_dispatch/middleware/static.rb:63:in `call' rack-mini-profiler (0.9.2) lib/mini_profiler/profiler.rb:300:in `call' railties (3.2.14) lib/rails/engine.rb:484:in `call' railties (3.2.14) lib/rails/application.rb:231:in `call' rack (1.4.5) lib/rack/content_length.rb:14:in `call' railties (3.2.14) lib/rails/rack/log_tailer.rb:17:in `call' rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
this works in plain ruby script, environment thing?
working ruby scripts:
companyapis class:
require 'builder' class companyapis def self.get_company cw_company_id = 21920 integrator_company_id = 'company_id' integrator_login_id = 'intergrator_login' integrator_password = 'intergrator_pw' xml = builder::xmlmarkup.new(:indent=>2) xml.instruct! xml.tag!('soap:envelope', :'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/', :xmlns => 'http://connectwise.com'){ xml.tag!('soap:body'){ xml.tag!('getcompany'){ xml.tag!('credentials'){ xml.companyid(integrator_company_id) xml.integratorloginid(integrator_login_id) xml.integratorpassword(integrator_password) } xml.id(cw_company_id) } } } end end
cwintegrator class:
require 'net/https' require 'uri' require 'nokogiri' require './company_api' class cwintegrator def self.call cw_company_id = 21920 cw_hostname = 'cw.host.com' companyapi_url = "https://#{cw_hostname}/v4_6_release/apis/2.0/companyapi.asmx" uri = uri.parse(companyapi_url) # use proxying kali #proxy_addr = '172.16.1.149' #proxy_port = 8080 request = net::http::post.new(uri.path) request.add_field('content-type', 'text/xml; charset=utf-8') request.add_field('soapaction', 'http://connectwise.com/getcompany') request.body = companyapis.get_company http = net::http.new(uri.host, uri.port) # use proxying kali #http = net::http.new(uri.host, uri.port, proxy_addr, proxy_port) http.use_ssl = true http.verify_mode = openssl::ssl::verify_none response = http.start {|h| h.request(request)} company_info = [] xml_doc = nokogiri::xml(response.body).remove_namespaces! company_name = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/companyname').text company_street_addr = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/streetlines/string')[0].text begin company_street_addr2 = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/streetlines/string')[1].text end company_city = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/city').text company_state = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/state').text company_zip = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/zip').text company_country = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/defaultaddress/country').text company_status = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/status').text company_phone = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/phonenumber').text company_fax = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/faxnumber').text company_www = xml_doc.xpath('//envelope/body/getcompanyresponse/getcompanyresult/website').text company_info += [company_name: company_name, cw_company_id: cw_company_id, company_name: company_name, company_street_addr: company_street_addr, company_street_addr2: company_street_addr2, company_city: company_city, company_state: company_state, company_zip: company_zip, company_country:company_country,company_status: company_status, company_phone: company_phone, company_fax: company_fax, company_www: company_www] puts(company_info) end end cwintegrator.call
rails
jealous , greedy methods call
etc. simple renaming of target method call
neutral my_call
resolve problem.
i bet there rails pretend gain full power on call method, overriding after class initialized.
Comments
Post a Comment