voipfone_client 0.0.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec00aae0364688ff1e2c3a8c5965b9d78b952571
4
- data.tar.gz: 61bffd3ac3eb9f92b083256f2d7a8cf505ff6a1c
3
+ metadata.gz: 301fd49404a1148d61c266b3277a9c2095f68c00
4
+ data.tar.gz: 406cbcf01334c54881834c36caa499c5bab12a93
5
5
  SHA512:
6
- metadata.gz: c86c3a9856a801fe831df734b897fbdb7939a2240aeb2d1862b0cb03875254d2b21d3aff4a51740f380b9dc60d8fcb950ebae17232f324deb0232464a22392cd
7
- data.tar.gz: e5d538c38fcdd211f40edce34ea412fea850b7f829565247c525702d8f504113053de7e1954a0340ce1cf4e5cf986c088020053ec37662bcf24ac559eb7e281a
6
+ metadata.gz: f5f3cc00772a9f448bdc10cfbb09ef32bd2b81b2a024fd68c309e01f14a273642275015b7fbf8e8cd3932751da8fa2e7173159bb406d514353f8374f11b02ea3
7
+ data.tar.gz: 19aaea9bc58b10fca0f7a6349dcf08bc29150f8865e1fbab3fd0e023091246f4999f8e3f72e0db4ddda31a0c965da8e2a5374fab9ca9cb1843c101a37c157764
@@ -1,12 +1,7 @@
1
1
  require 'json'
2
2
  require 'mechanize'
3
- require 'voipfone_client/errors'
4
- require 'voipfone_client/client'
5
- require 'voipfone_client/account_balance'
6
- require 'voipfone_client/account_details'
7
- require 'voipfone_client/diverts'
8
- require 'voipfone_client/voicemail'
9
- require 'voipfone_client/sms'
3
+ require 'require_all'
4
+ require_all 'lib/voipfone_client'
10
5
 
11
6
  module VoipfoneClient
12
7
  BASE_URL = "https://www.voipfone.co.uk"
@@ -19,7 +19,6 @@ module VoipfoneClient
19
19
  end
20
20
  end
21
21
 
22
- private
23
22
  # Responses from the private Voipfone API are always in the form ["message", {content}]
24
23
  # We will strip the message (hopefully "OK"), raise if not OK, and return the content.
25
24
  # @param request [JSON] The raw request response from the Voipfone API
