Class: Socialcast::CommandLine::CLI
- Inherits:
-
Thor
- Object
- Thor
- Socialcast::CommandLine::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/socialcast/command_line/cli.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #provision ⇒ Object
- #share(message = nil) ⇒ Object
- #sync_photos ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
36 |
# File 'lib/socialcast/command_line/cli.rb', line 36 def initialize(*args); super; end |
Instance Method Details
#authenticate ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/socialcast/command_line/cli.rb', line 43 def authenticate user = [:user] || ask('Socialcast username: ') password = [:password] || HighLine.new.ask("Socialcast password: ") { |q| q.echo = false }.to_s domain = [:domain] url = ['https://', domain, '/api/authentication'].join say "Authenticating #{user} to #{url}" params = { :email => user, :password => password } RestClient.log = Logger.new(STDOUT) if [:trace] RestClient.proxy = [:proxy] if [:proxy] resource = RestClient::Resource.new url response = resource.post params, :accept => :json say "API response: #{response.body.to_s}" if [:trace] communities = JSON.parse(response.body.to_s)['communities'] domain = communities.detect {|c| c['domain'] == domain} ? domain : communities.first['domain'] Socialcast::CommandLine.credentials = {:user => user, :password => password, :domain => domain, :proxy => [:proxy]} say "Authentication successful for #{domain}" end |
#provision ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/socialcast/command_line/cli.rb', line 103 def provision config = ldap_config load_plugins Socialcast::CommandLine::Provision.new(config, ).provision rescue Socialcast::CommandLine::Provision::ProvisionError => e Kernel.abort e. end |
#share(message = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/socialcast/command_line/cli.rb', line 68 def share( = nil) ||= $stdin.read_nonblock(100_000) rescue nil = [] [:attachments].each do |path| Dir[File.(path)].each do || say "Uploading attachment #{}..." uploader = Socialcast::CommandLine.resource_for_path '/api/attachments', {}, [:trace] uploader.post({:attachment => File.new()}, {:accept => :json}) do |response, request, result| if response.code == 201 << JSON.parse(response.body)['attachment']['id'] else say "Error uploading attachment: #{response.body}" end end end end ActiveResource::Base.logger = Logger.new(STDOUT) if [:trace] Socialcast::CommandLine::Message.configure_from_credentials Socialcast::CommandLine::Message.create :body => , :url => [:url], :message_type => [:message_type], :attachment_ids => , :group_id => [:group_id] say "Message has been shared" end |
#sync_photos ⇒ Object
115 116 117 118 119 |
# File 'lib/socialcast/command_line/cli.rb', line 115 def sync_photos config = ldap_config Socialcast::CommandLine::Provision.new(config).sync_photos end |