class XCJobs::Distribute::Crittercism::OAuth2

Attributes

app_id[RW]

required

dsym[RW]
token[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/xcjobs/crittercism/oauth2.rb, line 17
def initialize()
  yield self if block_given?
  @upload_url = "https://files.crittercism.com/api/v1/applications/#{app_id}/symbol-uploads"
  @process_symbol_url = "https://app.crittercism.com/v1.0/app/#{app_id}/symbols/uploads"
  @oauth_header = "-H 'Authorization: Bearer #{token}'"
  define
end

Private Instance Methods

create_resource_id() click to toggle source
# File lib/xcjobs/crittercism/oauth2.rb, line 42
def create_resource_id
  response = `/usr/bin/curl -X POST #{@upload_url} #{@oauth_header}  --silent`
  resource_id = JSON.parse(response)["resource-id"]
  if resource_id.nil? then
    throw "Crittercism Resource FAILED create"
  end
  resource_id
end
define() click to toggle source
# File lib/xcjobs/crittercism/oauth2.rb, line 27
def define
  namespace :distribute do
    desc 'upload & process dSYMs to Crittercism using OAuth2'
    task :crittercism_oauth2 do
      begin
        resource_id = create_resource_id
        upload_dsym(resource_id)
        process_symbols(resource_id)
      rescue => ex
        fail ex
      end
    end
  end
end
process_symbols(resource_id) click to toggle source
# File lib/xcjobs/crittercism/oauth2.rb, line 58
def process_symbols(resource_id)
  json = '{ "uploadUuid": "' + resource_id + '", "filename":"upload.zip" }'
  response = `/usr/bin/curl  --write-out %{http_code} --silent --output /dev/null -X POST "#{@process_symbol_url}" --silent -d '#{json}' #{@oauth_header} -H 'Content-Type: application/json'`
  if response != "200" then
    throw "Crittercism Resource #{resource_id} Processed: FAILED #{response}"
  end
end
upload_dsym(resource_id) click to toggle source
# File lib/xcjobs/crittercism/oauth2.rb, line 51
def upload_dsym(resource_id)
  response = `/usr/bin/curl -X PUT #{@upload_url}/#{resource_id} --write-out %{http_code} --silent --output /dev/null -F name=symbolUpload -F filedata=@"#{dsym}" #{@oauth_header}`
  if response != "202" then
    throw "Crittercism Resource #{resource_id} Uploaded: FAILED #{response}"
  end
end