@@ -0,0 +1,48 @@
1
+ module VoipfoneClient
2
+ class DivertListItem < Client
3
+ attr_accessor :name, :number
4
+
5
+ # Constructor for `DivertListItem` which accepts the name and number of the phone number to add to the diverts list.
6
+ # @param name [String] the name of the phone to be diverted to
7
+ # @param number [String] the number of the phone to be diverted to.
8
+ def initialize(name: nil, number: nil)
9
+ @name = name
10
+ @number = number
11
+ super()
12
+ end
13
+
14
+ # Add a new number to the list of numbers which can be diverted to. Requires a name
15
+ # and a phone number, which will have spaces stripped from it. May be in international
16
+ # format.
17
+ # @return [Boolean] true on success or a failure message (in which case a `VoipfoneAPIError` will be raised)
18
+ def save
19
+ if @name.nil? || @number.nil?
20
+ raise ArgumentError, "You need to include a name and number to add to the diverts list"
21
+ end
22
+ @number = @number.gsub(" ","")
23
+ parameters = {
24
+ "div-list-name" => @name,
25
+ "div-list-num" => number
26
+ }
27
+ request = @browser.post("#{VoipfoneClient::API_POST_URL}?setDivertsList", parameters)
28
+ response = parse_response(request)
29
+ if response == [@name, @number]
30
+ return true
31
+ else
32
+ raise VoipfoneAPIError, "Although Voipfone returned an OK, the data they stored didn't match what you asked for: #{response}"
33
+ end
34
+ end
35
+
36
+ class << self
37
+ # Get a list of phones which can be diverted to. Returns a nested array of name and phone number.
38
+ # @return [Array] of names and phone numbers
39
+ def all
40
+ d = self.new
41
+ request = d.browser.get("#{VoipfoneClient::API_GET_URL}?divertsCommon")
42
+ d.parse_response(request)["divertsCommon"].collect do |i|
43
+ DivertListItem.new(name: i.first, number: i.last)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ module VoipfoneClient
2
+ # Set up a global (whole-account) divert on your account.
3
+ # You need to specify the type of divert and the number to which the divert will go to.
4
+ # There are 4 supported situations which can be
5
+ # diverted for, namely:
6
+ # - all calls (i.e. no calls will reach the pbx / phones - immediate divert)
7
+ # - when there is a failure in the phone system
8
+ # - when the phone(s) are busy
9
+ # - when there's no answer
10
+ class GlobalDivert < Client
11
+ attr_accessor :type, :number
12
+
13
+ # Constructor for `GlobalDivert` which allows you to pass in a `DivertListItem` to be used as the receiving number.
14
+ # @param divert_list_item [DivertListItem] a `DivertListItem` object which will be used to fill the `GlobalDivert` number.
15
+ # You still need to specify the divert type.
16
+ def initialize(divert_list_item = nil)
17
+ if divert_list_item.is_a?(DivertListItem)
18
+ @number = divert_list_item.number
19
+ end
20
+ super()
21
+ end
22
+
23
+ # A hash of voipfone divert names vs our divert names. Note that when we query
24
+ # voipfone the returned value of the divert type is UPPERCASE.
25
+ VOIPFONE_DIVERT_NAMES = {
26
+ "all" => "all",
27
+ "chanunavail" => "fail",
28
+ "busy" => "busy",
29
+ "noanswer" => "no_answer"
30
+ }
31
+
32
+ #Save the divert on your account
33
+ # @return [Boolean] true on success, or a failure message (in which case a `VoipfoneAPIError` will be raised)
34
+ def save
35
+ if @type.nil? || @number.nil?
36
+ raise ArgumentError, "You need to set a divert type and divert number before you can save the divert."
37
+ end
38
+ set_diverts(@type => @number)
39
+ end
40
+
41
+ #Clear all diverts
42
+ # @return [Boolean] true on success, or a failure message (in which case a `VoipfoneAPIError` will be raised)
43
+ def clear!
44
+ set_diverts()
45
+ end
46
+ class << self
47
+ # Get current diverts
48
+ # @return [Array] A nested set of arrays with divert information for each type of divert currently set
49
+ def all
50
+ g = self.new
51
+ request = g.browser.get("#{VoipfoneClient::API_GET_URL}?divertsMain")
52
+ g.parse_response(request)["divertsMain"].collect do |d|
53
+ divert = GlobalDivert.new
54
+ divert.number = d[1]
55
+ divert.type = VOIPFONE_DIVERT_NAMES[d[2].downcase].to_sym
56
+ divert
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+ # Divert calls for different circumstances. There are 4 supported situations which can be
63
+ # diverted for, namely:
64
+ # - all calls (i.e. no calls will reach the pbx / phones - immediate divert)
65
+ # - when there is a failure in the phone system
66
+ # - when the phone(s) are busy
67
+ # - when there's no answer
68
+ # If no values are passed, all diverts are cleared.
69
+ # @param all [String] The number to which all calls will be diverted.
70
+ # @param fail [String] The number to which calls will be diverted in the event of a failure
71
+ # @param busy [String] The number to which calls will be diverted if the phones are busy
72
+ # @param no_answer [String] The number to which calls will be diverted if there's no answer
73
+ # @return [Boolean] true on success, or a failure message (in which case a `VoipfoneAPIError` will be raised)
74
+ def set_diverts(all: nil, fail: nil, busy: nil, no_answer: nil)
75
+ all ||= ""
76
+ fail ||= ""
77
+ busy ||= ""
78
+ no_answer ||= ""
79
+ parameters = {
80
+ "all" => all.gsub(" ",""),
81
+ "chanunavail" => fail.gsub(" ",""),
82
+ "busy" => busy.gsub(" ",""),
83
+ "noanswer" => no_answer.gsub(" ","")
84
+ }
85
+ request = @browser.post("#{VoipfoneClient::API_POST_URL}?divertsMain", parameters)
86
+ response = parse_response(request)
87
+ if response == "ok"
88
+ return true
89
+ else
90
+ raise VoipfoneAPIError, response.first
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+
97
+
98
+
99
+
100
+
101
+
@@ -0,0 +1,10 @@
1
+ module VoipfoneClient
2
+ class Client
3
+ # Return the phone numbers for this account, as strings
4
+ # @return [Array] Phone numbers as strings.
5
+ def phone_numbers
6
+ request = @browser.get("#{VoipfoneClient::API_GET_URL}?nums")
7
+ parse_response(request)["nums"].collect {|n| n.first}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module VoipfoneClient
2
+ class RegisteredMobile < Client
3
+ attr_accessor :number, :name
4
+
5
+ class << self
6
+ def all
7
+ r = RegisteredMobile.new
8
+ request = r.browser.get("#{VoipfoneClient::API_GET_URL}?registeredMobile")
9
+ r.parse_response(request)["registeredMobile"].collect do |m|
10
+ mobile = RegisteredMobile.new
11
+ mobile.number = m[0]
12
+ mobile.name = m[1]
13
+ mobile
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,25 +1,37 @@
1
- class VoipfoneClient::Client
2
- # Send an sms from your account.
3
- # @param to [String] the phone number to send the SMS to, as a string. Spaces will be stripped; + symbol allowed.
4
- # @param from [String] the phone number to send the SMS from, as a string. Spaces will be stripped; + symbol allowed.
5
- # @param message [String] the message to send. The first 160 characters only will be sent.
6
- def send_sms(to:to, from:from, message:message)
7
- if to.nil? || from.nil? || message.nil?
8
- raise ArgumentError, "You need to include 'to' and 'from' numbers and a message to send an SMS"
1
+ module VoipfoneClient
2
+ class SMS < Client
3
+ attr_accessor :from, :to, :message
4
+
5
+ # Constructor to create an SMS - optionally pass in to, from and message
6
+ # @param to [String] the phone number to send the SMS to, as a string. Spaces will be stripped; + symbol allowed.
7
+ # @param from [String] the phone number to send the SMS from, as a string. Spaces will be stripped; + symbol allowed.
8
+ # @param message [String] the message to send. The first 160 characters only will be sent.
9
+ def initialize(to: nil, from: nil, message: nil)
10
+ @to = to
11
+ @from = from
12
+ @message = message
13
+ super()
9
14
  end
