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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 958b4b84c5a4e2e65facedc3b8fa607d3bb98aac
4
- data.tar.gz: 3d8dea1b4eec8bac87ea155a1fbfe084a19a5651
3
+ metadata.gz: b917587d22dd4d7c0a28e3b52304256b2f226d0e
4
+ data.tar.gz: 1fa1a45fe9b6d08bafdbe45caad67a63e9c605cf
5
5
  SHA512:
6
- metadata.gz: 81870bff0f0c41095e0faf79c75bd5ec815d0b1862f9b7c24ff6b0f9117ae58d21ed79f03f9099340aa3f134506ccd5d5ec17866cf51b9f8a5c69a9e3f5f9eeb
7
- data.tar.gz: d7436984354f36d363da82e21925a1862fdba0c170992587c14d7891b911d40a5e9f68b02578199c231a30ea0e3b5d698954f62bf740247928f2602757ca6cf4
6
+ metadata.gz: ce68680bce0745ddf74c7ad9686c7928a948376c148c651e22daa6c89dde6e14b38f48859dbcea176fc454ba050bf28e13c1f579989786ccec8e4108d6f007ab
7
+ data.tar.gz: 5e28752b7b618d47a99f8ee6a09e71085533e4cc27e3f18964359a769a6bd688fc21c9f868328ed4a97d4a4001e59f244e078637bdbf72f3f4247ef3c09eefaa
data/README.md CHANGED
@@ -35,6 +35,12 @@ Send SMS:
35
35
  SteamFi::API.send_sms('1234PHONE', 'Hello world')
36
36
  ```
37
37
 
38
+ Set logger:
39
+
40
+ ```ruby
41
+ SteamFi::API.logger = MyLogger.new
42
+ ```
43
+
38
44
  ## Contributing
39
45
 
40
46
  1. Fork it ( https://github.com/[my-github-username]/steam_fi/fork )
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
- cattr_accessor :logger
14
-
15
- # Logger
16
- @@logger = Logger.new File.join(RAILS_ROOT, '/log/', "steam_fi_#{RAILS_ENV}.log")
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
- @@logger.info "#{Time.now} REQUEST\n#{url}\n#{params.to_yaml}"
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
- begin
39
- # build & send request
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
- case res
56
- when Net::HTTPSuccess
57
- @@logger.info "#{Time.now} RESPONSE\n#{res.body}"
58
- res.body
59
- else
60
- self.handle_error SteamFi::SteamException.new(res.inspect)
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
- end
63
-
64
- def self.handle_error(e)
65
- @@logger.error "#{Time.now} ERROR\n#{e.message}"
66
- raise SteamFi::SteamException.new(e.message)
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
@@ -1,3 +1,3 @@
1
1
  module SteamFi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steam_fi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurynas Butkus