comcetera 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,10 @@
1
1
  = comcetera
2
2
 
3
- First stab at a simple class that wraps the Comcetera mobile operator detection service. Give them a msisdn, they give you an operator code. Compile your own list of relevant codes based on wikipedia.
3
+ A simple wrapper for the NumberPortabilityLookup service of Comcetera. Give them a msisdn and they (usually) give you an operator code. Compile your own list of relevant codes based on wikipedia.
4
4
 
5
- I'm scratching my own itch here, so I'm only adding what I use. Feedback and patches are welcome
5
+ I'm scratching my own itch here, so I'm only adding what I use. Feedback and patches are welcome.
6
+
7
+ For more info about the service, take a look at: http://numberportabilitylookup.com/
6
8
 
7
9
  == Example
8
10
 
@@ -11,17 +13,21 @@ The usual way you'd do a lookup
11
13
  Comcetera.username = "meeeeee"
12
14
  Comcetera.password = "verysecret"
13
15
  comcetera = Comcetera.detect(31612345678)
14
- comcetera.operator_code # => "T-Mobile"
16
+ comcetera.operator_code # => "20415"
15
17
  comcetera.msisdn # => "31612345678"
16
18
 
17
19
  When the lookup does not work due to a timeout
20
+
18
21
  Comcetera.detect(31612345678) # => nil
19
22
 
20
- When the lookup gives a result, but not what you'd expect
23
+ This means that the amount of retries specified as Comcetera.retries have all timed out after Comcetera.timeout seconds. You can retry at a later time or do something else. This is great if, as is my use case, the lookup is used as a type of pre-selection for numbers.
24
+
25
+ The API can return a couple of errors. In this case, there is no operator code, but an error code and the full response as debug info.
21
26
 
22
27
  comcetera = Comcetera.detect(31612345678)
23
- comcetera.error_code # => "ERR21"
24
- comcetera.debug # => "QUERYOK\n31612345678 ERR21\nENDBATCH"
28
+ comcetera.operator_code # => nil
29
+ comcetera.error_code # => "ERR21"
30
+ comcetera.debug # => "QUERYOK\n31612345678 ERR21\nENDBATCH"
25
31
 
26
32
  == Operator codes
27
33
 
@@ -39,6 +45,11 @@ Example: Wikipedia mentions T-Mobile in the Netherlands as: MCC 204, MNC 16. Com
39
45
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
40
46
  * Send me a pull request. Bonus points for topic branches.
41
47
 
48
+ == Contributors
49
+
50
+ * Wes 'Narnach' Oldenbeuving
51
+ * Gerard 'smeevil' de Brieder
52
+
42
53
  == Copyright
43
54
 
44
55
  Copyright (c) 2010 Wes Oldenbeuving. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.1
@@ -2,8 +2,17 @@ require 'open-uri'
2
2
  require 'timeout'
3
3
 
4
4
  class Comcetera
5
+ ERROR_CODES={
6
+ "1"=>"Unknown subscriber",
7
+ "29"=>"Absent subscriber",
8
+ "21"=>"Facility not supported",
9
+ "11"=>"Teleserice not provisioned",
10
+ "13"=>"Call barred",
11
+ "36"=>"System Failure"
12
+ }
13
+
5
14
  attr_accessor :operator_code, :msisdn
6
- attr_accessor :error_code, :debug
15
+ attr_accessor :error_code, :error_message, :debug
7
16
 
8
17
  def initialize(attributes={})
9
18
  attributes.each do |key, value|
@@ -21,7 +30,7 @@ class Comcetera
21
30
  def retries
22
31
  @retries ||= 2
23
32
  end
24
-
33
+
25
34
  def password
26
35
  @password || raise("No password set for Comcetera")
27
36
  end
@@ -39,10 +48,10 @@ class Comcetera
39
48
  Timeout::timeout(self.timeout) do
40
49
  body=open("http://api.comcetera.com/npl?user=#{self.username}&pass=#{self.password}&msisdn=#{msisdn}").read
41
50
  msisdn, operator_code = body.split("\n")[1].split(" ") # 2nd line, last word is the operator hexcode
42
- unless operator_code.to_s =~ /ERR\d+/
51
+ unless operator_code.to_s =~ /ERR(\d+)/
43
52
  return new(:operator_code => operator_code, :msisdn => msisdn)
44
53
  else
45
- return new(:operator_code => nil, :msisdn => msisdn, :error_code=>operator_code, :debug=>body)
54
+ return new(:operator_code => nil, :msisdn => msisdn, :error_code=>operator_code, :error_message=>ERROR_CODES[$1]||"Unknown Error", :debug=>body)
46
55
  end
47
56
  end
48
57
  rescue Timeout::Error, SystemCallError => e
@@ -47,6 +47,7 @@ describe "Comcetera" do
47
47
  @comcetera = Comcetera.detect(31612345621)
48
48
  @comcetera.operator_code.should be_nil
49
49
  @comcetera.error_code.should == "ERR21"
50
+ @comcetera.error_message.should == "Facility not supported"
50
51
  @comcetera.debug.should == <<-MSG
51
52
  QUERYOK
52
53
  31612345621 ERR21
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comcetera
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Wes Oldenbeuving
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 +02:00
18
+ date: 2010-09-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency