Sha256: d03633affca066c60011ef91ca757db178150ad913eae7f62d7c49d04ae658f3

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
require "uri"
require "net/http"
require 'lhj/helper/pgyer_config'

module Lhj
  # pgyer upload
  class PgyerShortcut
    API_SHORTCUT_HOST = 'https://www.pgyer.com/apiv2/app/getByShortcut'

    attr_reader :api_key, :user_key, :password, :shortcut_url

    def initialize(env = :uat)
      @api_key = Lhj::PgyerConfig.api_key(env)
      @user_key = Lhj::PgyerConfig.user_key(env)
      @shortcut_url = Lhj::PgyerConfig.shortcut_url(env)
    end

    def request_shortcut_body
      url = URI(API_SHORTCUT_HOST)

      https = Net::HTTP.new(url.host, url.port)
      https.use_ssl = true

      request = Net::HTTP::Post.new(url)
      request['Content-Type'] = 'application/x-www-form-urlencoded'
      request.body = "_api_key=#{@api_key}&buildShortcutUrl=#{@shortcut_url}"

      response = https.request(request)
      response.read_body
    end

    def build_version
      body = request_shortcut_body
      res_json = JSON.parse(body)
      res = ''
      res = res_json['data']['buildBuildVersion'] if res_json['code'].to_i.zero?
      res
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lhj-tools-0.1.47 lib/lhj/helper/pgyer_shortcut_helper.rb