Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 81 lines (75 sloc) 2.999 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
module Twitter
  class Client
    module Utils
    private

      # Returns the configured screen name or the screen name of the authenticated user
      #
      # @return [String]
      def get_screen_name
        @screen_name ||= self.verify_credentials.screen_name
      end

      # Take a single user ID or screen name and merge it into an options hash with the correct key
      #
      # @param user_id_or_screen_name [Integer, String] A Twitter user ID or screen_name.
      # @param options [Hash] A customizable set of options.
      # @return [Hash]
      def merge_user_into_options!(user_id_or_screen_name, options={})
        case user_id_or_screen_name
        when Fixnum
          options[:user_id] = user_id_or_screen_name
        when String
          options[:screen_name] = user_id_or_screen_name
        end
        options
      end

      # Take a multiple user IDs and screen names and merge them into an options hash with the correct keys
      #
      # @param users_id_or_screen_names [Array] An array of Twitter user IDs or screen_names.
      # @param options [Hash] A customizable set of options.
      # @return [Hash]
      def merge_users_into_options!(user_ids_or_screen_names, options={})
        user_ids, screen_names = [], []
        user_ids_or_screen_names.flatten.each do |user_id_or_screen_name|
          case user_id_or_screen_name
          when Fixnum
            user_ids << user_id_or_screen_name
          when String
            screen_names << user_id_or_screen_name
          end
        end
        options[:user_id] = user_ids.join(',') unless user_ids.empty?
        options[:screen_name] = screen_names.join(',') unless screen_names.empty?
        options
      end

      # Take a single owner ID or owner screen name and merge it into an options hash with the correct key
      # (for Twitter API endpoints that want :owner_id and :owner_screen_name)
      #
      # @param owner_id_or_owner_screen_name [Integer, String] A Twitter user ID or screen_name.
      # @param options [Hash] A customizable set of options.
      # @return [Hash]
      def merge_owner_into_options!(owner_id_or_owner_screen_name, options={})
        case owner_id_or_owner_screen_name
        when Fixnum
          options[:owner_id] = owner_id_or_owner_screen_name
        when String
          options[:owner_screen_name] = owner_id_or_owner_screen_name
        end
        options
      end

      # Take a single list ID or slug and merge it into an options hash with the correct key
      #
      # @param list_id_or_slug [Integer, String] A Twitter list ID or slug.
      # @param options [Hash] A customizable set of options.
      # @return [Hash]
      def merge_list_into_options!(list_id_or_screen_name, options={})
        case list_id_or_screen_name
        when Fixnum
          options[:list_id] = list_id_or_screen_name
        when String
          options[:slug] = list_id_or_screen_name
        end
        options
      end

    end
  end
end
Something went wrong with that request. Please try again.