Module: Flappy::Publish

Included in:
Util::ClassMethods
Defined in:
lib/flappy/util/publish.rb

Instance Method Summary collapse

Instance Method Details

#fetch_app_infoObject



116
117
118
119
120
121
122
# File 'lib/flappy/util/publish.rb', line 116

def fetch_app_info
  logger.info 'Fetch app info from fir.im'

  @fir_app_info = get(fir_api[:app_url] + "/#{@app_id}", api_token: @token)
  write_app_info(id: @fir_app_info[:id], short: @fir_app_info[:short], name: @fir_app_info[:name])
  @fir_app_info
end

#fetch_uploading_infoObject



107
108
109
110
111
112
113
114
# File 'lib/flappy/util/publish.rb', line 107

def fetch_uploading_info
  logger.info "Fetching #{@app_info[:identifier]}@fir.im uploading info......"
  logger.info "Uploading app: #{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]})"

  post fir_api[:app_url], type:      @app_info[:type],
                          bundle_id: @app_info[:identifier],
                          api_token: @token
end

#logger_info_app_short_and_qrcodeObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/flappy/util/publish.rb', line 135

def logger_info_app_short_and_qrcode
  short = "#{fir_api[:domain]}/#{@fir_app_info[:short]}"

  logger.info "Published succeed: #{short}"

  if @export_qrcode
    qrcode_path = "#{File.dirname(@file_path)}/fir-#{@app_info[:name]}.png"
    Flappy.generate_rqrcode(short, qrcode_path)

    logger.info "Local qrcode file: #{qrcode_path}"
  end
end

#logger_info_publishing_messageObject



25
26
27
28
29
30
31
32
33
# File 'lib/flappy/util/publish.rb', line 25

def logger_info_publishing_message
   = (@token)

  email = .fetch(:email, '')
  name  = .fetch(:name, '')

  logger.info "Publishing app via #{name}<#{email}>......."
  logger_info_dividing_line
end

#publish(*args, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/flappy/util/publish.rb', line 6

def publish(*args, options)
  initialize_publish_options(args, options)
  check_supported_file_and_token

  logger_info_publishing_message

  @app_info       = send("#{@file_type}_info", @file_path, full_info: true)
  @uploading_info = fetch_uploading_info
  @app_id         = @uploading_info[:id]

  upload_app

  logger_info_dividing_line
  logger_info_app_short_and_qrcode

  upload_mapping_file_with_publish(options)
  logger_info_blank_line
end

#update_app_infoObject



97
98
99
100
101
102
103
104
105
# File 'lib/flappy/util/publish.rb', line 97

def update_app_info
  update_info = { short: @short, passwd: @passwd, is_opened: @is_opened }.compact

  return if update_info.blank?

  logger.info "Updating app info......"

  patch fir_api[:app_url] + "/#{@app_id}", update_info.merge(api_token: @token)
end

#upload_appObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/flappy/util/publish.rb', line 35

def upload_app
  @icon_cert   = @uploading_info[:cert][:icon]
  @binary_cert = @uploading_info[:cert][:binary]

  upload_app_icon unless @app_info[:icons].blank?
  upload_app_binary
  upload_device_info
  update_app_info
  fetch_app_info
end

#upload_device_infoObject



87
88
89
90
91
92
93
94
95
# File 'lib/flappy/util/publish.rb', line 87

def upload_device_info
  return if @app_info[:devices].blank?

  logger.info 'Updating devices info......'

  post fir_api[:udids_url], key:       @binary_cert[:key],
                            udids:     @app_info[:devices].join(','),
                            api_token: @token
end

#upload_mapping_file_with_publish(options) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/flappy/util/publish.rb', line 124

def upload_mapping_file_with_publish(options)
  return if !options[:mappingfile] || !options[:proj]

  logger_info_blank_line

  mapping options[:mappingfile], proj:    options[:proj],
                                 build:   @app_info[:build],
                                 version: @app_info[:version],
                                 token:   @token
end

#uploading_binary_infoObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/flappy/util/publish.rb', line 72

def uploading_binary_info
  {
    key:   @binary_cert[:key],
    token: @binary_cert[:token],
    file:  File.new(@file_path, 'rb'),
    # Custom variables
    'x:name'              => @app_info[:display_name] || @app_info[:name],
    'x:build'             => @app_info[:build],
    'x:version'           => @app_info[:version],
    'x:changelog'         => @changelog,
    'x:release_type'      => @app_info[:release_type],
    'x:distribution_name' => @app_info[:distribution_name]
  }
end

#uploading_icon_infoObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/flappy/util/publish.rb', line 60

def uploading_icon_info
  large_icon_path     = @app_info[:icons].max_by { |f| File.size(f) }
  uncrushed_icon_path = convert_icon(large_icon_path)

  {
    key:   @icon_cert[:key],
    token: @icon_cert[:token],
    file:  File.new(uncrushed_icon_path, 'rb'),
    'x:is_converted' => '1'
  }
end