Class: Testin::Network
- Inherits:
-
Object
- Object
- Testin::Network
- Defined in:
- lib/testin.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Network
constructor
A new instance of Network.
- #request ⇒ Object
- #validation_response(response_data) ⇒ Object
Constructor Details
#initialize(options) ⇒ Network
Returns a new instance of Network.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/testin.rb', line 29 def initialize() = = { request: { timeout: 30, open_timeout: 300 }, #proxy: "http://127.0.0.1:8888" # for debug } @testin_client = Faraday.new(self.class.testin_hostname, ) do |c| c.request :url_encoded c.adapter :net_http c.response :json, :content_type => /\bjson$/ end end |
Class Method Details
.testin_hostname ⇒ Object
25 26 27 |
# File 'lib/testin.rb', line 25 def self.testin_hostname "http://fileupload.pro.testin.cn" end |
Instance Method Details
#request ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/testin.rb', line 47 def request path = '' @testin_client.post do |req| req.url path req.headers['Host'] = 'openapi.pro.testin.cn' req.headers['Content-Type'] = 'text/plain' req.body = [:param].to_json end end |
#validation_response(response_data) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/testin.rb', line 57 def validation_response response_data error_code = response_data['code'].to_i return if error_code.zero? raise 'validation_response error' if response_data['msg'].empty? raise response_data['msg'] end |