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
- #authenticate_external_system ⇒ Object
- #info ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #provision ⇒ Object
- #share(message = nil) ⇒ Object
- #sync_photos ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
19 |
# File 'lib/socialcast/command_line/cli.rb', line 19 def initialize(*args); super; end |
Instance Method Details
#authenticate ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/socialcast/command_line/cli.rb', line 35 def authenticate user = [:user] || ask('Socialcast login (email address): ') password = [:password] || HighLine.new.ask("Socialcast password: ") { |q| q.echo = false }.to_s params = { :email => user, :password => password } response = Socialcast::CommandLine::Authenticate.new(:user, , params).request 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 } say "Authentication successful for #{domain}" end |
#authenticate_external_system ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/socialcast/command_line/cli.rb', line 57 def authenticate_external_system api_client_identifier = [:api_client_identifier] || ask("Socialcast external system identifier: ") api_client_secret = [:api_client_secret] || ask("Socialcast external system API secret: ") headers = { :headers => { :Authorization => "SocialcastApiClient #{api_client_identifier}:#{api_client_secret}" } } Socialcast::CommandLine::Authenticate.new(:external_system, , {}, headers).request Socialcast::CommandLine.credentials = { :api_client_identifier => api_client_identifier, :api_client_secret => api_client_secret, } end |
#info ⇒ Object
23 24 25 26 27 |
# File 'lib/socialcast/command_line/cli.rb', line 23 def info if ["version"] say "Socialcast Command Line #{Socialcast::CommandLine::VERSION}" end end |
#provision ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/socialcast/command_line/cli.rb', line 115 def provision config = ldap_config load_plugins Socialcast::CommandLine::ProvisionUser.new(config, ).provision rescue Socialcast::CommandLine::ProvisionUser::ProvisionError => e Kernel.abort e. end |
#share(message = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/socialcast/command_line/cli.rb', line 80 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 Socialcast::CommandLine::Message.with_debug [:trace] do Socialcast::CommandLine::Message.create :body => , :url => [:url], :message_type => [:message_type], :attachment_ids => , :group_id => [:group_id] end say "Message has been shared" end |
#sync_photos ⇒ Object
128 129 130 131 132 |
# File 'lib/socialcast/command_line/cli.rb', line 128 def sync_photos config = ldap_config Socialcast::CommandLine::ProvisionPhoto.new(config, ).sync end |