turbosms 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eca10e39e026c28c8dcb44bc60dbec75ff79ea20
4
- data.tar.gz: dc1d8bd10cd6395c290419a4acbe73c9beb6afea
3
+ metadata.gz: ecc2f2bb8d81f81beae1bfd088b9bcf974f2e3c4
4
+ data.tar.gz: 63fa21be68b7b9e1ea83e56764748c778a9cf71c
5
5
  SHA512:
6
- metadata.gz: ed50526c2d8eb71a299442ab86345bdd347b33a5d2ef20e73460b9417598c9f16cdec3b2ef8d7d089a1e6b6b10b88273a13f7b5db1cdd09723a256a4f6c1fe37
7
- data.tar.gz: e8fdd980bb6731bc5e823bd297727ef0f51e7ca63c1e28cfe669a8dcef1de500680babec42b607fa5abb20eafe4c801ab6c9600277f2a6332d86e04c832edfd5
6
+ metadata.gz: 48f995de4b6ad04cd021f34f922731a5ef5e40b8e7eb223b3916238cfe4ce7c7b0c943664f18a23ef8e2e92a31c87c9e63ecc93d111298da11f5de0f2e995bec
7
+ data.tar.gz: affa7612dced4b108c203bb4bde287aaab75bee7341814b2dc1d0fa5a05549fbe2b284608bfd90869aee8bb247b953dcb71883cccbe9a3c4f1dfd977bab0a519
@@ -1,6 +1,8 @@
1
1
  require 'savon'
2
2
 
3
3
  module TurboSMS
4
+ COOKIE_EXPTIRATION_TIMEOUT = 60*60*12
5
+
4
6
  class << self
5
7
 
6
8
  private
@@ -10,7 +12,7 @@ module TurboSMS
10
12
  end
11
13
 
12
14
  def authorized?
13
- !@cookies.nil?
15
+ !@cookies.nil? and @cookies_expires_at > Time.now
14
16
  end
15
17
 
16
18
  def auth_message
@@ -21,7 +23,7 @@ module TurboSMS
21
23
  def authorize
22
24
  response = client.call(:auth, message: auth_message)
23
25
  result = response.body[:auth_response][:auth_result]
24
- @cookies = response.http.cookies if (result.length == 27) # Ridiculous # Вы успешно авторизировались
26
+ store_cookies response.http.cookies if (result.length == 27) # Ridiculous # Вы успешно авторизировались
25
27
  raise AuthError, result unless authorized?
26
28
  end
27
29
 
@@ -31,9 +33,19 @@ module TurboSMS
31
33
  response = client.call(method_name, args.merge(cookies: @cookies))
32
34
  result = response.body[response_key][result_key]
33
35
  result = result[:result_array] if result.instance_of?(Hash) and !result[:result_array].nil?
34
- @cookies = nil if !result.instance_of?(Array) and result.length == 20 # Ridiculous # Вы не авторизированы
36
+ clear_cookie if !result.instance_of?(Array) and result.length == 20 # Ridiculous # Вы не авторизированы
35
37
  result
36
38
  end
37
39
 
40
+ def store_cookies(cookies)
41
+ @cookies = cookies
42
+ @cookies_expires_at = Time.now + COOKIE_EXPTIRATION_TIMEOUT
43
+ end
44
+
45
+ def clear_cookies
46
+ @cookies = nil
47
+ @cookies_expires_at = nil
48
+ end
49
+
38
50
  end
39
- end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module TurboSMS
2
- VERSION = '0.1.2'
3
- end
2
+ VERSION = '0.1.3'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbosms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalik Danchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon