serwersms 0.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/serwersms/client_credentials.rb +13 -0
- data/lib/serwersms/client_factory.rb +76 -0
- data/lib/serwersms/client_token.rb +13 -0
- data/lib/serwersms/error.rb +10 -0
- data/lib/serwersms/http/api_client.rb +63 -0
- data/lib/serwersms/http/http_credentials.rb +22 -0
- data/lib/serwersms/http/http_token.rb +23 -0
- data/lib/serwersms/resources/accounts.rb +59 -0
- data/lib/serwersms/resources/blacklist.rb +55 -0
- data/lib/serwersms/resources/contacts.rb +134 -0
- data/lib/serwersms/resources/error.rb +20 -0
- data/lib/serwersms/resources/files.rb +61 -0
- data/lib/serwersms/resources/groups.rb +83 -0
- data/lib/serwersms/resources/messages.rb +228 -0
- data/lib/serwersms/resources/phones.rb +33 -0
- data/lib/serwersms/resources/premium.rb +48 -0
- data/lib/serwersms/resources/senders.rb +33 -0
- data/lib/serwersms/resources/stats.rb +31 -0
- data/lib/serwersms/resources/subaccounts.rb +72 -0
- data/lib/serwersms/resources/templates.rb +55 -0
- data/lib/serwersms/resources_mixin.rb +55 -0
- data/lib/serwersms.rb +21 -57
- metadata +28 -27
- data/lib/library/accounts.rb +0 -65
- data/lib/library/blacklist.rb +0 -63
- data/lib/library/contacts.rb +0 -145
- data/lib/library/error.rb +0 -19
- data/lib/library/files.rb +0 -74
- data/lib/library/groups.rb +0 -103
- data/lib/library/messages.rb +0 -352
- data/lib/library/payments.rb +0 -55
- data/lib/library/phones.rb +0 -40
- data/lib/library/premium.rb +0 -58
- data/lib/library/senders.rb +0 -36
- data/lib/library/stats.rb +0 -31
- data/lib/library/subaccounts.rb +0 -87
- data/lib/library/templates.rb +0 -69
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bb814e6525d1dd5912fb68505139c28b7a2236666f9e37e228c09c375d7160fe
|
|
4
|
+
data.tar.gz: 63307ff009e5d67462229fb226ac0b04e2584e17730039d7ac9d727fa57e0cd6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10a5942f9fd9fd281f1211d7f0e86c350743f344473a25c0906281bfda3f961378b594a641c4bc3476e1665efbc9677d916ee90f861d36f809b11d8e3994bd36
|
|
7
|
+
data.tar.gz: e9149d162235cb9c06878bd5b368078bec62580d45020e4639d95c6eda02f9cb5e1d5e16042c1f185d602e42756a4090d338684a27bf81d9224d45b0b07692a0
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
class ClientCredentials
|
|
3
|
+
include SerwerSMS::ResourcesMixin
|
|
4
|
+
|
|
5
|
+
def initialize(username:, password:, **opts)
|
|
6
|
+
@http = Http::HttpCredentials.new(username: username, password: password, **opts)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(path, params = {})
|
|
10
|
+
@http.call(path, params)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module SerwerSMS
|
|
4
|
+
class ClientFactory
|
|
5
|
+
USERNAME_KEY = 'SERWERSMS_USERNAME'
|
|
6
|
+
PASSWORD_KEY = 'SERWERSMS_PASSWORD'
|
|
7
|
+
TOKEN_KEY = 'SERWERSMS_TOKEN'
|
|
8
|
+
API_URL_KEY = 'SERWERSMS_API_URL'
|
|
9
|
+
TIMEOUT_KEY = 'SERWERSMS_TIMEOUT'
|
|
10
|
+
|
|
11
|
+
# Tworzy klienta na podstawie zmiennych środowiskowych.
|
|
12
|
+
#
|
|
13
|
+
# Przykład:
|
|
14
|
+
# SerwerSMS::ClientFactory.from_env
|
|
15
|
+
#
|
|
16
|
+
def self.from_env
|
|
17
|
+
opts = {}
|
|
18
|
+
opts[:api_url] = ENV[API_URL_KEY] if ENV[API_URL_KEY]
|
|
19
|
+
opts[:timeout] = ENV[TIMEOUT_KEY].to_i if ENV[TIMEOUT_KEY]
|
|
20
|
+
|
|
21
|
+
build_client(
|
|
22
|
+
token: ENV[TOKEN_KEY],
|
|
23
|
+
username: ENV[USERNAME_KEY],
|
|
24
|
+
password: ENV[PASSWORD_KEY],
|
|
25
|
+
**opts
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Tworzy klienta na podstawie pliku YAML.
|
|
30
|
+
#
|
|
31
|
+
# Przykład pliku config/serwersms.yml:
|
|
32
|
+
#
|
|
33
|
+
# # Opcja 1 - autentykacja przez token (zalecana)
|
|
34
|
+
# serwersms_token: 'twoj_token'
|
|
35
|
+
#
|
|
36
|
+
# # Opcja 2 - autentykacja przez login i hasło
|
|
37
|
+
# # serwersms_username: 'twoj_login'
|
|
38
|
+
# # serwersms_password: 'twoje_haslo'
|
|
39
|
+
#
|
|
40
|
+
# # Opcjonalne
|
|
41
|
+
# # serwersms_api_url: 'https://api2.serwersms.pl'
|
|
42
|
+
# # serwersms_timeout: 30
|
|
43
|
+
#
|
|
44
|
+
# Przykład użycia:
|
|
45
|
+
# SerwerSMS::ClientFactory.from_yaml('config/serwersms.yml')
|
|
46
|
+
#
|
|
47
|
+
def self.from_yaml(yaml_file)
|
|
48
|
+
raise SerwerSMS::Error, "Config file not found: #{yaml_file}" unless File.exist?(yaml_file)
|
|
49
|
+
|
|
50
|
+
cfg = YAML.safe_load_file(yaml_file) || {}
|
|
51
|
+
|
|
52
|
+
opts = {}
|
|
53
|
+
opts[:api_url] = cfg['serwersms_api_url'] if cfg['serwersms_api_url']
|
|
54
|
+
opts[:timeout] = cfg['serwersms_timeout'] if cfg['serwersms_timeout']
|
|
55
|
+
|
|
56
|
+
build_client(
|
|
57
|
+
token: cfg['serwersms_token'],
|
|
58
|
+
username: cfg['serwersms_username'],
|
|
59
|
+
password: cfg['serwersms_password'],
|
|
60
|
+
**opts
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def self.build_client(token:, username:, password:, **opts)
|
|
67
|
+
if !token.to_s.strip.empty?
|
|
68
|
+
ClientToken.new(token: token, **opts)
|
|
69
|
+
elsif !username.to_s.strip.empty? && !password.to_s.strip.empty?
|
|
70
|
+
ClientCredentials.new(username: username, password: password, **opts)
|
|
71
|
+
else
|
|
72
|
+
raise SerwerSMS::Error, 'Wymagany SERWERSMS_TOKEN lub para SERWERSMS_USERNAME + SERWERSMS_PASSWORD'
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
|
|
5
|
+
module SerwerSMS
|
|
6
|
+
module Http
|
|
7
|
+
class ApiClient
|
|
8
|
+
API_URL = 'https://api2.serwersms.pl'.freeze
|
|
9
|
+
SYSTEM = 'client_ruby'.freeze
|
|
10
|
+
|
|
11
|
+
def initialize(api_url: API_URL, timeout: 30)
|
|
12
|
+
@api_url = api_url.chomp('/')
|
|
13
|
+
@timeout = timeout
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def call(path, params = {})
|
|
17
|
+
params = params.compact
|
|
18
|
+
params['system'] = SYSTEM
|
|
19
|
+
|
|
20
|
+
apply_auth(params)
|
|
21
|
+
|
|
22
|
+
uri = URI.parse("#{@api_url}/#{path}.json")
|
|
23
|
+
|
|
24
|
+
Net::HTTP.start(uri.host, uri.port,
|
|
25
|
+
use_ssl: true,
|
|
26
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER,
|
|
27
|
+
open_timeout: @timeout,
|
|
28
|
+
read_timeout: @timeout
|
|
29
|
+
) do |http|
|
|
30
|
+
request = Net::HTTP::Post.new(uri, build_headers)
|
|
31
|
+
request.body = params.to_json
|
|
32
|
+
|
|
33
|
+
response = http.request(request)
|
|
34
|
+
|
|
35
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
36
|
+
raise SerwerSMS::Error.new("HTTP #{response.code}", response.code)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
result = JSON.parse(response.body)
|
|
40
|
+
|
|
41
|
+
if result.is_a?(Hash) && result['error']
|
|
42
|
+
raise SerwerSMS::Error.new(
|
|
43
|
+
result.dig('error', 'message') || 'Unknown API error',
|
|
44
|
+
result.dig('error', 'code')
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def apply_auth(_params)
|
|
55
|
+
raise NotImplementedError, "#{self.class}#apply_auth not implemented"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def build_headers
|
|
59
|
+
{ 'Content-Type' => 'application/json' }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Http
|
|
3
|
+
class HttpCredentials < ApiClient
|
|
4
|
+
def initialize(username:, password:, **opts)
|
|
5
|
+
raise SerwerSMS::Error, 'Username is empty' if username.to_s.strip.empty?
|
|
6
|
+
raise SerwerSMS::Error, 'Password is empty' if password.to_s.strip.empty?
|
|
7
|
+
|
|
8
|
+
super(**opts)
|
|
9
|
+
|
|
10
|
+
@username = username
|
|
11
|
+
@password = password
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def apply_auth(params)
|
|
17
|
+
params['username'] = @username
|
|
18
|
+
params['password'] = @password
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Http
|
|
3
|
+
class HttpToken < ApiClient
|
|
4
|
+
def initialize(token:, **opts)
|
|
5
|
+
raise SerwerSMS::Error, 'Token is empty' if token.to_s.strip.empty?
|
|
6
|
+
|
|
7
|
+
super(**opts)
|
|
8
|
+
|
|
9
|
+
@token = token
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def apply_auth(_params)
|
|
15
|
+
# token przekazywany przez nagłówek Authorization, nie w body
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build_headers
|
|
19
|
+
super.merge('Authorization' => "Bearer #{@token}")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Accounts
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Register new account
|
|
9
|
+
#
|
|
10
|
+
# @param params [Hash]
|
|
11
|
+
# @option params [String] :phone
|
|
12
|
+
# @option params [String] :email
|
|
13
|
+
# @option params [String] :first_name
|
|
14
|
+
# @option params [String] :last_name
|
|
15
|
+
# @option params [String] :company
|
|
16
|
+
# @return [Hash]
|
|
17
|
+
# @option return [Boolean] :success
|
|
18
|
+
def add(params = {})
|
|
19
|
+
@client.call('account/add', params)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Return SMS limits for account
|
|
23
|
+
#
|
|
24
|
+
# @return [Hash]
|
|
25
|
+
# @option return [Array] :items
|
|
26
|
+
# @option item [String] :type Type of message
|
|
27
|
+
# @option item [String] :chars_limit Maximum length of message
|
|
28
|
+
# @option item [String] :value Limit messages
|
|
29
|
+
def limits(params = {})
|
|
30
|
+
@client.call('account/limits', params)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Return contact details
|
|
34
|
+
#
|
|
35
|
+
# @return [Hash]
|
|
36
|
+
# @option return [String] :telephone
|
|
37
|
+
# @option return [String] :email
|
|
38
|
+
# @option return [String] :form
|
|
39
|
+
# @option return [String] :faq
|
|
40
|
+
# @option return [Hash] :guardian_account
|
|
41
|
+
# @option guardian_account [String] :name
|
|
42
|
+
# @option guardian_account [String] :email
|
|
43
|
+
# @option guardian_account [String] :telephone
|
|
44
|
+
# @option guardian_account [String] :photo
|
|
45
|
+
def help(params = {})
|
|
46
|
+
@client.call('account/help', params)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Return messages from the administrator
|
|
50
|
+
#
|
|
51
|
+
# @return [Hash]
|
|
52
|
+
# @option return [Boolean] :new Marking unread message
|
|
53
|
+
# @option return [String] :message
|
|
54
|
+
def messages(params = {})
|
|
55
|
+
@client.call('account/messages', params)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Blacklist
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Add phone to the blacklist
|
|
9
|
+
#
|
|
10
|
+
# @param phone [String]
|
|
11
|
+
# @return [Hash]
|
|
12
|
+
# @option return [Boolean] :success
|
|
13
|
+
# @option return [Integer] :id
|
|
14
|
+
def add(phone)
|
|
15
|
+
@client.call('blacklist/add', 'phone' => phone)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# List of blacklisted phones
|
|
19
|
+
#
|
|
20
|
+
# @param phone [String]
|
|
21
|
+
# @param params [Hash]
|
|
22
|
+
# @option params [Integer] :page The number of the displayed page
|
|
23
|
+
# @option params [Integer] :limit Limit items displayed on single page
|
|
24
|
+
# @return [Hash]
|
|
25
|
+
# @option return [Hash] :paging
|
|
26
|
+
# @option paging [Integer] :page The number of current page
|
|
27
|
+
# @option paging [Integer] :count The number of all pages
|
|
28
|
+
# @option return [Array] :items
|
|
29
|
+
# @option item [String] :phone
|
|
30
|
+
# @option item [String] :added Date of adding phone
|
|
31
|
+
def index(phone = nil, params = {})
|
|
32
|
+
params['phone'] = phone
|
|
33
|
+
@client.call('blacklist/index', params)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Check if phone is blacklisted
|
|
37
|
+
#
|
|
38
|
+
# @param phone [String]
|
|
39
|
+
# @return [Hash]
|
|
40
|
+
# @option return [Boolean] :exists
|
|
41
|
+
def check(phone)
|
|
42
|
+
@client.call('blacklist/check', 'phone' => phone)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Delete phone from the blacklist
|
|
46
|
+
#
|
|
47
|
+
# @param phone [String]
|
|
48
|
+
# @return [Hash]
|
|
49
|
+
# @option return [Boolean] :success
|
|
50
|
+
def delete(phone)
|
|
51
|
+
@client.call('blacklist/delete', 'phone' => phone)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Contacts
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Add new contact
|
|
9
|
+
#
|
|
10
|
+
# @param group_id [Integer]
|
|
11
|
+
# @param phone [String]
|
|
12
|
+
# @param params [Hash]
|
|
13
|
+
# @option params [String] :email
|
|
14
|
+
# @option params [String] :first_name
|
|
15
|
+
# @option params [String] :last_name
|
|
16
|
+
# @option params [String] :company
|
|
17
|
+
# @option params [String] :tax_id
|
|
18
|
+
# @option params [String] :address
|
|
19
|
+
# @option params [String] :city
|
|
20
|
+
# @option params [String] :description
|
|
21
|
+
# @return [Hash]
|
|
22
|
+
# @option return [Boolean] :success
|
|
23
|
+
# @option return [Integer] :id
|
|
24
|
+
def add(group_id, phone, params = {})
|
|
25
|
+
params['group_id'] = group_id
|
|
26
|
+
params['phone'] = phone
|
|
27
|
+
@client.call('contacts/add', params)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# List of contacts
|
|
31
|
+
#
|
|
32
|
+
# @param group_id [Integer]
|
|
33
|
+
# @param search [String]
|
|
34
|
+
# @param params [Hash]
|
|
35
|
+
# @option params [Integer] :page The number of the displayed page
|
|
36
|
+
# @option params [Integer] :limit Limit items displayed on single page
|
|
37
|
+
# @option params [String] :sort Values: first_name|last_name|phone|company|tax_id|email|address|city|description
|
|
38
|
+
# @option params [String] :order Values: asc|desc
|
|
39
|
+
# @return [Hash]
|
|
40
|
+
# @option return [Hash] :paging
|
|
41
|
+
# @option paging [Integer] :page The number of current page
|
|
42
|
+
# @option paging [Integer] :count The number of all pages
|
|
43
|
+
# @option return [Array] :items
|
|
44
|
+
# @option item [Integer] :id
|
|
45
|
+
# @option item [String] :phone
|
|
46
|
+
# @option item [String] :email
|
|
47
|
+
# @option item [String] :company
|
|
48
|
+
# @option item [String] :first_name
|
|
49
|
+
# @option item [String] :last_name
|
|
50
|
+
# @option item [String] :tax_id
|
|
51
|
+
# @option item [String] :address
|
|
52
|
+
# @option item [String] :city
|
|
53
|
+
# @option item [String] :description
|
|
54
|
+
# @option item [Boolean] :blacklist
|
|
55
|
+
# @option item [Integer] :group_id
|
|
56
|
+
# @option item [String] :group_name
|
|
57
|
+
def index(group_id = nil, search = nil, params = {})
|
|
58
|
+
params['group_id'] = group_id.nil? ? 'none' : group_id
|
|
59
|
+
params['search'] = search
|
|
60
|
+
@client.call('contacts/index', params)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# View single contact
|
|
64
|
+
#
|
|
65
|
+
# @param id [Integer]
|
|
66
|
+
# @return [Hash]
|
|
67
|
+
# @option return [Integer] :id
|
|
68
|
+
# @option return [String] :phone
|
|
69
|
+
# @option return [String] :email
|
|
70
|
+
# @option return [String] :company
|
|
71
|
+
# @option return [String] :first_name
|
|
72
|
+
# @option return [String] :last_name
|
|
73
|
+
# @option return [String] :tax_id
|
|
74
|
+
# @option return [String] :address
|
|
75
|
+
# @option return [String] :city
|
|
76
|
+
# @option return [String] :description
|
|
77
|
+
# @option return [Boolean] :blacklist
|
|
78
|
+
def view(id)
|
|
79
|
+
@client.call('contacts/view', 'id' => id)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Edit a contact
|
|
83
|
+
#
|
|
84
|
+
# @param id [Integer]
|
|
85
|
+
# @param group_id [Integer, Array]
|
|
86
|
+
# @param phone [String]
|
|
87
|
+
# @param params [Hash]
|
|
88
|
+
# @option params [String] :email
|
|
89
|
+
# @option params [String] :first_name
|
|
90
|
+
# @option params [String] :last_name
|
|
91
|
+
# @option params [String] :company
|
|
92
|
+
# @option params [String] :tax_id
|
|
93
|
+
# @option params [String] :address
|
|
94
|
+
# @option params [String] :city
|
|
95
|
+
# @option params [String] :description
|
|
96
|
+
# @return [Hash]
|
|
97
|
+
# @option return [Boolean] :success
|
|
98
|
+
# @option return [Integer] :id
|
|
99
|
+
def edit(id, group_id, phone, params = {})
|
|
100
|
+
params['id'] = id
|
|
101
|
+
params['group_id'] = group_id
|
|
102
|
+
params['phone'] = phone
|
|
103
|
+
@client.call('contacts/edit', params)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Delete a contact
|
|
107
|
+
#
|
|
108
|
+
# @param id [Integer]
|
|
109
|
+
# @return [Hash]
|
|
110
|
+
# @option return [Boolean] :success
|
|
111
|
+
def delete(id)
|
|
112
|
+
@client.call('contacts/delete', 'id' => id)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Import contact list
|
|
116
|
+
#
|
|
117
|
+
# @param group_name [String]
|
|
118
|
+
# @param contact [Array]
|
|
119
|
+
# @option contact [String] :phone
|
|
120
|
+
# @option contact [String] :email
|
|
121
|
+
# @option contact [String] :first_name
|
|
122
|
+
# @option contact [String] :last_name
|
|
123
|
+
# @option contact [String] :company
|
|
124
|
+
# @return [Hash]
|
|
125
|
+
# @option return [Boolean] :success
|
|
126
|
+
# @option return [Integer] :id
|
|
127
|
+
# @option return [Integer] :correct Number of contacts imported correctly
|
|
128
|
+
# @option return [Integer] :failed Number of errors
|
|
129
|
+
def import(group_name, contact = [])
|
|
130
|
+
@client.call('contacts/import', 'group_name' => group_name, 'contact' => contact)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Error
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Preview error details
|
|
9
|
+
#
|
|
10
|
+
# @param code [Integer]
|
|
11
|
+
# @return [Hash]
|
|
12
|
+
# @option return [Integer] :code
|
|
13
|
+
# @option return [String] :type
|
|
14
|
+
# @option return [String] :message
|
|
15
|
+
def view(code)
|
|
16
|
+
@client.call("error/#{code}")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Files
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Add new file
|
|
9
|
+
#
|
|
10
|
+
# @param type [String] mms|voice
|
|
11
|
+
# @param params [Hash]
|
|
12
|
+
# @option params [String] :url URL address to file
|
|
13
|
+
# @option params [String] :name File name
|
|
14
|
+
# @return [Hash]
|
|
15
|
+
# @option return [Boolean] :success
|
|
16
|
+
# @option return [String] :id
|
|
17
|
+
def add(type, params = {})
|
|
18
|
+
params['type'] = type
|
|
19
|
+
@client.call('files/add', params)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# List of files
|
|
23
|
+
#
|
|
24
|
+
# @param type [String] mms|voice
|
|
25
|
+
# @return [Hash]
|
|
26
|
+
# @option return [Array] :items
|
|
27
|
+
# @option item [String] :id
|
|
28
|
+
# @option item [String] :name
|
|
29
|
+
# @option item [Integer] :size
|
|
30
|
+
# @option item [String] :type mms|voice
|
|
31
|
+
# @option item [String] :date
|
|
32
|
+
def index(type)
|
|
33
|
+
@client.call('files/index', 'type' => type)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# View file details
|
|
37
|
+
#
|
|
38
|
+
# @param id [String]
|
|
39
|
+
# @param type [String] mms|voice
|
|
40
|
+
# @return [Hash]
|
|
41
|
+
# @option return [String] :id
|
|
42
|
+
# @option return [String] :name
|
|
43
|
+
# @option return [Integer] :size
|
|
44
|
+
# @option return [String] :type mms|voice
|
|
45
|
+
# @option return [String] :date
|
|
46
|
+
def view(id, type)
|
|
47
|
+
@client.call('files/view', 'id' => id, 'type' => type)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Delete a file
|
|
51
|
+
#
|
|
52
|
+
# @param id [String]
|
|
53
|
+
# @param type [String] mms|voice
|
|
54
|
+
# @return [Hash]
|
|
55
|
+
# @option return [Boolean] :success
|
|
56
|
+
def delete(id, type)
|
|
57
|
+
@client.call('files/delete', 'id' => id, 'type' => type)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module SerwerSMS
|
|
2
|
+
module Resources
|
|
3
|
+
class Groups
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Add new group
|
|
9
|
+
#
|
|
10
|
+
# @param name [String]
|
|
11
|
+
# @return [Hash]
|
|
12
|
+
# @option return [Boolean] :success
|
|
13
|
+
# @option return [Integer] :id
|
|
14
|
+
def add(name)
|
|
15
|
+
@client.call('groups/add', 'name' => name)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# List of groups
|
|
19
|
+
#
|
|
20
|
+
# @param search [String] Group name filter
|
|
21
|
+
# @param params [Hash]
|
|
22
|
+
# @option params [Integer] :page The number of the displayed page
|
|
23
|
+
# @option params [Integer] :limit Limit items displayed on single page
|
|
24
|
+
# @option params [String] :sort Values: name
|
|
25
|
+
# @option params [String] :order Values: asc|desc
|
|
26
|
+
# @return [Hash]
|
|
27
|
+
# @option return [Hash] :paging
|
|
28
|
+
# @option paging [Integer] :page The number of current page
|
|
29
|
+
# @option paging [Integer] :count The number of all pages
|
|
30
|
+
# @option return [Array] :items
|
|
31
|
+
# @option item [Integer] :id
|
|
32
|
+
# @option item [String] :name
|
|
33
|
+
# @option item [Integer] :count Number of contacts in the group
|
|
34
|
+
def index(search = nil, params = {})
|
|
35
|
+
params['search'] = search
|
|
36
|
+
@client.call('groups/index', params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# View single group
|
|
40
|
+
#
|
|
41
|
+
# @param id [Integer]
|
|
42
|
+
# @return [Hash]
|
|
43
|
+
# @option return [Integer] :id
|
|
44
|
+
# @option return [String] :name
|
|
45
|
+
# @option return [Integer] :count Number of contacts in the group
|
|
46
|
+
def view(id)
|
|
47
|
+
@client.call('groups/view', 'id' => id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Edit a group
|
|
51
|
+
#
|
|
52
|
+
# @param id [Integer]
|
|
53
|
+
# @param name [String]
|
|
54
|
+
# @return [Hash]
|
|
55
|
+
# @option return [Boolean] :success
|
|
56
|
+
# @option return [Integer] :id
|
|
57
|
+
def edit(id, name)
|
|
58
|
+
@client.call('groups/edit', 'id' => id, 'name' => name)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Delete a group
|
|
62
|
+
#
|
|
63
|
+
# @param id [Integer]
|
|
64
|
+
# @return [Hash]
|
|
65
|
+
# @option return [Boolean] :success
|
|
66
|
+
def delete(id)
|
|
67
|
+
@client.call('groups/delete', 'id' => id)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# View groups containing phone number
|
|
71
|
+
#
|
|
72
|
+
# @param phone [String]
|
|
73
|
+
# @return [Hash]
|
|
74
|
+
# @option return [Array] :items
|
|
75
|
+
# @option item [Integer] :id
|
|
76
|
+
# @option item [Integer] :group_id
|
|
77
|
+
# @option item [String] :group_name
|
|
78
|
+
def check(phone)
|
|
79
|
+
@client.call('groups/check', 'phone' => phone)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|