defpost_weibo(number) @number = number conn = Faraday.new(:url => "https://api.weibo.com")
result = conn.post '/2/statuses/update.json', :access_token => @weibo_config['access_token'], :status => generate_post
responseJSON = JSON.parse result.body if responseJSON['error_code'] puts 'post error:' + responseJSON['error'] else puts "post to weibo successfully" end end
private
defgenerate_post
total = get_history total = total + @number.to_i number_rest = 4000 - total
save_to_history total post_template = @weibo_config['post_template'].force_encoding("utf-8") post_template % {:number_done => @number, :total => total,:number_rest => number_rest} end
defget_history @pushups['total'] end
defsave_to_history(total) @pushups['total'] = total File.open('pushups.yml','w') do |h| h.write @pushups.to_yaml end end end