smsapi-client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d3b9d0bfa832e3b08c12271a46baa9f3c2111a0
4
- data.tar.gz: 970f448af0780ee8b96ef7fe0640804c81351962
3
+ metadata.gz: aca718d7c1299fa804479d64055ce5b67151e2bf
4
+ data.tar.gz: 4020f101559041a6f0ffcb2d13fa001f2e2a6cd0
5
5
  SHA512:
6
- metadata.gz: 892fa8a907f6b9f6d3bf0f9aab3931ca3864f2abcde86143ceff4d76631b02be6ac21986c36181186814ad60d1171271614a5823ba68eb1616593032629e1e46
7
- data.tar.gz: d09630489721bc5338010204b973719e79a3334c109c429bbd5d42277e299cf6b17beb6bc0522ffda329cd0c8cd8ac3bb9bd93f9834cc9ccc3fa3b733fd710ab
6
+ metadata.gz: 64e515e7620bf98aba7d37f151e843788d8bb80ce5ae6f40127d3c7199d6154ca38b7dea8bc7cec2d27e4f7349265740f3dd4bcb2cb8dd22eba8639fc4a81770
7
+ data.tar.gz: 028165990a2077b50c4c04ecab59b02203c896177ac0dfec54d7961f2b6762602afa4ff33b0a613160c93387b4a077e21180793703d5bd154cc20e1e2b33e6b8
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add this line to your application's Gemfile:
6
6
 
7
7
  ```ruby
8
- gem 'smsapi-client', '~> 0.2'
8
+ gem 'smsapi-client', '~> 0.3'
9
9
  ```
10
10
 
11
11
  And then execute:
@@ -14,7 +14,7 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install smsapi-client
17
+ $ gem install smsapi-client -v '~> 0.3'
18
18
 
19
19
  ## Usage
20
20
 
@@ -22,6 +22,15 @@ Or install it yourself as:
22
22
  # Create the client
23
23
  client = Smsapi::Client.new('username', 'password')
24
24
 
25
+ # Get credits (account details)
26
+ credits = client.credits
27
+ credits.balance # => 2.6600
28
+ credits.pro_sms_limit # => 16
29
+ credits.eco_sms_limit # => 38
30
+ credits.mms_limit # => 8
31
+ credits.vms_gsm_limit # => 26
32
+ credits.vms_stac_limit # => 26
33
+
25
34
  # Send a single text message
26
35
  sms = client.send_single 500500500, 'Text Message'
27
36
  sms.status # 'OK'
data/lib/smsapi/client.rb CHANGED
@@ -1,23 +1,23 @@
1
1
  module Smsapi
2
2
  class Client
3
3
  def initialize(username, password)
4
- @server = Server.new(username, password)
4
+ @server = Smsapi::Server.new(username, password)
5
+ end
6
+
7
+ def credits(options = {})
8
+ Smsapi::Credits.new(@server, options).check
5
9
  end
6
10
 
7
11
  def send_single(to, message, options = {})
8
- SMS.new(to, message, @server, options).deliver
12
+ Smsapi::SMS.new(to, message, @server, options).deliver
9
13
  end
10
14
 
11
15
  def schedule_single(to, message, date, options = {})
12
- SMS.new(to, message, @server, options).deliver_at(date)
16
+ Smsapi::SMS.new(to, message, @server, options).deliver_at(date)
13
17
  end
14
18
 
15
19
  def send_bulk(to, message, options = {})
16
- BulkSMS.new(to, message, @server, options).deliver
17
- end
18
-
19
- def details
20
- # not implemented
20
+ Smsapi::BulkSMS.new(to, message, @server, options).deliver
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,61 @@
1
+ module Smsapi
2
+ class Credits
3
+
4
+ attr_accessor :status, :error_code, :balance, :pro_sms_limit, :eco_sms_limit, :mms_limit, :vms_gsm_limit, :vms_stac_limit
5
+ def initialize(server, options = {})
6
+ @options = default_options.merge options
7
+ @server = server
8
+ end
9
+
10
+ def check
11
+ read_response @server.user(server_params).join(';')
12
+ self
13
+ end
14
+
15
+ def sent?
16
+ not self.status.nil?
17
+ end
18
+
19
+ def error?
20
+ self.status == 'ERROR'
21
+ end
22
+
23
+ def success?
24
+ self.status == 'Points'
25
+ end
26
+
27
+ def error_message
28
+ Smsapi::ERROR_MESSAGES[error_code]
29
+ end
30
+
31
+ def read_response(response)
32
+ response = response.split(':').map(&:strip)
33
+
34
+ self.status = response[0]
35
+ if status == 'ERROR'
36
+ self.error_code = response[1]
37
+ else
38
+ data = response[1].split(';')
39
+ self.balance = data[0].to_f
40
+ self.pro_sms_limit = data[1].to_i
41
+ self.eco_sms_limit = data[2].to_i
42
+ self.mms_limit = data[3].to_i
43
+ self.vms_gsm_limit = data[4].to_i
44
+ self.vms_stac_limit = data[5].to_i
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def default_options
51
+ {
52
+ credits: 1,
53
+ details: 1
54
+ }
55
+ end
56
+
57
+ def server_params
58
+ @options
59
+ end
60
+ end
61
+ end
@@ -2,7 +2,7 @@ module Smsapi::Defaults
2
2
  def default_options
3
3
  {
4
4
  from: 'eco',
5
- test: '1'
5
+ test: '0'
6
6
  }
7
7
  end
8
8
  end
data/lib/smsapi/server.rb CHANGED
@@ -6,6 +6,11 @@ module Smsapi
6
6
  @connection = setup_connection
7
7
  end
8
8
 
9
+ def user(params = {})
10
+ api_response = make_request(Smsapi::API[:user_path], params)
11
+ api_response.split(';')
12
+ end
13
+
9
14
  def sms(params = {})
10
15
  api_response = make_request(Smsapi::API[:sms_path], params)
11
16
  api_response.split(';')
data/lib/smsapi/smsapi.rb CHANGED
@@ -2,6 +2,7 @@ require 'smsapi/server'
2
2
  require 'smsapi/server/connection'
3
3
  require 'smsapi/client'
4
4
  require 'smsapi/defaults'
5
+ require 'smsapi/credits'
5
6
  require 'smsapi/sms'
6
7
  require 'smsapi/bulk_sms'
7
8
  require 'smsapi/group_sms'
@@ -10,14 +11,16 @@ module Smsapi
10
11
  class Error < StandardError; end
11
12
  class ServerError < Error; end
12
13
 
13
- VERSION = "0.2.0"
14
+ VERSION = "0.3.0"
14
15
  API = {
15
16
  uri: 'ssl.smsapi.pl',
16
17
  port: 443,
18
+ user_path: '/user.do',
17
19
  sms_path: '/sms.do'
18
20
  }
19
21
 
20
22
  ERROR_MESSAGES = {
21
23
  '101' => 'Bad Credentials',
24
+ '1001' => 'Bad Request Format'
22
25
  }
23
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alek Niemczyk
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2015-10-02 00:00:00.000000000 Z
14
+ date: 2015-12-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -59,6 +59,7 @@ files:
59
59
  - bin/setup
60
60
  - lib/smsapi/bulk_sms.rb
61
61
  - lib/smsapi/client.rb
62
+ - lib/smsapi/credits.rb
62
63
  - lib/smsapi/defaults.rb
63
64
  - lib/smsapi/group_sms.rb
64
65
  - lib/smsapi/server.rb