我有以下代码行给出了一个错误:
rescue Timeout::Error => e
logs.puts("Rescued a timeout error...#{e}")
email_ids_all.each do |email_delete|
call= "/api/v2/emails/#{email_delete}/"
uri= HTTParty.delete("https://www.surveys.com#{call}",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/x-www-form-urlencoded', 'Content-Length' => "0" }
)
puts "Deleted email #{email_delete}".green
log.puts("Deleted email #{email_delete}")
end
abort #abort entire script after deleting emails
end
Run Code Online (Sandbox Code Playgroud)
我收到的错误是这样的:
syntax error, unexpected keyword_rescue, expecting $end
rescue Timeout::Error => e
^
Run Code Online (Sandbox Code Playgroud)
基本上我只是尝试在脚本超时时运行API删除调用.虽然我在块中放入了什么并不重要,rescue但是我收到了同样的错误.我的rescue方法语法有什么问题?
以下请求有什么问题?
request = Typhoeus::Request.new("http://fluidsurveys.com/api/v2/groups",
method: :get,
userpwd: "test_user:test_password",
headers: { 'ContentType' => "application/json"})
response = request.body
puts response
Run Code Online (Sandbox Code Playgroud)
这回来了 undefined method body for #<Typhoeus::Request:0x007f8e50d3b1d0> (NoMethodError)
以下请求适用于httparty:
call= "/api/v2/groups/"
auth = {:username => "test_user", :password => "test_password"}
url = HTTParty.get("http://fluidsurveys.com/api/v2/groups",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' } )
response = url.body
puts response
Run Code Online (Sandbox Code Playgroud)
编辑:
我试过这个:
response = request.response
puts response.body
Run Code Online (Sandbox Code Playgroud)
没有运气.我收到了这个:undefined method body for nil:NilClass (NoMethodError)
我有一个字符串数组:
string_array = ['memberid', 'membershiptype', 'date']
Run Code Online (Sandbox Code Playgroud)
现在我需要检查这个数组是否包含'id',我希望它返回true.
我知道我可以做string_array.include? 'memberid',但我需要在该字符串中找到一个子字符串'id'.
我是第一次调用基于SOAP的API,我从文档中获得以下信息:
在您的客户端中,构建您的授权标头,如下所示:
1连接用户名和密码,例如:ExampleUsername:ExamplePassword
2在base 64中编码字符串,例如:RXhhbXBsZVVzZXJOYW1lOVV4YW1wbGVQYXNzd29yZA ==
3在代码中,输入值为Basic的Authorization标头.
示例Web服务标头,带有编码的用户名和密码
POST https://api.five9.com/wsadmin/AdminWebService HTTP/1.1
Accept-Encoding:gzip,deflate
Content-Type:text/xml; charset = UTF-8
SOAPAction:""
授权:基本RXhhbXBsZVVzZXJOYW110kV4YW1wbGVQYXNzd29yZA ==
我正在使用Savon宝石来打电话.在api_call给定上述信息的情况下,如何使用Ruby 1.9.3和Savon gem验证API调用?
这就是我用来设置WSDL的方法,或者client.
client = Savon.client(wsdl: "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=luigi@apitest.com")
Run Code Online (Sandbox Code Playgroud) 我试图在Ruby中创建一个.rb文件,使用以下步骤:
1. Create New File
2. Name new file "a"
3. Associate file to .rb filetype
Run Code Online (Sandbox Code Playgroud)
这会创建一个名为"a"的文件,它可以正常工作; 但是,当我将此文件重命名为a.rb时,它会立即将文件转换为文本文件.这是为什么?
我一直在创建一个新文件,并a.rb从一开始就命名为" ",并自动将它与一个ruby文件相关联.现在它只是将命名与文本文件相关联,我不得不离开.rb并稍后手动分配文件类型.改变了什么?
我有以下代码:
<%= simple_form_for @comment do |f| %>
<%= f.input :comment, label: 'Phrase you would like to add:' %>
<%= f.collection_radio_buttons :options, [[true, 'Positive'] ,[false, 'Negative']], :first, :last, label: 'Emotion' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但单选按钮collection_radio_buttons并排.如何将单选按钮垂直叠放在一起?
我使用net-sftp gem将文件下载到内存:
sftp = Net::SFTP.start('ftp.myapp.com','user_name', :password => 'password')
records = sftp.download!("luigi/List.csv")
Run Code Online (Sandbox Code Playgroud)
然后我需要移动我的文件,位于远程luigi/List.csv并重命名.
我想在这里移动它:
"luigi/archive/List_#{Time.now}.csv"
我想删除位于的原始文件luigi/List.csv.
如何使用ruby 2.0.0和rails 4.0.0在我的FTP站点上移动,重命名和删除文件?
我一直在我的开发环境中测试我的sidekiq工作者,他们工作正常.然而,当我推到Heroku时,我似乎无法让我的工人开始.
我不确定解决此问题的最佳方法,但这里有一些信息:
web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
Run Code Online (Sandbox Code Playgroud)
我没有sidekiq.yaml文件.
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 9999
preload_app true
before_fork do |server, worker|
@sidekiq_pid ||= spawn("bundle exec sidekiq -c 2")
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
worker_processes 3
after_fork do |server, worker|
Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
end
Sidekiq.configure_server do |config|
config.redis = { :size => …Run Code Online (Sandbox Code Playgroud) 如何将我的文件设置为不提取 csv 文件中的标题?我已经尝试过这个:
CSV.foreach(email_response_file, :col_sep => "\t", :return_headers => false) do |column|
....
end
Run Code Online (Sandbox Code Playgroud)
但是,无论我设置:return_headers为 true 还是 false,我仍然会拉入标题。我怎样才能摆脱它们?我认为我的问题是.foreach我正在使用的方法。
我有以下代码:
Test.all.where("comment like '%test%'")
Run Code Online (Sandbox Code Playgroud)
我怎么能写这个包括所有模型的地方Test.comment is like '%test%',但忽略了这个例子test.Test,Testing并且TEST都应归还.