Sha256: 7f2bf21b00f03e04c95eceaedc0993dd5c5aed73231136bce31252ae6b78cf16

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'json'
require 'rest-client'
require 'fileutils'
require 'conflux/helpers'

namespace :conflux do

  desc 'Set which conflux app to use for the current directory'
  task :set_app do
    helpers = Conflux::Helpers
    creds = helpers.ask_for_basic_creds

    auth_response_body = helpers.json_request(
      Net::HTTP::Post,
      '/users/apps_basic_auth',
      creds,
      nil,
      'Authentication failed.'
    )

    # Ask which app the user wants to use:
    app_slug = helpers.prompt_user_to_select_app(auth_response_body['apps_map'])

    manifest_response_body = helpers.form_request(
      Net::HTTP::Get,
      '/apps/manifest',
      { app_slug: app_slug },
      { 'Conflux-User' => auth_response_body['token'] },
      'Connecting to Conflux app failed.'
    )

    manifest_json = manifest_response_body['manifest']

    # Create .conflux/ folder if doesn't already exist
    FileUtils.mkdir_p(helpers.conflux_folder_path) if !File.exists?(helpers.conflux_folder_path)

    puts 'Configuring manifest.json...'

    # Write this app info to a new manifest.json file for the user
    File.open(helpers.conflux_manifest_path, 'w+') do |f|
      f.write(JSON.pretty_generate(manifest_json))
    end

    puts "Successfully connected project to conflux app: #{app_slug}"
    puts "The 'conflux' ruby gem wasn't automatically installed...Make sure it's installed if it's not already."
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
conflux-1.0.5 lib/tasks/conflux.rake
conflux-1.0.4 lib/tasks/conflux.rake
conflux-1.0.3 lib/tasks/conflux.rake
conflux-1.0.2 lib/tasks/conflux.rake