telein-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c44c3cceda568525149c516df84adec350ce2979
4
+ data.tar.gz: a4bf9baa84c52e7d43e6b9eecf70f5f2812bb400
5
+ SHA512:
6
+ metadata.gz: 344d0408e0146df2904dab11405e56ce89dc06e7270e09488c606025beb238bb9b508e808decf76c2528f731575dd24dbfc136946c30890b9e84723a91ecaf82
7
+ data.tar.gz: 32200f66888504f448635204ba22e4d2049ece6ff3e77d9ad70c4d65f31c94308b5f9f3fa397df53c9bd359f3292ac3701034c47686966d9a3a4481931c004e5
data/README.md CHANGED
@@ -7,21 +7,27 @@ the Telein API in Ruby.
7
7
 
8
8
  Add this line to your application's Gemfile:
9
9
 
10
- gem 'telein-client', :require => 'telein'
10
+ ```ruby
11
+ gem 'telein-client', :require => 'telein'
12
+ ```
11
13
 
12
14
  Or install it yourself as:
13
15
 
14
- $ gem install telein-client
16
+ ```
17
+ $ gem install telein-client
18
+ ```
15
19
 
16
20
  ## Usage
17
21
 
18
- require 'telein'
22
+ ```ruby
23
+ require 'telein'
19
24
 
20
- # if you do not set this properly, it's going to return 999 responses
21
- Telein.api_key = 'your_api_key'
25
+ # if you do not set this properly, it's going to return 999 responses
26
+ Telein.api_key = 'your_api_key'
22
27
 
23
- client = Telein::Client.new
24
- client.carrier_code_for('(12) 3434-5656') # => 41
28
+ client = Telein::Client.new
29
+ client.carrier_code_for('(12) 3434-5656') # => 41
30
+ ```
25
31
 
26
32
  ## About Telein
27
33
 
@@ -3,22 +3,28 @@ module Telein
3
3
  # The mapping of carrier codes and meanings , in pt-BR
4
4
  # @todo Maybe provide in en-US format
5
5
  CARRIER_CODES = {
6
- 12 => "CTBC",
7
- 14 => "Brasil Telecom",
8
- 20 => "Vivo",
9
- 21 => "Claro",
10
- 23 => "Telemig",
11
- 24 => "Amazonia",
12
- 31 => "Oi",
13
- 37 => "Unicel",
14
- 41 => "TIM",
15
- 43 => "Sercomercio",
16
- 77 => "Nextel",
17
- 98 => "Fixo",
18
- 99 => "Número não encontrado",
19
- 100 => "Número inválido",
20
- 101 => "Erro no servidor",
21
- 990 => "IP blacklisted",
22
- 995 => "IP excedeu 6 consultas/hora nas últimas 24 horas",
23
- 999 => "Chave inválida" }
24
- end
6
+ 12 => 'CTBC',
7
+ 14 => 'Brasil Telecom',
8
+ 20 => 'Vivo',
9
+ 21 => 'Claro',
10
+ 23 => 'Telemig',
11
+ 24 => 'Amazonia',
12
+ 31 => 'Oi',
13
+ 37 => 'Unicel',
14
+ 41 => 'TIM',
15
+ 43 => 'Sercomercio',
16
+ 77 => 'Nextel Rádio',
17
+ 78 => 'Nextel',
18
+ 81 => 'Datora',
19
+ 82 => 'Porto',
20
+ 98 => 'Fixo',
21
+ 99 => 'Número não encontrado',
22
+ 100 => 'Número inválido',
23
+ 101 => 'Erro no servidor',
24
+ 990 => 'IP blacklisted',
25
+ 991 => 'Limite excedido',
26
+ 992 => 'IP sem acesso',
27
+ 994 => 'Chave bloqueada',
28
+ 995 => 'IP excedeu 6 consultas/hora nas últimas 24 horas',
29
+ 999 => 'Chave inválida' }
30
+ end
@@ -51,6 +51,8 @@ module Telein
51
51
  # response parsing (carrier#number)
52
52
  carrier_code, _ = response.split('#')
53
53
 
54
+ return 101 if carrier_code.to_i == 0
55
+
54
56
  return carrier_code.to_i
55
57
  rescue
56
58
  next
@@ -66,4 +68,4 @@ module Telein
66
68
  end
67
69
 
68
70
  end
69
- end
71
+ end
@@ -12,7 +12,9 @@ module Telein
12
12
 
13
13
  # General format of a Brazilian phone.
14
14
  # An area_code and a number that may contain and extra 9
