esendex4soap 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
data/esendex4soap.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "esendex4soap"
8
- s.version = "0.6.1"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Voip Scout"]
data/lib/esendex4soap.rb CHANGED
@@ -1,9 +1,45 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'savon'
3
3
  require 'log4r'
4
- require 'wtf_lang'
4
+ #require 'wtf_lang'
5
+ require 'api_smith'
6
+
7
+ module LanguageTools
8
+ class DetectLanguageDotCom
9
+ include APISmith::Client
10
+ base_uri "http://ws.detectlanguage.com"
11
+ endpoint "0.2"
12
+
13
+ def initialize(api_key)
14
+ @api_key = api_key
15
+ add_query_options! :key => @api_key
16
+ end
17
+
18
+ def detect(text)
19
+ (post "detect", :extra_query => {:q => text})["data"]["detections"].first["language"]
20
+ end
21
+
22
+ end
23
+
24
+ class AlchemyLanguage
25
+ include APISmith::Client
26
+ base_uri "http://access.alchemyapi.com/"
27
+ endpoint "calls/text"
28
+
29
+ def initialize(api_key)
30
+ @api_key = api_key
31
+ add_query_options! :outputMode => 'json', :apikey => @api_key
32
+ end
33
+
34
+ def detect(text)
35
+ (post "TextGetLanguage", :extra_query => {:text => text})["language"]
36
+ end
37
+ end
38
+
39
+ end
5
40
 
6
41
  module Esendex
42
+
7
43
  class Client
8
44
  include Log4r
9
45
  INBOX_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/InboxService.asmx?wsdl'
@@ -17,8 +53,11 @@ module Esendex
17
53
  @username = args.shift
18
54
  @password = args.shift
19
55
  @account_reference = args.shift
56
+ # @detectlanguage_api_key, @alchemyapi_api_key = args.shift, args.shift
20
57
  @sent_message_ids, @sent_message_statuses = [], {}
21
58
 
59
+ @language = LanguageTools::DetectLanguageDotCom.new(args.shift)
60
+
22
61
  Savon.configure do |config|
23
62
  config.raise_errors = true
24
63
  config.log = false
@@ -28,24 +67,24 @@ module Esendex
28
67
 
29
68
  @log = Logger.new "#{self.class.name}"
30
69
  @log.outputters = Outputter.stdout
31
- @log.level = ERROR
70
+ @log.level = DEBUG #ERROR
32
71
 
33
72
  @message_kind = String.new
34
73
 
35
74
  end
36
75
 
37
76
  def send_message(recipient, text, originator, validityperiod)
38
- @log.debug "TO:#{recipient} text size:#{text.size} in #{text.full_lang} language"
77
+ @log.debug "TO:#{recipient} text size:#{text.size} in #{@language.detect(text)} language"
39
78
  #TODO: handle other languages as well
40
- unless text.full_lang == 'russian'
41
- sms_parts = text.scan(/.{610}/mu)
42
- sms_parts << text[sms_parts.to_s.size..text.size]
79
+ unless @language.detect(text) == 'ru'
80
+ sms_parts = text.scan(/.{1,160}/mu)
81
+ @log.debug "#{text[sms_parts.to_s.size..text.size]}"
43
82
  @message_kind = 'Text'
44
83
  @log.debug "#{@message_kind}:#{text.scan(/./mu)} = #{text.size}. #{sms_parts.size} part/s."
45
84
  sms(recipient, sms_parts, originator, validityperiod)
46
85
  else
47
- sms_parts = text.scan(/.{70}/mu)
48
- sms_parts << text[sms_parts.to_s.size..text.size]
86
+ sms_parts = text.scan(/.{1,70}/mu)
87
+ @log.debug "#{text[sms_parts.to_s.size..text.size]}"
49
88
  @message_kind = 'Unicode'
50
89
  @log.debug "#{@message_kind}:#{text.scan(/./mu)} != #{text.size}. #{sms_parts.size} part/s."
51
90
  sms(recipient, sms_parts, originator, validityperiod)
@@ -120,5 +159,5 @@ module Esendex
120
159
 
121
160
  end #module Esendex
122
161
 
123
- #sms = Esendex::Client.new 'username', 'password', 'account_reference', 'from', 'expire int hours'
124
- #sms.send_message 'PHONENUMBER', 'message in any language'
162
+ #sms = Esendex::Client.new 'username', 'password', 'account_reference', 'api_key for detectlanguage'
163
+ #sms.send_message 'PHONENUMBER', 'message in any language', 'FROM', 'expire int hours'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: esendex4soap
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.1
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Voip Scout