10
- to = to.gsub(" ","")
11
- from = from.gsub(" ","")
12
- parameters = {
13
- "sms-send-to" => to,
14
- "sms-send-from" => from,
15
- "sms-message" => message
16
- }
17
- request = @browser.post("#{VoipfoneClient::API_POST_URL}?smsSend", parameters)
18
- response = parse_response(request)
19
- if response == "ok"
20
- return true
21
- else
22
- raise VoipfoneAPIError, response
15
+
16
+ # Send an sms from your account.
17
+ def send
18
+ if @to.nil? || @from.nil? || @message.nil?
19
+ raise ArgumentError, "You need to include 'to' and 'from' numbers and a message to send an SMS"
20
+ end
21
+ to = @to.gsub(" ","")
22
+ from = @from.gsub(" ","")
23
+ parameters = {
24
+ "sms-send-to" => to,
25
+ "sms-send-from" => from,
26
+ "sms-message" => @message[0..159]
27
+ }
28
+ request = @browser.post("#{VoipfoneClient::API_POST_URL}?smsSend", parameters)
29
+ response = parse_response(request)
30
+ if response == "ok"
31
+ return true
32
+ else
33
+ raise VoipfoneAPIError, response
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -1,3 +1,3 @@
1
1
  module VoipfoneClient
2
- VERSION = "0.0.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "yard", "~> 0.8"
24
24
 
25
25
  spec.add_dependency "mechanize", "~> 2.7"
26
+ spec.add_dependency "require_all", "~> 1.3"
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voipfone_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Error Creative Studio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: require_all
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
69
83
  description: Voipfone are a brilliant SIP provider with loads of features, but no
70
84
  API. This Gem hooks into the API which their web interfaces uses.
71
85
  email:
@@ -85,8 +99,11 @@ files:
85
99
  - lib/voipfone_client/account_balance.rb
86
100
  - lib/voipfone_client/account_details.rb
