restclient_api_base 0.0.4 → 0.0.5

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: 509536339ef55a76d0ce5b2b79b4cf83aeeee644
4
- data.tar.gz: a7de0f09cb2b8ad99a2397ca5c543efa22d6ffdf
3
+ metadata.gz: e29b7b73cd034da75ef57895421cc66ce6bb1fdc
4
+ data.tar.gz: 308cc38dd40071562a17c39936da542828ed61b9
5
5
  SHA512:
6
- metadata.gz: 983a7ad03f32db52d26c32a472890779ef24cb033454985c046bcf83cb199a2dd52e1bf025e47e520728672dabd8792320f6d2a53d66b730bc55749e0970a9c9
7
- data.tar.gz: f16c6d7cf92360dbccb79355fbbba0b1adeaf97545083e45cdd8c7e4bfb02d93dad6372a709efdb850233f2ce1c1372dbde071f5913a35b3bcae86fd48447c9f
6
+ metadata.gz: 837736b116a6babaa088fffdb313d6dddbda2694bcdbd81e58465a855e689aa89cb78c042efe71a7e45d9f151a778b047153ca54a6aedc52ce4d1a2c7210a65d
7
+ data.tar.gz: 77e7cd4199a17a79e904076baf02243ea864eb16783fc7fedf5eb54470f618a689fa31d461653bfdd498151acdb1e77b98428fd6b6b142ee0027becb52ab2af3
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module RestclientApiBase
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require "restclient_api_base/version"
4
4
  require "json"
5
5
  require "rest-client"
6
+ require "logger"
6
7
 
7
8
  # For other framework except Rails
8
9
  begin
@@ -19,7 +20,7 @@ module RestclientApiBase
19
20
  # base_url: the api base url, like: http://api.example.com, default is ''
20
21
  # private_params: your api secret, like: { app_id: 'xxxx' }, default is {}
21
22
 
22
- attr_accessor :base_url, :private_params
23
+ attr_accessor :base_url, :private_params, :logger_name
23
24
 
24
25
  def get api_url, params = {}
25
26
  begin
@@ -95,5 +96,22 @@ module RestclientApiBase
95
96
  raise 'the private params must be a hash' unless params.is_a? Hash
96
97
  @private_params = params
97
98
  end
99
+
100
+ def logger_name
101
+ @logger_name ||= self.to_s + '::Error'
102
+ end
103
+
104
+ def write_log *args
105
+ log_tag = logger_name + '-' + Time.now.strftime('%Y-%m-%d %H:%M:%S')
106
+ if Object.const_defined? :Rails
107
+ Rails.logger.tagged(log_tag) do
108
+ Rails.logger.info(args.join('-'))
109
+ end
110
+ else
111
+ logger = Logger.new(STDOUT)
112
+ logger.info(log_tag + args.join('-'))
113
+ end
114
+ end
115
+
98
116
  end
99
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restclient_api_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spirit