kave_rest_api 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/generators/kave_rest_api/install_generator.rb +18 -0
- data/lib/generators/templates/kave_rest_api_initializer.rb +18 -0
- data/lib/kave_rest_api.rb +39 -0
- data/lib/kave_rest_api/core.rb +11 -0
- data/lib/kave_rest_api/helper.rb +3 -0
- data/lib/kave_rest_api/helpers/convertor.rb +39 -0
- data/lib/kave_rest_api/helpers/validator.rb +31 -0
- data/lib/kave_rest_api/meaning.rb +42 -0
- data/lib/kave_rest_api/request.rb +5 -0
- data/lib/kave_rest_api/requests/RequestBase.rb +11 -0
- data/lib/kave_rest_api/requests/config.rb +41 -0
- data/lib/kave_rest_api/requests/deliver.rb +32 -0
- data/lib/kave_rest_api/requests/info.rb +19 -0
- data/lib/kave_rest_api/requests/latestoutbox.rb +28 -0
- data/lib/kave_rest_api/requests/lookup.rb +45 -0
- data/lib/kave_rest_api/requests/receive.rb +29 -0
- data/lib/kave_rest_api/requests/selectoutbox.rb +32 -0
- data/lib/kave_rest_api/requests/send.rb +54 -0
- data/lib/kave_rest_api/respond.rb +3 -0
- data/lib/kave_rest_api/responds/config.rb +34 -0
- data/lib/kave_rest_api/responds/deliver.rb +38 -0
- data/lib/kave_rest_api/responds/info.rb +32 -0
- data/lib/kave_rest_api/responds/latestoutbox.rb +38 -0
- data/lib/kave_rest_api/responds/lookup.rb +38 -0
- data/lib/kave_rest_api/responds/receive.rb +38 -0
- data/lib/kave_rest_api/responds/selectoutbox.rb +38 -0
- data/lib/kave_rest_api/responds/send.rb +38 -0
- data/lib/kave_rest_api/version.rb +3 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35085d98be9a761d0ff0207a7708ae86d947f20e
|
4
|
+
data.tar.gz: 1e6086482e28cd0cd1e156e13995961a3d4a766b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab068e20fb83f83520314f83eaa711c2fe980512b0764ec66b597ff1a3b5ca37e40c4459c8a01ac468fbb3bda9db68e0e748fe5ea9e2060597a8014e9b612d03
|
7
|
+
data.tar.gz: fa3876760c5e783ccb728ae1aa274bd4f01525e2d4ea6f3b4b6713472c853e9db51ec86921632820e6edfe345a2252e979f2d3492f5c8434f289585b2659d47f
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
desc "Creates KaveRestApi initializer for your application"
|
6
|
+
|
7
|
+
def copy_initializer
|
8
|
+
template "kave_rest_api_initializer.rb", "config/initializers/kave_rest_api.rb"
|
9
|
+
|
10
|
+
puts <<~EOF
|
11
|
+
\e[36mInstall complete 👻 \e[0m
|
12
|
+
For report issues or suggest feature contact me on twitter/github: \e[32m@mm580486\e[0m
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
KaveRestApi.configure do |config|
|
2
|
+
|
3
|
+
# To completely ignore debug mode events(No Errors) uncomment this line *optional
|
4
|
+
# config.debugmode = false #by default it's true
|
5
|
+
|
6
|
+
# It is recommended that you pull your API keys from environment settings. *required
|
7
|
+
config.api_key = 'XXXX-XXXX-XXXX-XXXX'
|
8
|
+
|
9
|
+
# Default response format is json (you can use xml too). *optional
|
10
|
+
config.format = 'json'
|
11
|
+
|
12
|
+
#If you don't set your sender number in your request, this is the default number used instead *required
|
13
|
+
config.default_sender = '10000777070777'
|
14
|
+
|
15
|
+
# You can remove problematic emojis (like android emojis) and replace with standard emojis listed here:(https://www.webpagefx.com/tools/emoji-cheat-sheet/)
|
16
|
+
# config.strip_emoji = false # can include false , true and matcher
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
%w(faraday faraday_middleware validatable i18n).each do |dependency|
|
2
|
+
require dependency
|
3
|
+
end
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "pry"
|
7
|
+
rescue LoadError
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
module KaveRestApi
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor :api_key, :default_sender,:debugmode,:format,:strip_emoji
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
%w(version core helper request meaning respond).each do |identify|
|
34
|
+
require "kave_rest_api/#{identify}"
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
module KaveRestApi
|
3
|
+
module NumberHelper
|
4
|
+
def ctpd
|
5
|
+
return self.to_s.tr('0123456789','Û°Ù¡Û²Û³Û´ÛµÛ¶Û·Û¸Û¹')
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
module StringHelper
|
11
|
+
|
12
|
+
def ctsd
|
13
|
+
return self.to_s.tr('۰١۱۲۳۴۵۶۷۸۹،','01123456789,')
|
14
|
+
end
|
15
|
+
|
16
|
+
def ctpd
|
17
|
+
return self.to_s.tr('01123456789,','۰١۱۲۳۴۵۶۷۸۹،')
|
18
|
+
end
|
19
|
+
|
20
|
+
def strip_emoji
|
21
|
+
str = self.force_encoding('utf-8').encode
|
22
|
+
arr_regex=[/[\u{1f600}-\u{1f64f}]/,/[\u{2702}-\u{27b0}]/,/[\u{1f680}-\u{1f6ff}]/,/[\u{24C2}-\u{1F251}]/,/[\u{1f300}-\u{1f5ff}]/]
|
23
|
+
arr_regex.each do |regex|
|
24
|
+
str = str.gsub regex, ''
|
25
|
+
end
|
26
|
+
return str
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class Integer
|
34
|
+
include KaveRestApi::NumberHelper
|
35
|
+
end
|
36
|
+
|
37
|
+
class String
|
38
|
+
include KaveRestApi::StringHelper
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module KaveRestApi
|
3
|
+
module NumberHelper
|
4
|
+
|
5
|
+
def is_phone?
|
6
|
+
return !!self.match(/^(09{1})+([1-3]{1})+(\d{8})$/)
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
module StringHelper
|
12
|
+
|
13
|
+
def multibyte?
|
14
|
+
chars.count < bytes.count
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_phone?
|
18
|
+
return !!self.ctsd.match(/^(09{1})+([1-3]{1})+(\d{8})$/)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Integer
|
26
|
+
include KaveRestApi::NumberHelper
|
27
|
+
end
|
28
|
+
|
29
|
+
class String
|
30
|
+
include KaveRestApi::StringHelper
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
ERRORS = {
|
3
|
+
'200' => I18n.t("KaveRestApi.200", :default => "fallback text"),
|
4
|
+
'400' => 'http://www.banksepah.ir',
|
5
|
+
'401' => 'https://www.edbi.ir',
|
6
|
+
'402' => 'http://www.bim.ir',
|
7
|
+
'403' => 'http://www.bki.ir',
|
8
|
+
'404' => 'http://www.bank-maskan.ir',
|
9
|
+
'405' => 'http://www.postbank.ir',
|
10
|
+
'406' => 'http://www.ttbank.ir',
|
11
|
+
'407' => 'http://www.enbank.ir',
|
12
|
+
'408' => 'http://www.parsian-bank.ir',
|
13
|
+
'409' => 'http://www.bpi.ir',
|
14
|
+
'411' => 'http://www.karafarinbank.ir',
|
15
|
+
'412' => 'https://www.sb24.com',
|
16
|
+
'413' => 'http://www.sinabank.ir',
|
17
|
+
'414' => 'http://www.sbank.ir',
|
18
|
+
'415' => 'https://www.ba24.ir',
|
19
|
+
'417' => 'http://www.shahr-bank.ir',
|
20
|
+
'418' => 'http://www.bank-day.org',
|
21
|
+
'419' => 'http://www.bsi.ir',
|
22
|
+
'422' => 'http://www.bankmellat.ir',
|
23
|
+
'424' => 'http://www.tejaratbank.ir',
|
24
|
+
'426' => 'https://www.rb24.ir/',
|
25
|
+
'428' => 'https://www.ansarbank.com',
|
26
|
+
'431' => 'https://www.mebank.ir',
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
ENTRIES = {
|
31
|
+
:inÙ€queue => '1',
|
32
|
+
:givenÙ€date => '2',
|
33
|
+
:deliver_to_telecommunications => '4',
|
34
|
+
:failed => '6',
|
35
|
+
:delivered => '10',
|
36
|
+
:inaccessible => '11',
|
37
|
+
:ads_block => '14',
|
38
|
+
:sms_id_is_invalid => '100'
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class RequestBase
|
3
|
+
def initialize(args = {})
|
4
|
+
config = KaveRestApi.configuration
|
5
|
+
raise(ArgumentError, 'not a valid configuration class') if config.nil? || config.api_key.nil? || config.default_sender.nil?
|
6
|
+
@API_URL = "https://api.kavenegar.com/v1/#{config.api_key}"
|
7
|
+
@DEFAULT_SENDER = config.default_sender.freeze
|
8
|
+
@FORMAT= config.format rescue 'json'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Config < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :apilogs,:dailyreport,:debugmode,:defaultsender,:mincreditalarm,:resendfailed
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(args = {})
|
9
|
+
@ACTION_NAME = [:config,@FORMAT].join('.').freeze
|
10
|
+
@apilogs = args.fetch(:apilogs,nil)
|
11
|
+
@dailyreport = args.fetch(:dailyreport,nil)
|
12
|
+
@debugmode = args.fetch(:debugmode,nil)
|
13
|
+
@defaultsender = args.fetch(:defaultsender,nil)
|
14
|
+
@mincreditalarm = args.fetch(:mincreditalarm,nil)
|
15
|
+
@resendfailed = args.fetch(:resendfailed,nil)
|
16
|
+
@response = ResponseConfig.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
@valid
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_message_errors
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
connection = Faraday.new(url: "#{@API_URL}/account/") do |faraday|
|
29
|
+
faraday.adapter Faraday.default_adapter
|
30
|
+
faraday.response @FORMAT.to_sym
|
31
|
+
end
|
32
|
+
response = connection.get(@ACTION_NAME,apilogs: @apilogs,dailyreport: @dailyreport,debugmode: @debugmode,defaultsender: @defaultsender,mincreditalarm: @mincreditalarm,resendfailed: @resendfailed)
|
33
|
+
@response.validate(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Deliver < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :messageid
|
6
|
+
attr_reader :response
|
7
|
+
validates_presence_of :messageid
|
8
|
+
validates_format_of :messageid, :with => /^\d*$/, :if => Proc.new { !messageid.nil? }
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
@ACTION_NAME = [:status,@FORMAT].join('.').freeze
|
12
|
+
@messageid = args.fetch(:messageid)
|
13
|
+
if @messageid.kind_of?(Array)
|
14
|
+
raise(ArgumentError,'Message Id Arrays: Buffer Overflow: Max length 3000 of array') if @messageid.length > 3000
|
15
|
+
@messageid = @messageid.join(',')
|
16
|
+
end
|
17
|
+
@messageid = @messageid.ctsd
|
18
|
+
@response = ResponseDeliver.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
connection = Faraday.new(url: "#{@API_URL}/sms/") do |faraday|
|
23
|
+
faraday.adapter Faraday.default_adapter
|
24
|
+
faraday.response FORMAT.to_sym
|
25
|
+
end
|
26
|
+
response = connection.get(@ACTION_NAME, messageid: @messageid)
|
27
|
+
@response.validate(response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Info < KaveRestApi::RequestBase
|
3
|
+
def initialize(args = {})
|
4
|
+
@ACTION_NAME = [:info,@FORMAT].join('.').freeze
|
5
|
+
@response = ResponseInfo.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
9
|
+
connection = Faraday.new(url: "#{API_URL}/account/") do |faraday|
|
10
|
+
faraday.adapter Faraday.default_adapter
|
11
|
+
faraday.response FORMAT.to_sym
|
12
|
+
end
|
13
|
+
response = connection.get(@ACTION_NAME)
|
14
|
+
@response.validate(response.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class LatestOutBox < KaveRestApi::RequestBase
|
3
|
+
include Validatable
|
4
|
+
attr_accessor :pagesize,:sender
|
5
|
+
attr_reader :response
|
6
|
+
validates_format_of :sender, :with => /^\d*$/, :if => Proc.new { !sender.nil? }
|
7
|
+
validates_format_of :pagesize, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
8
|
+
validates_length_of :pagesize, :within => 1..4
|
9
|
+
def initialize(args = {})
|
10
|
+
super
|
11
|
+
@ACTION_NAME = [:latestoutbox,@FORMAT].join('.').freeze
|
12
|
+
@pagesize = args.fetch(:pagesize,3000).ctsd
|
13
|
+
@sender = args.fetch(:sender,nil)
|
14
|
+
@response = ResponseLatestOutBox.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
connection = Faraday.new(url: "#{@API_URL}/sms/") do |faraday|
|
19
|
+
faraday.adapter Faraday.default_adapter
|
20
|
+
faraday.response @FORMAT.to_sym
|
21
|
+
end
|
22
|
+
response = connection.get(@ACTION_NAME, sender: @sender,pagesize: @pagesize)
|
23
|
+
@response.validate(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Lookup < KaveRestApi::RequestBase
|
3
|
+
include Validatable
|
4
|
+
attr_accessor :receptor, :message,:unixdate,:type,:date,:localid,:sender
|
5
|
+
attr_reader :response,:message_size
|
6
|
+
validates_presence_of :token
|
7
|
+
validates_presence_of :receptor
|
8
|
+
validates_length_of :message, :within => 1..140
|
9
|
+
validates_format_of :sender, :with => /^\d*$/, :if => Proc.new { !sender.nil? }
|
10
|
+
validates_format_of :unixdate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:lookup,@FORMAT].join('.').freeze
|
15
|
+
@receptor = args.fetch(:receptor)
|
16
|
+
@receptor = @receptor.ctsd
|
17
|
+
@valid_receptor = @receptor.is_phone?
|
18
|
+
@token = args.fetch(:token)
|
19
|
+
@token2 = args.fetch(:token2,nil)
|
20
|
+
@token3 = args.fetch(:token3,nil)
|
21
|
+
@template = args.fetch(:template)
|
22
|
+
@type = args.fetch(:type,'sms')
|
23
|
+
@response = ResponseLookup.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_message?
|
27
|
+
@valid_message ||= true
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_receptor?
|
31
|
+
@valid_receptor
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
connection = Faraday.new(url: "#{@API_URL}/verify/") do |faraday|
|
36
|
+
faraday.adapter Faraday.default_adapter
|
37
|
+
faraday.response @FORMAT.to_sym
|
38
|
+
end
|
39
|
+
response = connection.get(@ACTION_NAME, receptor: @receptor , message: @message,localid: @localid,sender: @sender,date: @date,type: @type)
|
40
|
+
@response.validate(response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class Receive < KaveRestApi::RequestBase
|
3
|
+
attr_accessor :linenumber, :isread
|
4
|
+
attr_reader :response
|
5
|
+
include Validatable
|
6
|
+
validates_presence_of :linenumber
|
7
|
+
validates_presence_of :isread
|
8
|
+
validates_format_of :isread, :with => /^[01]$/, :if => Proc.new { !isread.nil? }
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
super
|
12
|
+
@ACTION_NAME = [:receive,@FORMAT].join('.').freeze
|
13
|
+
@linenumber = args.fetch(:linenumber,@DEFAULT_SENDER)
|
14
|
+
@isread = args.fetch(:isread,0)
|
15
|
+
@response = ResponseReceive.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
connection = Faraday.new(url: "#{@API_URL}/sms/") do |faraday|
|
20
|
+
faraday.adapter Faraday.default_adapter
|
21
|
+
faraday.response @FORMAT.to_sym
|
22
|
+
end
|
23
|
+
response = connection.get(@ACTION_NAME,linenumber: @linenumber,isread: @isread)
|
24
|
+
@response.validate(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class SelectOutBox < KaveRestApi::RequestBase
|
3
|
+
|
4
|
+
include Validatable
|
5
|
+
attr_accessor :startdate,:sender,:enddate
|
6
|
+
attr_reader :response
|
7
|
+
validates_presence_of :startdate
|
8
|
+
validates_format_of :sender, :with => /^\d*$/, :if => Proc.new { !sender.nil? }
|
9
|
+
validates_format_of :startdate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
10
|
+
validates_format_of :enddate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:selectoutbox,@FORMAT].join('.').freeze
|
15
|
+
@startdate = args.fetch(:startdate)
|
16
|
+
@enddate = args.fetch(:enddate,nil)
|
17
|
+
@sender = args.fetch(:sender,nil)
|
18
|
+
@response = ResponseSelectOutBox.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
connection = Faraday.new(url: "#{API_URL}/sms/") do |faraday|
|
23
|
+
faraday.adapter Faraday.default_adapter
|
24
|
+
faraday.response FORMAT.to_sym
|
25
|
+
end
|
26
|
+
response = connection.get(ACTION_NAME, sender: @sender,startdate: @startdate,enddate: @enddate)
|
27
|
+
@response.validate(response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class SendSimple < KaveRestApi::RequestBase
|
3
|
+
include Validatable
|
4
|
+
attr_accessor :receptor, :message,:unixdate,:type,:date,:localid,:sender
|
5
|
+
attr_reader :response,:message_size,:config
|
6
|
+
validates_presence_of :message
|
7
|
+
validates_presence_of :receptor
|
8
|
+
validates_length_of :message, :within => 1..140
|
9
|
+
validates_format_of :sender, :with => /^\d*$/, :if => Proc.new { !sender.nil? }
|
10
|
+
validates_format_of :unixdate, :with => /^\d*$/, :if => Proc.new { !unixdate.nil? }
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
super
|
14
|
+
@ACTION_NAME = [:send,@FORMAT].join('.').freeze
|
15
|
+
@receptor = args.fetch(:receptor)
|
16
|
+
|
17
|
+
if @receptor.kind_of?(Array)
|
18
|
+
@valid_receptor= false if @receptor.length > 200
|
19
|
+
@receptor = @receptor.join(',')
|
20
|
+
end
|
21
|
+
@receptor = @receptor.ctsd
|
22
|
+
@date = args.fetch(:date,nil)
|
23
|
+
@message = args.fetch(:message)
|
24
|
+
@message = @message.ctsd if args.fetch(:standard_digit,false)
|
25
|
+
@unixdate = args.fetch(:unixdate,nil)
|
26
|
+
@type = args.fetch(:type,nil)
|
27
|
+
@localid = args.fetch(:localid,nil)
|
28
|
+
@sender = args.fetch(:sender,@DEFAULT_SENDER)
|
29
|
+
@response = ResponseSendSimple.new
|
30
|
+
@message_size=@message.multibyte? ? 268:612
|
31
|
+
@valid_message= (@message.length > @message_size ) ? false:true
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_message?
|
35
|
+
@valid_message
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_receptor?
|
39
|
+
@valid_receptor
|
40
|
+
end
|
41
|
+
|
42
|
+
def call
|
43
|
+
connection = Faraday.new(url: "#{@API_URL}/sms/") do |faraday|
|
44
|
+
faraday.adapter Faraday.default_adapter
|
45
|
+
faraday.response @FORMAT.to_sym
|
46
|
+
end
|
47
|
+
|
48
|
+
response = connection.get(@ACTION_NAME, receptor: @receptor , message: @message,localid: @localid,sender: @sender,date: @date,type: @type)
|
49
|
+
@response.validate(response.body)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseConfig
|
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,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseDeliver
|
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(select=nil)
|
16
|
+
if select.nil?
|
17
|
+
return @response['entries']
|
18
|
+
else
|
19
|
+
return @response['entries'].select { |en|
|
20
|
+
en['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']['status'].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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseInfo
|
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,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseLatestOutBox
|
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(select=nil)
|
16
|
+
if select.nil?
|
17
|
+
return @response['entries']
|
18
|
+
else
|
19
|
+
return @response['entries'].select { |en|
|
20
|
+
en['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']['status'].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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseLookup
|
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(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']['status'].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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseReceive
|
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(select=nil)
|
16
|
+
if select.nil?
|
17
|
+
return @response['entries']
|
18
|
+
else
|
19
|
+
return @response['entries'].select { |en|
|
20
|
+
en['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']['status'].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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseSelectOutBox
|
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(select=nil)
|
16
|
+
if select.nil?
|
17
|
+
return @response['entries']
|
18
|
+
else
|
19
|
+
return @response['entries'].select { |en|
|
20
|
+
en['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']['status'].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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KaveRestApi
|
2
|
+
class ResponseSendSimple
|
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(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']['status'].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
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kave_rest_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mohammad mahmoudi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: feedjira
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: validatable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.14'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.14'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
description: "\n Ruby gem to send and receive SMS via kavenegar API(rest)\n kavenegar
|
140
|
+
is great services for send and receive sms this service has a some feature like
|
141
|
+
verification sms or voice service , etc\n "
|
142
|
+
email:
|
143
|
+
- mm580486@gmail.com
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- lib/generators/kave_rest_api/install_generator.rb
|
149
|
+
- lib/generators/templates/kave_rest_api_initializer.rb
|
150
|
+
- lib/kave_rest_api.rb
|
151
|
+
- lib/kave_rest_api/core.rb
|
152
|
+
- lib/kave_rest_api/helper.rb
|
153
|
+
- lib/kave_rest_api/helpers/convertor.rb
|
154
|
+
- lib/kave_rest_api/helpers/validator.rb
|
155
|
+
- lib/kave_rest_api/meaning.rb
|
156
|
+
- lib/kave_rest_api/request.rb
|
157
|
+
- lib/kave_rest_api/requests/RequestBase.rb
|
158
|
+
- lib/kave_rest_api/requests/config.rb
|
159
|
+
- lib/kave_rest_api/requests/deliver.rb
|
160
|
+
- lib/kave_rest_api/requests/info.rb
|
161
|
+
- lib/kave_rest_api/requests/latestoutbox.rb
|
162
|
+
- lib/kave_rest_api/requests/lookup.rb
|
163
|
+
- lib/kave_rest_api/requests/receive.rb
|
164
|
+
- lib/kave_rest_api/requests/selectoutbox.rb
|
165
|
+
- lib/kave_rest_api/requests/send.rb
|
166
|
+
- lib/kave_rest_api/respond.rb
|
167
|
+
- lib/kave_rest_api/responds/config.rb
|
168
|
+
- lib/kave_rest_api/responds/deliver.rb
|
169
|
+
- lib/kave_rest_api/responds/info.rb
|
170
|
+
- lib/kave_rest_api/responds/latestoutbox.rb
|
171
|
+
- lib/kave_rest_api/responds/lookup.rb
|
172
|
+
- lib/kave_rest_api/responds/receive.rb
|
173
|
+
- lib/kave_rest_api/responds/selectoutbox.rb
|
174
|
+
- lib/kave_rest_api/responds/send.rb
|
175
|
+
- lib/kave_rest_api/version.rb
|
176
|
+
homepage: https://github.com/mm580486/kave_rest_api/
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
metadata: {}
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 1.9.3
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.5.1
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Ruby gem to send and receive SMS via kavenegar API(rest)
|
200
|
+
test_files: []
|