Sha256: 096d202bb3803c4f8ddd0f5897e280f3f8bba18d0a15423c3619c32186dffb8a

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

module BungieClient::Wrappers
  class User < Default
    attr_reader :membership_type, :display_name

    # Initialize wrapper with user's preset
    #
    # @note maybe add the `destiny_membership_id` as an alternative to `display_name`
    #
    # @option options [Integer] :membership_type Platform type number (xbox - 1, playstation - 2, all - 256)
    # @option options [String] :display_name Simple user name
    def initialize(options)
      super

      # set membershipType
      if %w(1 2 256).include? options[:membership_type].to_s
        @membership_type = options[:membership_type].to_s
      else
        @membership_type = '256'
      end

      # set displayName
      if options[:display_name].is_a? String
        @display_name = options[:display_name]
      else
        raise 'You must set user display name'
      end
    end

    # Get DestinyMembershipId of selected user
    def destiny_membership_id
      return @destiny_membership_id unless @destiny_membership_id.nil?

      @destiny_membership_id = call_service(
        'get_membership_id_by_display_name',
        {
          :displayName =>  @display_name,
          :membershipType => @membership_type
        }
      )
    end

    def fill_url(url, params)
      params = {} unless params.is_a? Hash

      params[:displayName] = @display_name
      params[:membershipType] = @membership_type
      params[:destinyMembershipId] = destiny_membership_id if url.include? '{destinyMembershipId}'
      params[:membershipId] = destiny_membership_id if url.include? '{membershipId}'

      super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bungie_client-1.1.0 lib/bungie_client/wrappers/user.rb
bungie_client-1.0.3 lib/bungie_client/wrappers/user.rb
bungie_client-1.0.2 lib/bungie_client/wrappers/user.rb
bungie_client-1.0.0 lib/bungie_client/wrappers/user.rb