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 +4 -4
- data/lib/restclient_api_base/version.rb +1 -1
- data/lib/restclient_api_base.rb +19 -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: e29b7b73cd034da75ef57895421cc66ce6bb1fdc
|
4
|
+
data.tar.gz: 308cc38dd40071562a17c39936da542828ed61b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837736b116a6babaa088fffdb313d6dddbda2694bcdbd81e58465a855e689aa89cb78c042efe71a7e45d9f151a778b047153ca54a6aedc52ce4d1a2c7210a65d
|
7
|
+
data.tar.gz: 77e7cd4199a17a79e904076baf02243ea864eb16783fc7fedf5eb54470f618a689fa31d461653bfdd498151acdb1e77b98428fd6b6b142ee0027becb52ab2af3
|
data/lib/restclient_api_base.rb
CHANGED
@@ -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
|