87
101
  - lib/voipfone_client/client.rb
88
- - lib/voipfone_client/diverts.rb
102
+ - lib/voipfone_client/divert_list_item.rb
89
103
  - lib/voipfone_client/errors.rb
104
+ - lib/voipfone_client/global_divert.rb
105
+ - lib/voipfone_client/phone_numbers.rb
106
+ - lib/voipfone_client/registered_mobile.rb
90
107
  - lib/voipfone_client/sms.rb
91
108
  - lib/voipfone_client/version.rb
92
109
  - lib/voipfone_client/voicemail.rb
@@ -1,79 +0,0 @@
1
- class VoipfoneClient::Client
2
- # Get a list of phones which can be diverted to. Returns a nested array of name and phone number.
3
- # @return [Array] of names and phone numbers
4
- def diverts_list
5
- request = @browser.get("#{VoipfoneClient::API_GET_URL}?divertsCommon")
6
- parse_response(request)["divertsCommon"]
7
- end
8
-
9
- # Add a new number to the list of numbers which can be diverted to. Requires a name
10
- # and a phone number, which will have spaces stripped from it. May be in international
11
- # format.
12
- # @param name [String] The name which appears in dropdowns in the web interface
13
- # @param number [String] The number which will be called. Spaces will be stripped. + symbol accepted
14
- # @return [Boolean] true on success or a failure message (in which case a `VoipfoneAPIError` will be raised)
15
- def add_to_diverts_list(name: nil, number: nil)
16
- if name.nil? || number.nil?
17
- raise ArgumentError, "You need to include a name and number to add to the diverts list"
18
- end
19
- number = number.gsub(" ","")
20
- parameters = {
21
- "div-list-name" => name,
22
- "div-list-num" => number
23
- }
24
- request = @browser.post("#{VoipfoneClient::API_POST_URL}?setDivertsList", parameters)
25
- response = parse_response(request)
26
- if response == [name, number]
27
- return true
28
- else
29
- raise VoipfoneAPIError, "Although Voipfone returned an OK, the data they stored didn't match what you asked for: #{response}"
30
- end
31
- end
32
-
33
-
34
- # Divert calls for different circumstances. There are 4 supported situations which can be
35
- # diverted for, namely:
36
- # - all calls (i.e. no calls will reach the pbx / phones - immediate divert)
37
- # - when there is a failure in the phone system
38
- # - when the phone(s) are busy
39
- # - when there's no answer
40
- # If no values are passed, all diverts are cleared.
41
- # @param all [String] The number to which all calls will be diverted.
42
- # @param fail [String] The number to which calls will be diverted in the event of a failure
43
- # @param busy [String] The number to which calls will be diverted if the phones are busy
44
- # @param no_answer [String] The number to which calls will be diverted if there's no answer
45
- # @return [Boolean] true on success, or a failure message (in which case a `VoipfoneAPIError` will be raised)
46
- def set_diverts(all: nil, fail: nil, busy: nil, no_answer: nil)
47
- all ||= ""
48
- fail ||= ""
49
- busy ||= ""
50
- no_answer ||= ""
51
- parameters = {
52
- "all" => all.gsub(" ",""),
53
- "chanunavail" => fail.gsub(" ",""),
54
- "busy" => busy.gsub(" ",""),
55
- "noanswer" => no_answer.gsub(" ","")
56
- }
57
- request = @browser.post("#{VoipfoneClient::API_POST_URL}?divertsMain", parameters)
58
- response = parse_response(request)
59
- if response == "ok"
60
- return true
61
- else
62
- raise VoipfoneAPIError, response.first
63
- end
64
- end
65
-
66
- # Diverts all calls to the number passed into this method
67
- # @param number [String] The number to be diverted to.
68
- # @return [Boolean] true on success, or an error message (in which case a `VoipfoneAPIError` will be raised)
69
- def divert_all_calls(number: nil)
70
- set_diverts(all: number)
71
- end
72
-
73
- # Get current diverts
74
- # @return [Array] A nested set of arrays with divert information for each type of divert currently set
75
- def get_diverts
76
- request = @browser.get("#{VoipfoneClient::API_GET_URL}?divertsMain")
77
- parse_response(request)["divertsMain"]
78
- end
79
- end