kave_rest_api 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kave_rest_api/helpers/convertor.rb +1 -1
- data/lib/kave_rest_api/meaning.rb +24 -24
- data/lib/kave_rest_api/request.rb +1 -1
- data/lib/kave_rest_api/requests/cancel.rb +40 -0
- data/lib/kave_rest_api/requests/countinbox.rb +34 -0
- data/lib/kave_rest_api/requests/countpostalcode.rb +34 -0
- data/lib/kave_rest_api/requests/tts.rb +45 -0
- data/lib/kave_rest_api/respond.rb +1 -1
- data/lib/kave_rest_api/responds/cancel.rb +32 -0
- data/lib/kave_rest_api/responds/countinbox.rb +34 -0
- data/lib/kave_rest_api/responds/countpostalcode.rb +34 -0
- data/lib/kave_rest_api/responds/tts.rb +38 -0
- data/lib/kave_rest_api/version.rb +1 -1
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7a4e79e8b37df1496d9c4d70919cb72950a54b8
|
4
|
+
data.tar.gz: af9a928e4cafa6af2518f0fc4d06af354f4b0f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6483110893abc9e49bea9c10bc922720704f4567339efcd3529c816ad990c790eb25bb8a7a635dd7374bf34579c3c911a9de5c492aa8fad6cbb73cf64a12bb0b
|
7
|
+
data.tar.gz: 0a03289ce6bbfa8cdeb8aa8a4e96e6d03e2b2a6abfc817a23fbc57809383687866cc49a6f1c3431860a55d63a2f2e1ac030fece7dfebf2e183a7d5e895594b35
|
@@ -1,29 +1,29 @@
|
|
1
1
|
module KaveRestApi
|
2
2
|
ERRORS = {
|
3
|
-
'200' => I18n.t("KaveRestApi.200", :default => "
|
4
|
-
'400' =>
|
5
|
-
'401' =>
|
6
|
-
'402' =>
|
7
|
-
'403' =>
|
8
|
-
'404' =>
|
9
|
-
'405' =>
|
10
|
-
'406' =>
|
11
|
-
'407' =>
|
12
|
-
'408' =>
|
13
|
-
'409' =>
|
14
|
-
'411' =>
|
15
|
-
'412' =>
|
16
|
-
'413' =>
|
17
|
-
'414' =>
|
18
|
-
'415' =>
|
19
|
-
'417' =>
|
20
|
-
'418' =>
|
21
|
-
'419' =>
|
22
|
-
'422' =>
|
23
|
-
'424' =>
|
24
|
-
'426' =>
|
25
|
-
'428' =>
|
26
|
-
'431' =>
|
3
|
+
'200' => I18n.t("KaveRestApi.200", :default => "Request Approved"),
|
4
|
+
'400' => I18n.t("KaveRestApi.400", :default => "Argument Error"),
|
5
|
+
'401' => I18n.t("KaveRestApi.401", :default => "Account has been disabled"),
|
6
|
+
'402' => I18n.t("KaveRestApi.402", :default => "Operation failed"),
|
7
|
+
'403' => I18n.t("KaveRestApi.403", :default => "Not a valid API key"),
|
8
|
+
'404' => I18n.t("KaveRestApi.404", :default => "Undeifined method"),
|
9
|
+
'405' => I18n.t("KaveRestApi.405", :default => "Get / Post wrong"),
|
10
|
+
'406' => I18n.t("KaveRestApi.406", :default => "Eequired field"),
|
11
|
+
'407' => I18n.t("KaveRestApi.407", :default => "You don't currently have permission to access this method"),
|
12
|
+
'408' => I18n.t("KaveRestApi.408", :default => "fallback text"),
|
13
|
+
'409' => I18n.t("KaveRestApi.409", :default => "Server not able to respond"),
|
14
|
+
'411' => I18n.t("KaveRestApi.411", :default => "Not a valid receptor"),
|
15
|
+
'412' => I18n.t("KaveRestApi.412", :default => "Not a valid sender"),
|
16
|
+
'413' => I18n.t("KaveRestApi.413", :default => "Message is invalid"),
|
17
|
+
'414' => I18n.t("KaveRestApi.414", :default => "Request is limit"),
|
18
|
+
'415' => I18n.t("KaveRestApi.415", :default => "fallback text"),
|
19
|
+
'417' => I18n.t("KaveRestApi.417", :default => "Not a valid UnixTime"),
|
20
|
+
'418' => I18n.t("KaveRestApi.418", :default => "Your credit is not enough"),
|
21
|
+
'419' => I18n.t("KaveRestApi.419", :default => "fallback text"),
|
22
|
+
'422' => I18n.t("KaveRestApi.422", :default => "fallback text"),
|
23
|
+
'424' => I18n.t("KaveRestApi.424", :default => "Template not found"),
|
24
|
+
'426' => I18n.t("KaveRestApi.426", :default => "fallback text"),
|
25
|
+
'428' => I18n.t("KaveRestApi.428", :default => "fallback text"),
|
26
|
+
'431' => I18n.t("KaveRestApi.431", :default => "fallback text"),
|
27
27
|
}
|
28
28
|
|
29
29
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module KaveRestApi
|
2
2
|
|
3
|
-
self.require_libs './requests','RequestBase','send','deliver','latestoutbox','selectoutbox','info','config','receive','lookup'
|
3
|
+
self.require_libs './requests','RequestBase','tts','send','deliver','latestoutbox','selectoutbox','info','config','receive','lookup','countinbox','cancel','countpostalcode'
|
4
4
|
|
5
5
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Cancel < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :messageid
|
6
|
+
attr_reader :response
|
7
|
+
validates_presence_of :messageid
|
8
|
+
|
9
|
+
validates_format_of :messageid, :with => /^\d*$/, :if => Proc.new { !messageid.nil? }
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:countinbox,@FORMAT].join('.').freeze
|
15
|
+
@messageid = args.fetch(:messageid)
|
16
|
+
if @messageid.kind_of?(Array)
|
17
|
+
@valid= false if @messageid.length > 200
|
18
|
+
@messageid = @messageid.join(',')
|
19
|
+
end
|
20
|
+
@messageid = @messageid.ctsd
|
21
|
+
|
22
|
+
@response = ResponseCancel.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
@valid ||= true
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
connection = Faraday.new(url: "#{API_URL}/sms/") do |faraday|
|
31
|
+
faraday.adapter Faraday.default_adapter
|
32
|
+
faraday.response FORMAT.to_sym
|
33
|
+
end
|
34
|
+
response = connection.get(ACTION_NAME,isread: @isread, linenumber: @linenumber,startdate: @startdate,enddate: @enddate)
|
35
|
+
@response.validate(response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class CountInBox < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :startdate,:linenumber,:enddate
|
6
|
+
attr_reader :response
|
7
|
+
validates_presence_of :startdate
|
8
|
+
validates_presence_of :linenumber
|
9
|
+
validates_format_of :linenumber, :with => /^\d*$/, :if => Proc.new { !linenumber.nil? }
|
10
|
+
validates_format_of :startdate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
11
|
+
validates_format_of :enddate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
12
|
+
|
13
|
+
def initialize(args = {})
|
14
|
+
super
|
15
|
+
@ACTION_NAME = [:countinbox,@FORMAT].join('.').freeze
|
16
|
+
@startdate = args.fetch(:startdate)
|
17
|
+
@enddate = args.fetch(:enddate,nil)
|
18
|
+
@linenumber = args.fetch(:linenumber,nil)
|
19
|
+
@isread = args.fetch(:isread,nil)
|
20
|
+
@response = ResponseCountInBox.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
connection = Faraday.new(url: "#{API_URL}/sms/") do |faraday|
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
faraday.response FORMAT.to_sym
|
27
|
+
end
|
28
|
+
response = connection.get(ACTION_NAME,isread: @isread, linenumber: @linenumber,startdate: @startdate,enddate: @enddate)
|
29
|
+
@response.validate(response.body)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class CountPostalCode < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :postalcode
|
6
|
+
attr_reader :response
|
7
|
+
validates_presence_of :postalcode
|
8
|
+
|
9
|
+
validates_format_of :postalcode, :with => /^\d*$/, :if => Proc.new { !messageid.nil? }
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:countpostalcode,@FORMAT].join('.').freeze
|
15
|
+
@postalcode = args.fetch(:postalcode)
|
16
|
+
@postalcode = @postalcode.ctsd
|
17
|
+
|
18
|
+
@response = ResponseCountPostalCode.new
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def call
|
24
|
+
connection = Faraday.new(url: "#{API_URL}/sms/") do |faraday|
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
faraday.response FORMAT.to_sym
|
27
|
+
end
|
28
|
+
response = connection.get(ACTION_NAME,countpostalcode: @countpostalcode)
|
29
|
+
@response.validate(response.body)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Tts < KaveRestApi::RequestBase
|
3
|
+
include Validatable
|
4
|
+
attr_accessor :receptor, :message,:date,:localid,:repeat
|
5
|
+
attr_reader :response,:message,:config,:status,:statustext,:sender,:receptor,:date,:cost
|
6
|
+
validates_presence_of :message
|
7
|
+
validates_presence_of :receptor
|
8
|
+
validates_length_of :message, :within => 1..500
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:maketts,@FORMAT].join('.').freeze
|
15
|
+
@receptor = args.fetch(:receptor)
|
16
|
+
if @receptor.kind_of?(Array)
|
17
|
+
@valid_receptor= false if @receptor.length > 200
|
18
|
+
@receptor = @receptor.join(',')
|
19
|
+
end
|
20
|
+
@receptor = @receptor.ctsd
|
21
|
+
@date = args.fetch(:date,nil)
|
22
|
+
@message = args.fetch(:message)
|
23
|
+
@message = @message.ctsd if args.fetch(:standard_digit,false)
|
24
|
+
@repeat = args.fetch(:repeat,nil)
|
25
|
+
@localid = args.fetch(:localid,nil)
|
26
|
+
@response = ResponseSendSimple.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_receptor?
|
30
|
+
@valid_receptor
|
31
|
+
end
|
32
|
+
|
33
|
+
def call
|
34
|
+
connection = Faraday.new(url: "#{@API_URL}/call/") do |faraday|
|
35
|
+
faraday.adapter Faraday.default_adapter
|
36
|
+
faraday.response @FORMAT.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
response = connection.get(@ACTION_NAME, receptor: @receptor , message: @message,localid: @localid,date: @date,repeat: @repeat)
|
40
|
+
@response.validate(response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module KaveRestApi
|
2
|
-
self.require_libs './responds','send','deliver','latestoutbox','selectoutbox','info','config','receive','lookup'
|
2
|
+
self.require_libs './responds','tts','send','deliver','latestoutbox','selectoutbox','info','config','receive','lookup','countinbox','cancel','countpostalcode'
|
3
3
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseCancel
|
3
|
+
attr_reader :response, :status,:statusmessage
|
4
|
+
|
5
|
+
def validate(response = nil)
|
6
|
+
@response = response
|
7
|
+
perform_validation
|
8
|
+
return self
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
@valid
|
13
|
+
end
|
14
|
+
|
15
|
+
def entries
|
16
|
+
return @response['entries']
|
17
|
+
end
|
18
|
+
|
19
|
+
def full_message_errors
|
20
|
+
return KaveRestApi::ERRORS[@response['return']['status'].to_s]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def perform_validation
|
26
|
+
raise ArgumentError, 'not a valid response' if @response.nil?
|
27
|
+
@valid = (@response['return']['status'] == 200)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseCountInBox
|
3
|
+
attr_reader :response, :status,:statusmessage
|
4
|
+
attr_accessor :apilogs,:dailyreport,:debugmode,:defaultsender,:mincreditalarm,:resendfailed
|
5
|
+
|
6
|
+
def validate(response = nil)
|
7
|
+
@response = response
|
8
|
+
perform_validation
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
@valid
|
14
|
+
end
|
15
|
+
|
16
|
+
def entries
|
17
|
+
return @response['entries']
|
18
|
+
end
|
19
|
+
|
20
|
+
def full_message_errors
|
21
|
+
return KaveRestApi::ERRORS[@response['return']['status'].to_s]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def perform_validation
|
27
|
+
raise ArgumentError, 'not a valid response' if @response.nil?
|
28
|
+
@valid = (@response['return']['status'] == 200)
|
29
|
+
@response['entries'].each { |key, value| send("#{key}=", value) }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseCountPostalCode
|
3
|
+
attr_reader :response, :status,:statusmessage
|
4
|
+
attr_accessor :section,:value
|
5
|
+
|
6
|
+
def validate(response = nil)
|
7
|
+
@response = response
|
8
|
+
perform_validation
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
@valid
|
14
|
+
end
|
15
|
+
|
16
|
+
def entries
|
17
|
+
return @response['entries']
|
18
|
+
end
|
19
|
+
|
20
|
+
def full_message_errors
|
21
|
+
return KaveRestApi::ERRORS[@response['return']['status'].to_s]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def perform_validation
|
27
|
+
raise ArgumentError, 'not a valid response' if @response.nil?
|
28
|
+
@valid = (@response['return']['status'] == 200)
|
29
|
+
@response['entries'].each { |key, value| send("#{key}=", value) }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseTts
|
3
|
+
attr_reader :response, :status,:statustext
|
4
|
+
|
5
|
+
def validate(response = nil)
|
6
|
+
@response = response
|
7
|
+
perform_validation
|
8
|
+
return self
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
@valid
|
13
|
+
end
|
14
|
+
|
15
|
+
def entries(select=nil)
|
16
|
+
if select.nil?
|
17
|
+
return @response['entries']
|
18
|
+
else
|
19
|
+
return @response['entries'].select { |entry|
|
20
|
+
entry['status'] == (KaveRestApi::ENTRIES[select].nil? ? select:KaveRestApi::ENTRIES[select])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def full_message_errors
|
26
|
+
return KaveRestApi::ERRORS[@response['return']['message'].to_s]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def perform_validation
|
32
|
+
raise ArgumentError, 'not a valid response' if @response.nil?
|
33
|
+
@valid = (@response['return']['status'] == 200)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kave_rest_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mohammad mahmoudi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -155,7 +155,10 @@ files:
|
|
155
155
|
- lib/kave_rest_api/meaning.rb
|
156
156
|
- lib/kave_rest_api/request.rb
|
157
157
|
- lib/kave_rest_api/requests/RequestBase.rb
|
158
|
+
- lib/kave_rest_api/requests/cancel.rb
|
158
159
|
- lib/kave_rest_api/requests/config.rb
|
160
|
+
- lib/kave_rest_api/requests/countinbox.rb
|
161
|
+
- lib/kave_rest_api/requests/countpostalcode.rb
|
159
162
|
- lib/kave_rest_api/requests/deliver.rb
|
160
163
|
- lib/kave_rest_api/requests/info.rb
|
161
164
|
- lib/kave_rest_api/requests/latestoutbox.rb
|
@@ -163,8 +166,12 @@ files:
|
|
163
166
|
- lib/kave_rest_api/requests/receive.rb
|
164
167
|
- lib/kave_rest_api/requests/selectoutbox.rb
|
165
168
|
- lib/kave_rest_api/requests/send.rb
|
169
|
+
- lib/kave_rest_api/requests/tts.rb
|
166
170
|
- lib/kave_rest_api/respond.rb
|
171
|
+
- lib/kave_rest_api/responds/cancel.rb
|
167
172
|
- lib/kave_rest_api/responds/config.rb
|
173
|
+
- lib/kave_rest_api/responds/countinbox.rb
|
174
|
+
- lib/kave_rest_api/responds/countpostalcode.rb
|
168
175
|
- lib/kave_rest_api/responds/deliver.rb
|
169
176
|
- lib/kave_rest_api/responds/info.rb
|
170
177
|
- lib/kave_rest_api/responds/latestoutbox.rb
|
@@ -172,6 +179,7 @@ files:
|
|
172
179
|
- lib/kave_rest_api/responds/receive.rb
|
173
180
|
- lib/kave_rest_api/responds/selectoutbox.rb
|
174
181
|
- lib/kave_rest_api/responds/send.rb
|
182
|
+
- lib/kave_rest_api/responds/tts.rb
|
175
183
|
- lib/kave_rest_api/version.rb
|
176
184
|
homepage: https://github.com/mm580486/kave_rest_api/
|
177
185
|
licenses:
|
@@ -193,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
201
|
version: '0'
|
194
202
|
requirements: []
|
195
203
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
204
|
+
rubygems_version: 2.6.11
|
197
205
|
signing_key:
|
198
206
|
specification_version: 4
|
199
207
|
summary: Ruby gem to send and receive SMS via kavenegar API(rest)
|