Class: Tappay::Client
- Inherits:
-
Object
- Object
- Tappay::Client
- Defined in:
- lib/tappay/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(url, data) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/tappay/client.rb', line 9 def initialize( = {}) @options = @timeout = .fetch(:timeout, 25) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/tappay/client.rb', line 7 def @options end |
Instance Method Details
#post(url, data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tappay/client.rb', line 14 def post(url, data) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.open_timeout = timeout http.read_timeout = timeout request = Net::HTTP::Post.new(uri.request_uri, headers) request.body = data.to_json @response = http.request(request) validate_response Response.new(@response) rescue Timeout::Error, Net::OpenTimeout, Net::ReadTimeout => e raise ConnectionError, "HTTP Request failed: #{e.}" end |