class LineChange::Connection

Constants

API_KEY_HEADER
APK_MIME_TYPE

Attributes

conn[R]

Public Class Methods

new(adapters = [Faraday.default_adapter], logging = false) click to toggle source
# File lib/line_change/connection.rb, line 15
def initialize(adapters = [Faraday.default_adapter], logging = false)
  @conn = Faraday.new(url: 'https://rink.hockeyapp.net') do |faraday|
    faraday.request  :multipart
    faraday.request  :url_encoded
    faraday.request  :json

    faraday.response :logger if logging
    faraday.response :json
    faraday.response :response_handler

    faraday.adapter  *adapters
  end
end

Public Instance Methods

upload(path, id) click to toggle source
# File lib/line_change/connection.rb, line 29
def upload(path, id)
  conn.post(url(id), body(path), API_KEY_HEADER => LineChange.configuration.api_key)
end

Private Instance Methods

body(path) click to toggle source
# File lib/line_change/connection.rb, line 41
def body(path)
  {
    status: 2,
    notify: 0,
    notes: notes(path),
    notes_type: 0,
    ipa: Faraday::UploadIO.new(path, APK_MIME_TYPE)
  }
end
notes(path) click to toggle source
# File lib/line_change/connection.rb, line 51
def notes(path)
  if /^(\d+)/ =~ File.basename(path)
    "Build number #{$1}"
  else
    "Build file #{File.basename(path)}"
  end
end
url(id) click to toggle source
# File lib/line_change/connection.rb, line 37
def url(id)
  "/api/2/apps/#{id}/app_versions/upload"
end