railsware-telesign 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ module Telesign
2
+ module Exceptions
3
+ class TelesignError < StandardError; end
4
+
5
+ [ :InvalidParameter, :InvalidCustomerID, :InvalidReferenceID,
6
+ :StatusUnavailable, :MaxRetriesReached, :AccountSuspended,
7
+ :SystemUnavailable ].each do |name|
8
+ const_set(name, Class.new(TelesignError))
9
+ end
10
+
11
+ EXCEPTIONAL_ERRORS = {
12
+ -10001 => InvalidParameter,
13
+ -20001 => InvalidCustomerID,
14
+ -20002 => InvalidReferenceID,
15
+ -30001 => AccountSuspended,
16
+ -40001 => StatusUnavailable,
17
+ -50001 => MaxRetriesReached,
18
+ -80001 => SystemUnavailable,
19
+ -90001 => SystemUnavailable
20
+ }
21
+
22
+ def self.raise_if_error(api_error)
23
+ if api_error && EXCEPTIONAL_ERRORS[api_error.code]
24
+ raise EXCEPTIONAL_ERRORS[api_error.code].new(api_error.message)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,67 @@
1
+ module Telesign
2
+ module Language
3
+ ARABIC = "arabic"
4
+ AUSTRALIAN = "australian"
5
+ CANADIAN_FRENCH = "canadianfrench"
6
+ CANTONESE = "cantonese"
7
+ CHINESE = "chinese"
8
+ CROATIAN = "croatian"
9
+ CZECH = "czech"
10
+ DANISH = "danish"
11
+ DUTCH = "dutch"
12
+ EGYPTIAN = "egyptian"
13
+ ENGLISH_UK = "englishuk"
14
+ ESTONIAN = "estonian"
15
+ FINNISH = "finnish"
16
+ FRENCH = "french"
17
+ GERMAN = "german"
18
+ GREEK = "greek"
19
+ HEBREW = "hebrew"
20
+ HINDI = "hindi"
21
+ HUNGARIAN = "hungarian"
22
+ INDONESIAN = "indonesian"
23
+ ITALIAN = "italian"
24
+ JAPANESE = "japanese"
25
+ KOREAN = "korean"
26
+ NORWEGIAN = "norwegian"
27
+ POLISH = "polish"
28
+ PORTUGUESE = "portuguese"
29
+ PORTUGUESE_EU = "portugueseeu"
30
+ ROMANIAN = "romanian"
31
+ RUSSIAN = "russian"
32
+ SLOVAK = "slovak"
33
+ SPANISH = "spanish"
34
+ SPANISH_EU = "spanisheu"
35
+ SWEDISH = "swedish"
36
+ THAI = "thai"
37
+ TURKISH = "turkish"
38
+ UKRAINIAN = "ukrainian"
39
+ VIETNAMESE = "vietnamese"
40
+
41
+ LOCALE_LANGUAGES = {
42
+ :"ar-AR" => ARABIC,
43
+ :"da-DK" => DANISH,
44
+ :"de-DE" => GERMAN,
45
+ :"el-EL" => GREEK,
46
+ :"en-US" => nil,
47
+ :"es-ES" => SPANISH_EU,
48
+ :"es-LA" => SPANISH,
49
+ :"fr-FR" => FRENCH,
50
+ :"it-IT" => ITALIAN,
51
+ :"iw-IW" => HEBREW,
52
+ :"ja-JP" => JAPANESE,
53
+ :"ko-KR" => KOREAN,
54
+ :"nl-NL" => DUTCH,
55
+ :"pl-PL" => POLISH,
56
+ :"pt-BR" => PORTUGUESE,
57
+ :"ru-RU" => RUSSIAN,
58
+ :"sv-SE" => SWEDISH,
59
+ :"tr-TR" => TURKISH,
60
+ :"zh-CN" => CHINESE
61
+ }
62
+
63
+ def self.for_locale(locale)
64
+ LOCALE_LANGUAGES[locale.to_sym]
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ module Telesign
2
+ module PhoneType
3
+
4
+ types = %w(UNDETERMINED FIXED_LINE MOBILE PREPAID_MOBILE TOLL_FREE NON_FIXED_VOIP PAGER PAYPHONE INVALID RESTRICTED PERSONAL VOICEMAIL OTHER)
5
+ types.each do |type|
6
+ const_set(type, type)
7
+ end
8
+
9
+ CODES = {
10
+ 300 => UNDETERMINED,
11
+ 301 => FIXED_LINE,
12
+ 302 => MOBILE,
13
+ 303 => PREPAID_MOBILE,
14
+ 304 => TOLL_FREE,
15
+ 305 => NON_FIXED_VOIP,
16
+ 306 => PAGER,
17
+ 307 => PAYPHONE,
18
+ 308 => INVALID,
19
+ 309 => RESTRICTED,
20
+ 310 => PERSONAL,
21
+ 311 => VOICEMAIL,
22
+ 320 => OTHER
23
+ }
24
+
25
+ def self.type_for_code(code)
26
+ CODES[code.to_i]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Telesign
2
+ class Phone
3
+
4
+ attr_accessor :number, :country_code
5
+
6
+ def initialize(number, country = "US")
7
+ self.number = number
8
+ self.country_code = Country::country_code_for_name(country.to_s)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Telesign
2
+ module PhoneID
3
+ class Request < ApiRequest
4
+
5
+ request_method :requestPhoneID
6
+
7
+ attr_accessor :phone_number, :country_code
8
+
9
+ alias_method :phoneNumber, :phone_number
10
+ alias_method :countryCode, :country_code
11
+
12
+ def initialize(phone)
13
+ self.country_code = phone.country_code
14
+ self.phone_number = phone.number
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'forwardable'
2
+ module Telesign
3
+ module PhoneID
4
+ class Response < ApiResponse
5
+
6
+ response_method :requestPhoneIDResult
7
+
8
+ def_delegators :@response, :city, :county, :zip, :state, :country, :countryName, :timeZone, :latitude, :longitude,
9
+ :aPIError, :cleansedCode, :maxNumLength, :referenceID, :timeZoneUTCMin, :timeZoneUTCMax,
10
+ :primaryMetroCode, :originalPhoneNumber, :cleansedPhoneNumber
11
+
12
+ alias_method :time_zone, :timeZone
13
+ alias_method :api_error, :aPIError
14
+ alias_method :country_name, :countryName
15
+ alias_method :cleansed_code, :cleansedCode
16
+ alias_method :max_num_length, :maxNumLength
17
+ alias_method :reference_id, :referenceID
18
+ alias_method :time_zone_utc_min, :timeZoneUTCMin
19
+ alias_method :time_zone_utc_max, :timeZoneUTCMax
20
+ alias_method :primary_metro_code, :primaryMetroCode
21
+ alias_method :original_phone_number, :originalPhoneNumber
22
+ alias_method :cleansed_phone_number, :cleansedPhoneNumber
23
+
24
+ attr_reader :phone_type
25
+
26
+ def after_initialize
27
+ @phone_type = Telesign::PhoneType.type_for_code(@response.typeofPhone)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Telesign
2
+ module PhoneVerification
3
+ class Request < ApiRequest
4
+
5
+ attr_accessor :country_code, :phone_number, :delay_time, :radial_count,
6
+ :extension_content, :extension_type, :call_type, :caller_id, :priority,
7
+ :message, :project, :additional, :verification_code
8
+
9
+ alias_method :countryCode, :country_code
10
+ alias_method :phoneNumber, :phone_number
11
+ alias_method :delayTime, :delay_time
12
+ alias_method :redialCount, :radial_count
13
+ alias_method :extensionContent, :extension_content
14
+ alias_method :extensionType, :extension_type
15
+ alias_method :callType, :call_type
16
+ alias_method :callerID, :caller_id
17
+ alias_method :verificationCode, :verification_code
18
+
19
+ def initialize(phone)
20
+ self.phone_number = phone.number
21
+ self.country_code = phone.country_code
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Telesign
2
+ module PhoneVerification
3
+ class Response < ApiResponse
4
+
5
+ def_delegators :@response, :aPIError, :referenceID
6
+
7
+ alias_method :api_error, :aPIError
8
+ alias_method :reference_id, :referenceID
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Telesign
2
+ module SMS
3
+ class Request < PhoneVerification::Request
4
+
5
+ request_method :requestSMS
6
+
7
+ def self.message_format=(format)
8
+ define_method(:message) do
9
+ format % verification_code
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module Telesign
2
+ module SMS
3
+ class Response < PhoneVerification::Response
4
+ response_method :requestSMSResult
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Telesign
2
+ module Status
3
+ class Request < ApiRequest
4
+
5
+ request_method :requestSTATUS
6
+
7
+ attr_accessor :reference_id, :verification_code
8
+
9
+ alias_method :referenceID, :reference_id
10
+ alias_method :verificationCode, :verification_code
11
+
12
+ def initialize(reference_id)
13
+ self.reference_id = reference_id
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ module Telesign
2
+ module Status
3
+ class Response < ApiResponse
4
+
5
+ response_method :requestSTATUSResult
6
+
7
+ module StatusCode
8
+ ANSWERED = "100"
9
+ NOT_ANSWERED = "101"
10
+ DISCONNECTED = "102"
11
+ IN_PROGRESS = "103"
12
+ INVALID_PHONE_NUMBER = "104"
13
+ NOT_YET_ATTEMPTED = "105"
14
+ FAILED = "106"
15
+ LINE_BUSY = "107"
16
+ SMS_DELIVERED = "203"
17
+ SMS_NOT_DELIVERED = "207"
18
+ end
19
+
20
+ def_delegators :@response, :aPIError, :referenceID, :statusCode
21
+
22
+ alias_method :api_error, :aPIError
23
+ alias_method :reference_id, :referenceID
24
+ alias_method :status_code, :statusCode
25
+
26
+ def answered?
27
+ [ StatusCode::ANSWERED, StatusCode::SMS_DELIVERED ].include?(status_code)
28
+ end
29
+ alias_method :delivered?, :answered?
30
+
31
+ def verification_code_valid?
32
+ @response.verificationCodeValid == "0"
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railsware-telesign
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - pcunnane
9
+ autorequire: telesign
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-05 00:00:00.000000000 +07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: railsware-soap4r
17
+ requirement: &70328359147360 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.8.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70328359147360
26
+ description:
27
+ email:
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files:
31
+ - README.markdown
32
+ files:
33
+ - MIT-LICENSE
34
+ - lib/telesign.rb
35
+ - lib/telesign/api/default.rb
36
+ - lib/telesign/api/defaultDriver.rb
37
+ - lib/telesign/api/defaultMappingRegistry.rb
38
+ - lib/telesign/call/request.rb
39
+ - lib/telesign/call/response.rb
40
+ - lib/telesign/lib/country.rb
41
+ - lib/telesign/lib/exceptions.rb
42
+ - lib/telesign/lib/language.rb
43
+ - lib/telesign/lib/phone_type.rb
44
+ - lib/telesign/phone_id/request.rb
45
+ - lib/telesign/phone_id/response.rb
46
+ - lib/telesign/phone_verification/request.rb
47
+ - lib/telesign/phone_verification/response.rb
48
+ - lib/telesign/sms/request.rb
49
+ - lib/telesign/sms/response.rb
50
+ - lib/telesign/status/request.rb
51
+ - lib/telesign/status/response.rb
52
+ - lib/telesign/api_request.rb
53
+ - lib/telesign/api_response.rb
54
+ - lib/telesign/phone.rb
55
+ - README.markdown
56
+ has_rdoc: true
57
+ homepage:
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ - lib/telesign
64
+ - lib/telesign/call
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.9.2
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.6.2
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A Telesign Library
83
+ test_files: []