Module: FIR::Publish

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

Instance Method Summary collapse

Instance Method Details

#fetch_app_infoObject



121
122
123
124
125
# File 'lib/fir/util/publish.rb', line 121

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

  get fir_api[:app_url] + "/#{@app_id}", api_token: @token
end

#fetch_uploading_infoObject



113
114
115
116
117
118
119
# File 'lib/fir/util/publish.rb', line 113

def fetch_uploading_info
  logger.info "Fetching #{@app_info[:identifier]}@fir.im uploading info......"

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

#logger_info_app_short_and_qrcodeObject



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/fir/util/publish.rb', line 138

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

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

  if @export_qrcode
    qrcode_path = "#{File.dirname(@file_path)}/fir-#{@app_info[:name]}.png"
    FIR.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/fir/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/fir/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



104
105
106
107
108
109
110
111
# File 'lib/fir/util/publish.rb', line 104

def update_app_info
  return if @short.blank?

  logger.info 'Updating app info......'

  patch fir_api[:app_url] + "/#{@app_id}", short:     @short,
                                           api_token: @token
end

#upload_appObject



35
36
37
38
39
40
41
42
43
# File 'lib/fir/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
end

#upload_app_binaryObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/fir/util/publish.rb', line 68

def upload_app_binary
  logger.info 'Uploading app binary......'

  uploaded_info = post(@binary_cert[:upload_url], uploading_binary_info)

  return if uploaded_info[:is_completed]

  logger.error 'Upload app binary failed'
  exit 1
end

#upload_app_iconObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/fir/util/publish.rb', line 45

def upload_app_icon
  logger.info 'Uploading app icon......'

  uploaded_info = post(@icon_cert[:upload_url], uploading_icon_info)

  return if uploaded_info[:is_completed]

  logger.error 'Upload app icon failed'
  exit 1
end

#upload_device_infoObject



94
95
96
97
98
99
100
101
102
# File 'lib/fir/util/publish.rb', line 94

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



127
128
129
130
131
132
133
134
135
136
# File 'lib/fir/util/publish.rb', line 127

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fir/util/publish.rb', line 79

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



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fir/util/publish.rb', line 56

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