15
- FORMAT = /\A\(?(?<area_code>[1-9][0-9])\)?\s*(?<number>(?<extra_digit>9?)[2-9]\d{3}\-?\d{4})\Z/
15
+ # Valid area codes are ruled by Resolution nº 263 from Anatel:
16
+ # http://legislacao.anatel.gov.br/resolucoes/16-2001/383-resolucao-263
17
+ FORMAT = /\A\(?(?<area_code>[14689][1-9]|[23][12478]|[357][1345]|77|79)\)?\s*(?<number>(((?<extra_digit>9?)\d)|[2-9])\d{3}\-?\d{4})\Z/
16
18
 
17
19
  # @param value [String] a string containing phone information
18
20
  def initialize(value)
@@ -56,12 +58,8 @@ module Telein
56
58
  end
57
59
 
58
60
  # Checks if phone is valid
59
- # This is a loosen check, in the sense that it accepts
60
- # a wide range of probably invalid phones, like
61
- # (99) 9999-9999 but the specs for area codes in Brazil
62
- # are also loosen, allowing the existence of such numbers in the future.
63
- # Also, for phones in the 11 area, the method may return false
64
- # positives, since only cellphones have that extra digit.
61
+ # For phones in the 1[1-9] and 2[1-9] areas, the method may return false
62
+ # positives, since only cellphones have that extra digit as of Q2 of 2014.
65
63
  #
66
64
  # @return [Boolean] whether phone is valid or invalid
67
65
  def valid?
@@ -1,4 +1,4 @@
1
1
  module Telein
2
2
  # Telein version
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -51,4 +51,16 @@ describe Telein::Client do
51
51
  client.carrier_code_for('(12) 9434-5656').should == 101
52
52
  end
53
53
 
54
- end
54
+ it 'returns server error code when carrier code is not present' do
55
+ Telein.servers.each do |server|
56
+ stub_request(:get,server.query_url_for('0000000000')).to_return(:body => '')
57
+ stub_request(:get,server.query_url_for('1234345656')).to_return(:body => '')
58
+ stub_request(:get,server.query_url_for('1294345656')).to_return(:body => '')
59
+ end
60
+
61
+ client = described_class.new
62
+ client.carrier_code_for('(00) 0000-0000').should == 100
63
+ client.carrier_code_for('(12) 3434-5656').should == 101
64
+ client.carrier_code_for('(12) 9434-5656').should == 101
65
+ end
66
+ end
metadata CHANGED
@@ -1,155 +1,138 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telein-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Thiago Brandão Damasceno
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: curb
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.8'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0.8'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0.9'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0.9'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: redcarpet
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: 2.13.0
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: 2.13.0
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rubygems-tasks
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - "~>"
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0.2'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ~>
94
+ - - "~>"
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0.2'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: webmock
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ~>
101
+ - - "~>"
116
102
  - !ruby/object:Gem::Version
117
103
  version: '1.11'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ~>
108
+ - - "~>"
124
109
  - !ruby/object:Gem::Version
125
110
  version: '1.11'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: yard
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ~>
115
+ - - "~>"
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0.8'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ~>
122
+ - - "~>"
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0.8'
142
- description: ! 'The ''telein-client'' gem allows the access for
143
-
144
- the Telein API in Ruby.'
125
+ description: |-
126
+ The 'telein-client' gem allows the access for
127
+ the Telein API in Ruby.
145
128
  email: thiagobrandam@gmail.com
146
129
  executables: []
147
130
  extensions: []
148
131
  extra_rdoc_files: []
149
132
  files:
150
- - .gitignore
151
- - .rspec
152
- - .yardopts
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".yardopts"
153
136
  - Gemfile
154
137
  - LICENSE.txt
155
138
  - README.md
@@ -168,33 +151,26 @@ files:
168
151
  homepage: https://github.com/thiagobrandam/telein-client#readme
169
152
  licenses:
170
153
  - MIT
154
+ metadata: {}
171
155
  post_install_message:
172
156
  rdoc_options: []
173
157
  require_paths:
174
158
  - lib
175
159
  required_ruby_version: !ruby/object:Gem::Requirement
176
- none: false
177
160
  requirements:
178
- - - ! '>='
161
+ - - ">="
179
162
  - !ruby/object:Gem::Version
180
163
  version: '0'
181
- segments:
182
- - 0
183
- hash: 4047080957501176446
184
164
  required_rubygems_version: !ruby/object:Gem::Requirement
185
- none: false
186
165
  requirements:
187
- - - ! '>='
166
+ - - ">="
188
167
  - !ruby/object:Gem::Version
189
168
  version: '0'
190
- segments:
191
- - 0
192
- hash: 4047080957501176446
193
169
  requirements: []
194
170
  rubyforge_project:
195
- rubygems_version: 1.8.25
171
+ rubygems_version: 2.2.2
196
172
  signing_key:
197
- specification_version: 3
173
+ specification_version: 4
198
174
  summary: Client to access Telein API in Ruby
199
175
  test_files:
200
176
  - spec/spec_helper.rb