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

#publish(*args, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fir/util/publish.rb', line 6

def publish *args, options
  @file_path = File.absolute_path(args.first.to_s)
  @token     = options[:token] || current_token
  @changelog = options[:changelog].to_s
  @short     = options[:short].to_s

  check_supported_file_and_token

  logger.info "Publishing app......."
  logger_info_dividing_line

  file_type = File.extname(@file_path).delete(".")

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

  upload_app

  logger_info_dividing_line
  logger.info "Published succeed: #{fir_api[:domain]}/#{fetch_app_info[:short]}"

  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

  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
  unless @short.blank?
    logger.info "Updating app info......"

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

#upload_appObject



40
41
42
43
44
45
46
47
48
# File 'lib/fir/util/publish.rb', line 40

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

  upload_app_icon
  upload_app_binary
  upload_device_info
  update_app_info
end

#upload_app_binaryObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fir/util/publish.rb', line 71

def upload_app_binary
  logger.info "Uploading app......"

  hash = {
    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],
  }

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

  unless uploaded_info[:is_completed]
    logger.error "Upload app binary failed"
    exit 1
  end
end

#upload_app_iconObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fir/util/publish.rb', line 50

def upload_app_icon
  unless @app_info[:icons].blank?
    logger.info "Uploading app's icon......"

    icon_path = @app_info[:icons].max_by { |f| File.size(f) }

    hash = {
      key:   @icon_cert[:key],
      token: @icon_cert[:token],
      file:  File.new(icon_path, "rb")
    }

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

    unless uploaded_info[:is_completed]
      logger.error "Upload app icon failed"
      exit 1
    end
  end
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
  unless @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
end