Class: Bvr::CallCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/bvr/call_collection.rb

Constant Summary collapse

VALID_OPTIONS =

Valid Options:

Variable  Value Option  Description
command calloverview  Mandatory
username  X..140  Mandatory the username of the reseller
password  X..100  Mandatory the password of the reseller
customer  X..140  Mandatory the username of the customer
date  YYYY-MM-DD hh:nn:ss Optional  the datetime from which to start retrieving the history, current datetime is default
callid  N..1000000  Optional  the callid from which to start retrieving the history, 0 is default
recordcount 1 - 500 Optional  the maximum number of records returned, 10 is default, 500 is maximum
direction forward / backward  Optional  the direction to search, backward is default
[:date, :callid, :recordcount, :direction, :customer, :command]
API_COMMANDS =
{
  find_by_customer_id: 'calloverview'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



18
19
20
# File 'lib/bvr/call_collection.rb', line 18

def collection
  @collection
end

#query_paramsObject

Returns the value of attribute query_params.



18
19
20
# File 'lib/bvr/call_collection.rb', line 18

def query_params
  @query_params
end

#raw_countObject

Returns the value of attribute raw_count.



18
19
20
# File 'lib/bvr/call_collection.rb', line 18

def raw_count
  @raw_count
end

#raw_more_dataObject

Returns the value of attribute raw_more_data.



18
19
20
# File 'lib/bvr/call_collection.rb', line 18

def raw_more_data
  @raw_more_data
end

Class Method Details

.find_by_customer_id(customer_id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bvr/call_collection.rb', line 20

def self.find_by_customer_id(customer_id, options={})
  raise ArgumentError.new('Unknown Argument') unless self.valid_options?(options)


  params = {
    command: API_COMMANDS[:find_by_customer_id],
    customer: customer_id
  }

  response = Bvr.connection.get(params.merge(options))

  return [] if response['Calls'].nil?

  self.new_from_response(response).tap do |call_collection|
    call_collection.query_params = options
  end
end

.new_from_response(h) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/bvr/call_collection.rb', line 38

def self.new_from_response(h)
  self.new.tap do |calls_collection|
    calls_collection.raw_more_data  = h['MoreData']
    calls_collection.raw_count = h['Calls']['Count']
    calls_collection.collection = h['Calls']['Call'].each_with_object([]) do |callH, array|
      array << Call.new_from_response(callH)
    end
  end
end

Instance Method Details

#countObject



48
49
50
# File 'lib/bvr/call_collection.rb', line 48

def count
  Integer(self.raw_count)
end

#next?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/bvr/call_collection.rb', line 52

def next?
  self.raw_more_data == 'True'
end