steam_fi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/steam_fi/api.rb +57 -50
- data/lib/steam_fi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b917587d22dd4d7c0a28e3b52304256b2f226d0e
|
4
|
+
data.tar.gz: 1fa1a45fe9b6d08bafdbe45caad67a63e9c605cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce68680bce0745ddf74c7ad9686c7928a948376c148c651e22daa6c89dde6e14b38f48859dbcea176fc454ba050bf28e13c1f579989786ccec8e4108d6f007ab
|
7
|
+
data.tar.gz: 5e28752b7b618d47a99f8ee6a09e71085533e4cc27e3f18964359a769a6bd688fc21c9f868328ed4a97d4a4001e59f244e078637bdbf72f3f4247ef3c09eefaa
|
data/README.md
CHANGED
data/lib/steam_fi/api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
5
|
module SteamFi
|
5
6
|
class API
|
@@ -9,61 +10,67 @@ module SteamFi
|
|
9
10
|
:username => nil,
|
10
11
|
:password => nil
|
11
12
|
}
|
13
|
+
|
14
|
+
@@logger = nil
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# Set configuration parameters
|
19
|
-
def self.setup(options)
|
20
|
-
@@config.merge!(options)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Send SMS message
|
24
|
-
def self.send_sms(msisdn, message, params = {})
|
25
|
-
params.merge! :msisdn => msisdn, :msg => message
|
26
|
-
self.request @@config[:sms_url], params
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
# Send request
|
32
|
-
def self.request(url, params = {})
|
33
|
-
# add username & password
|
34
|
-
params.merge! :l => @@config[:username], :p => @@config[:password]
|
16
|
+
class << self
|
17
|
+
def setup(options)
|
18
|
+
@@config.merge!(options)
|
19
|
+
end
|
35
20
|
|
36
|
-
|
21
|
+
# Send SMS message
|
22
|
+
def send_sms(msisdn, message, params = {})
|
23
|
+
params.merge! :msisdn => msisdn, :msg => message
|
24
|
+
request @@config[:sms_url], params
|
25
|
+
end
|
37
26
|
|
38
|
-
|
39
|
-
|
40
|
-
uri = URI.parse(url)
|
41
|
-
req = Net::HTTP::Post.new(uri.path)
|
42
|
-
|
43
|
-
req.set_form_data(params)
|
44
|
-
req.initialize_http_header({
|
45
|
-
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
|
46
|
-
})
|
47
|
-
|
48
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
49
|
-
http.use_ssl = (uri.port == 443)
|
50
|
-
res = http.request(req)
|
51
|
-
rescue Exception => e
|
52
|
-
self.handle_error e
|
27
|
+
def logger
|
28
|
+
@@logger
|
53
29
|
end
|
30
|
+
|
31
|
+
def logger=(logger)
|
32
|
+
@@logger = logger
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
# Send request
|
38
|
+
def request(url, params = {})
|
39
|
+
# add username & password
|
40
|
+
params.merge! :l => @@config[:username], :p => @@config[:password]
|
54
41
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
42
|
+
logger.info "#{Time.now} REQUEST\n#{url}\n#{params.to_yaml}" if logger
|
43
|
+
|
44
|
+
begin
|
45
|
+
# build & send request
|
46
|
+
uri = URI.parse(url)
|
47
|
+
req = Net::HTTP::Post.new(uri.path)
|
48
|
+
|
49
|
+
req.set_form_data(params)
|
50
|
+
req.initialize_http_header({
|
51
|
+
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
|
52
|
+
})
|
53
|
+
|
54
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
55
|
+
http.use_ssl = (uri.port == 443)
|
56
|
+
res = http.request(req)
|
57
|
+
rescue Exception => e
|
58
|
+
handle_error e
|
59
|
+
end
|
60
|
+
|
61
|
+
case res
|
62
|
+
when Net::HTTPSuccess
|
63
|
+
logger.info "#{Time.now} RESPONSE\n#{res.body}" if logger
|
64
|
+
res.body
|
65
|
+
else
|
66
|
+
handle_error SteamFi::SteamException.new(res.inspect)
|
67
|
+
end
|
61
68
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
69
|
+
|
70
|
+
def handle_error(e)
|
71
|
+
logger.error "#{Time.now} ERROR\n#{e.message}" if logger
|
72
|
+
raise SteamFi::SteamException.new(e.message)
|
73
|
+
end
|
74
|
+
end
|
68
75
|
end
|
69
76
|
end
|
data/lib/steam_fi/version.rb
CHANGED