rong_cloud_server 0.2.0 → 0.2.1

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: a8851d724f0063d44b4baec6498e55dbcb584ce2
4
- data.tar.gz: 46cbca45d889185c5e3a2062c17d99f9d8a7df83
3
+ metadata.gz: 6be41c66282f7b2fede5bdcb34a09f19147480db
4
+ data.tar.gz: a9359a4d519e77a867bf10d32d484ec4629f743a
5
5
  SHA512:
6
- metadata.gz: f8f62f13ef18c5c4541c34fae5df6969c73855f9955b910ebc1c3955d2688e0892dabe8d2a077bb8685bf9f7d805f082c1a0f214539448a81b2835415d5cfe97
7
- data.tar.gz: 994b4805135d4b3113cf2638ad072f28fd9293be0329f3c61d5d048830f32e6e6f9f4f8a4f22bbcca330f8e60d978a142d7becf41f08baec84b9b39a9c5d9b09
6
+ metadata.gz: 3ef454bbea716cdebfcbfb9c603f2771111354f3aeb7618f8466828f47f547648ddd93d5ed554a68e4b389f8ec2c2037439c303111562d32700a0d7455e541bc
7
+ data.tar.gz: 409b2fc2ebb46cebaa8cc15251209c33365ccb45c2006855584ea226996b9951fab689186c2bf81f3de879e90a2af50cd4d00eedc4ba9bcb01461ee86347ea59
data/.gitignore CHANGED
@@ -3,4 +3,5 @@ rong_cloud.log
3
3
  /doc
4
4
  .yardoc/
5
5
  Gemfile.lock
6
- coverage/
6
+ coverage/
7
+ log/
data/README.md CHANGED
@@ -28,6 +28,8 @@ This repository implements most essential apis for [RongCloud Server API](http:/
28
28
  config.app_key = "APP_KEY"
29
29
  config.app_secret = "SECRET_KEY"
30
30
  # config.host = "http://api.cn.ronghub.com" # default: https://api.cn.ronghub.com, use http here is just convenient for debugging
31
+ # config.timeout = 10 # set open timeout and read timeout in seconds for http request, default is 2 seconds
32
+ # config.debug_mode = true # if need to log request and response details, the log file is at "log/rong_cloud_debug.log", default is `false`
31
33
  end
32
34
  ```
33
35
  3. Use the instance of `RongCloud::Service` to talk to RongCloud Server:
@@ -57,7 +59,4 @@ ruby -Ilib -Itest -e 'ARGV.each { |f| require f }' ./test/**/*_test.rb
57
59
  ### How to contribute
58
60
  1. Fork this repo;
59
61
  2. Write your code and test;
60
- 3. Open a new Pull Request.
61
-
62
- ### TODO
63
- 1. Logger support
62
+ 3. Open a new Pull Request.
@@ -7,10 +7,11 @@ module RongCloud
7
7
  # The default host to accept connections, use a https protocol
8
8
  DEFAULT_HOST = "https://api.cn.ronghub.com".freeze
9
9
  DEFAULT_TIMEOUT = 2
10
+ DEFAULT_DEBUG_MODE = false
10
11
 
11
12
  module ModuleMethods
12
13
  attr_accessor :app_key, :app_secret
13
- attr_writer :host, :timeout
14
+ attr_writer :host, :timeout, :debug_mode
14
15
 
15
16
  # Fetch the api host, the default is: https://api.cn.ronghub.com
16
17
  #
@@ -21,6 +22,10 @@ module RongCloud
21
22
  def timeout
22
23
  @timeout || DEFAULT_TIMEOUT
23
24
  end
25
+
26
+ def debug_mode
27
+ @debug_mode || DEFAULT_DEBUG_MODE
28
+ end
24
29
  end
25
30
  extend ModuleMethods
26
31
  end
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'rong_cloud/signature'
4
+ require 'logger'
4
5
 
5
6
  module RongCloud
6
7
  # Handle api request, based on Ruby's built-in Net::HTTP,
@@ -23,9 +24,11 @@ module RongCloud
23
24
  request_options = { use_ssl: use_ssl, open_timeout: timeout, read_timeout: timeout }
24
25
 
25
26
  res = Net::HTTP.start(uri.hostname, uri.port, request_options) do |http|
27
+ inspect_debug_informations(req, uri, request_options)
26
28
  http.request(req)
27
29
  end
28
30
 
31
+ inspect_debug_informations(res)
29
32
  handle_response(res)
30
33
  end
31
34
 
@@ -79,5 +82,29 @@ module RongCloud
79
82
  raise error
80
83
  end
81
84
  end
85
+
86
+ def inspect_debug_informations(*objects)
87
+ return unless RongCloud::Configuration.debug_mode
88
+
89
+ objects.each do |obj|
90
+ begin
91
+ case
92
+ when obj.is_a?(URI::Generic)
93
+ logger.debug("Requesting #{obj.hostname}:#{obj.port}")
94
+ when obj.is_a?(Net::HTTPGenericRequest)
95
+ logger.debug("request method: #{obj.method}, headers: #{obj.to_hash}, raw body: #{obj.body}")
96
+ when obj.is_a?(Net::HTTPResponse)
97
+ logger.debug("response headers: #{obj.to_hash}, raw body: #{obj.body}")
98
+ else
99
+ logger.debug(obj.inspect)
100
+ end
101
+ rescue
102
+ end
103
+ end
104
+ end
105
+
106
+ def logger
107
+ @logger ||= ::Logger.new("log/rong_cloud_debug.log")
108
+ end
82
109
  end
83
110
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.require_path = 'lib'
5
5
  s.summary = 'RongCloud Server API SDK'
6
6
  s.description = 'RongCloud Server API in Ruby,http://www.rongcloud.cn/docs/server.html'
7
- s.version = '0.2.0'
7
+ s.version = '0.2.1'
8
8
  s.files = `git ls-files`.split("\n")
9
9
  s.authors = ['Martin Hong']
10
10
  s.email = 'hongzeqin@gmail.com'
@@ -14,6 +14,7 @@ end
14
14
  require 'minitest/autorun'
15
15
  require 'byebug'
16
16
  require 'rong_cloud'
17
+ require 'fileutils'
17
18
 
18
19
  def rong_cloud_configure_with_settings
19
20
  RongCloud.configure do |config|
@@ -21,5 +22,8 @@ def rong_cloud_configure_with_settings
21
22
  config.app_secret = ENV["RONGCLOUD_APP_SECRET"]
22
23
  config.host = ENV["RONGCLOUD_API_HOST"] || "https://api.cn.ronghub.com"
23
24
  config.timeout = 10
25
+ config.debug_mode = true
26
+
27
+ FileUtils.mkdir_p "log/"
24
28
  end
25
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rong_cloud_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Hong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-10 00:00:00.000000000 Z
11
+ date: 2018-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest