Sha256: f8bbf1d5ac9650351ebd1a1b1380538e9ba36077ff0f5db31a8cf78e0fdd9f7a

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require 't/core_ext/string'
require 't/rcfile'
require 'thor'
require 'twitter'

module T
  class CLI
    class List
      class Add < Thor
        DEFAULT_HOST = 'api.twitter.com'
        DEFAULT_PROTOCOL = 'https'

        check_unknown_options!

        def initialize(*)
          super
          @rcfile = RCFile.instance
        end

        desc "users LIST_NAME SCREEN_NAME [SCREEN_NAME...]", "Add users to a list."
        def users(list_name, screen_name, *screen_names)
          screen_names.unshift(screen_name)
          screen_names.map!{|screen_name| screen_name.strip_at}
          client.list_add_members(list_name, screen_names)
          number = screen_names.length
          say "@#{@rcfile.default_profile[0]} added #{number} #{number == 1 ? 'user' : 'users'} to the list \"#{list_name}\"."
          say
          say "Run `#{$0} list remove users #{list_name} #{screen_names.join(' ')}` to undo."
        end

        desc "all SUBCOMMAND ...ARGS", "Add all users to a list."
        require 't/cli/list/add/all'
        subcommand 'all', CLI::List::Add::All

      private

        def base_url
          "#{protocol}://#{host}"
        end

        def client
          return @client if @client
          @rcfile.path = parent_options['profile'] if parent_options['profile']
          @client = Twitter::Client.new(
            :endpoint => base_url,
            :consumer_key => @rcfile.default_consumer_key,
            :consumer_secret => @rcfile.default_consumer_secret,
            :oauth_token => @rcfile.default_token,
            :oauth_token_secret  => @rcfile.default_secret
          )
        end

        def host
          parent_options['host'] || DEFAULT_HOST
        end

        def protocol
          parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
t-0.2.1 lib/t/cli/list/add.rb
t-0.2.0 lib/t/cli/list/add.rb