Class: Bvr::PhoneCollection
- Inherits:
-
Object
- Object
- Bvr::PhoneCollection
show all
- Includes:
- Enumerable
- Defined in:
- lib/bvr/phone_collection.rb
Constant Summary
collapse
- API_COMMANDS =
{
add: 'changeuserinfo'
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PhoneCollection.
11
12
13
14
|
# File 'lib/bvr/phone_collection.rb', line 11
def initialize(customer_id)
@collection = []
@customer_id = customer_id
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, arg, &block) ⇒ Object
53
54
55
56
57
|
# File 'lib/bvr/phone_collection.rb', line 53
def method_missing(method, arg, &block)
return super unless self.collection.respond_to? method
self.collection.send(method, arg, &block)
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
9
10
11
|
# File 'lib/bvr/phone_collection.rb', line 9
def collection
@collection
end
|
#customer_id ⇒ Object
Returns the value of attribute customer_id.
9
10
11
|
# File 'lib/bvr/phone_collection.rb', line 9
def customer_id
@customer_id
end
|
Class Method Details
.add(customer_id, phone, add = "add") ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/bvr/phone_collection.rb', line 16
def self.add(customer_id, phone, add="add")
params = {
command: API_COMMANDS[:add],
customer: customer_id,
geocallcli_options: add,
geocallcli: phone
}
Bvr.connection.get(params)
end
|
Instance Method Details
#add(phone) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/bvr/phone_collection.rb', line 27
def add(phone)
return true if self.collection.include? phone
response = Bvr::PhoneCollection.add(self.customer_id, phone.number)
return false unless response['Result'][0] == 'Success'
self.collection << phone
true
end
|
#each(&block) ⇒ Object
37
38
39
|
# File 'lib/bvr/phone_collection.rb', line 37
def each(&block)
@collection.each { |em| block.call(em) }
end
|
#rm(phone) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/bvr/phone_collection.rb', line 41
def rm(phone)
return false unless self.collection.include? phone
response = Bvr::PhoneCollection.add(self.customer_id, phone.number, "delete")
return false unless response['Result'][0] == 'Success'
self.collection.delete phone
true
end
|