Sha256: 0f05e560642c735c5f0055f40d520dbc9357bc66a8f4587e43546f0d7ab4268b

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

module Sorenson
  module Services
    class Account < Base
      attr_accessor :rate_plan, :username, :status, :customer_id, :id, :rate_plan_expiration_date, :date_last_modified, 
                    :last_login_time, :date_retrieved, :total_asset_count, :token
      
      def self.login(username, password)
        account = Account.new(JSON.parse(login_no_resource(username, password)))
        self.account_token  = account.token
        self.account_id     = account.id
        return account if account.token
      end
      
      # Get Accout
      def self.get_account
        new(get_from("/accounts/#{account_id}"))
      end
      
      def rate_plan
        RatePlan.new(Base.get_from("/accounts/#{account_id}/rate_plan"))
      end
      
      def overage_action
        Base.get_from("/accounts/#{account_id}/overage_action")["overage_action"]
      end
      
      def set_password(password, old_password)
        Base.put_to("/accounts/#{account_id}", :account => {:password => password, :old_password => old_password})[:status]
      end
      
      def empty_trash
        Base.post_to("/accounts/#{account_id}/empty_trash")['status']
      end
      
      def initialize(data)
        self.username                  = data['username']
        self.status                    = data['status']
        self.customer_id               = data['id']
        self.id                        = data['id']
        self.rate_plan_expiration_date = data['rate_plan_expiration_date']
        self.date_last_modified        = data['date_last_modified']
        self.last_login_time           = data['last_login_time']
        self.date_retrieved            = data['date_retrieved']
        self.total_asset_count         = data['total_asset_count']
        self.token                     = data['token']
        self.id                        = data['account_id'] if data['account_id']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
360_services-0.0.1 lib/sorenson/services/account.rb