create a new site when pushing for the first time to the hosting platform

did committed May 03, 2014
commit 3a75d2980993f8965da69c540075166a6fbdc929
Showing 3 changed files with 14 additions and 63 deletions
locomotive/wagon.rb b/lib/locomotive/wagon.rb +8 -6
@@ @@ -14,13 +14,15 @@ module Locomotive
# @param [ Object ] shell Used to ask for/prompt information
#
def self.authenticate(email, password, shell)
- require 'locomotive/wagon/misc/engine_api'
+ require 'locomotive/wagon/misc/hosting_api'
require 'netrc'
- api = Locomotive::ClientAPI.new
+ api_key = nil
+ api = Locomotive::HostingAPI.new(email, password)
- if api_key = api.api_key(email, password)
+ if api.authenticated?
# existing account
+ api_key = api.api_key
say "You have been successfully authenticated.", :green
else
# new account?
@@ @@ -29,7 +31,7 @@ module Locomotive
if shell.yes?('Do you want to create a new account? [Y/N]')
name = shell.ask 'What is your name?'
- if account = api.create_account(name, email, password)
+ if account = api.create_account(name: name, email: email, password: password)
shell.say "Your account has been successfully created.", :green
api_key = account['api_key']
end
@@ @@ -134,8 +136,8 @@ module Locomotive
def self.push(path, connection_info, options = {})
if reader = self.require_mounter(path, true)
- reader.mounting_point.site.domains = connection_info['domains'] if connection_info["domains"]
- reader.mounting_point.site.subdomain = connection_info['subdomain'] if connection_info["subdomain"]
+ reader.mounting_point.site.domains = connection_info['domains'] if connection_info['domains']
+ reader.mounting_point.site.subdomain = connection_info['subdomain'] if connection_info['subdomain']
require 'bundler'
Bundler.require 'misc'
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb +6 -14
@@ @@ -346,25 +346,17 @@ module Locomotive
# @return [ Hash ] The information of the connection or nil if errors
#
def retrieve_connection_info(env, path)
- require 'active_support/core_ext/hash'
- require 'erb'
- connection_info = nil
+ require 'locomotive/wagon/misc/deployment_connection'
+
begin
- path_to_deploy_file = File.join(path, 'config', 'deploy.yml')
- env_parsed_deploy_file = ERB.new(File.open(path_to_deploy_file).read).result
- connection_info = YAML::load(env_parsed_deploy_file)[env.to_s].with_indifferent_access
+ service = Locomotive::Wagon::DeploymentConnection.new(path, shell)
- if connection_info[:ssl] && !connection_info[:host].start_with?('https')
- connection_info[:host] = 'https://' + connection_info[:host]
- end
+ service.get_information(env)
- if connection_info.nil?
- raise "No #{env.to_s} environment found in the config/deploy.yml file"
- end
rescue Exception => e
- say "Unable to read the information about the remote LocomotiveCMS site (#{e.message})", :red
+ say "Unable to read the information about the deployment, reason: #{e.message}", :red
+ nil
end
- connection_info
end
end
locomotive/wagon/misc/engine_api.rb b/lib/locomotive/wagon/misc/engine_api.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require 'httparty'
-
- module Locomotive
- class ClientAPI
-
- include HTTParty
-
- base_uri ENV['HOSTING_URL'] || 'https://www.locomotivehosting.fr'
-
- def host
- URI(self.class.base_uri).host
- end
-
- def auth_token(email, password)
- response = self.class.get('/locomotive/api/tokens.json', { body: { email: email, password: password }})
-
- if response.success?
- response['token']
- end
- end
-
- def api_key(email, password)
- if auth_token = auth_token(email, password)
- my_account(auth_token)['api_key']
- end
- end
-
- def my_account(auth_token)
- self.class.get('/locomotive/api/my_account.json', { query: { auth_token: auth_token }})
- end
-
- def create_account(name, email, password)
- account = { name: name, email: email, password: password, password_confirmation: password }
-
- response = self.class.post('/locomotive/api/my_account.json', { body: { account: account }})
-
- if response.success?
- response.parsed_response
- end
- end
-
- end
- end
\ No newline at end of file