Sha256: 219ab22b65b15814299db6c545604933b341d91fc852a61903b6a33c0ff1c976
Contents?: true
Size: 1.91 KB
Versions: 5
Compression:
Stored size: 1.91 KB
Contents
require 'faraday' require 'faraday_middleware' require 'lhj/helper/pgyer_config' require 'lhj/command/yapi/formatters/service' require 'lhj/config' require_relative 'tb_config' module Lhj # pgyer upload class Pgyer API_HOST = 'https://upload.pgyer.com/apiv1/app/upload'.freeze attr_reader :api_key, :user_key, :password, :result def initialize @api_key = Lhj::PgyerConfig.api_key @user_key = Lhj::PgyerConfig.user_key @password = Lhj::PgyerConfig.password @result = { 'data' => {} } end # @return [Faraday::Connection] def http_client conn_options = { request: { timeout: 1000, open_timeout: 300 } } Faraday.new(nil, conn_options) do |builder| builder.request :multipart builder.request :url_encoded builder.response :json, content_type: /\bjson$/ builder.adapter :net_http end end def upload_file(file, des) update_description = @result[:update_description] update_description = "" if update_description.nil? params = { '_api_key' => @api_key, 'uKey' => @user_key, 'password' => @password, 'updateDescription' => des, 'installType' => 2, 'file' => Faraday::UploadIO.new(file, 'application/octet-stream') } begin puts 'begin upload' response = http_client.post API_HOST, params @result = response.body puts @result if @result['data'] && @result['data']['appUpdateDescription'] @result['data']['appUpdateDescription'] = Lhj::TbHelper.trans_tb(@result['data']['appUpdateDescription']) end rescue Faraday::TimeoutError puts 'upload fail' end end def render_template temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'pgyer.erb')) Lhj::ErbFormatter::Service.new(self).render_template(temp_str) end end end
Version data entries
5 entries across 5 versions & 1 rubygems