Class: Formable::Http
- Inherits:
-
Object
- Object
- Formable::Http
- Defined in:
- lib/formable/http.rb
Instance Method Summary collapse
- #close ⇒ Object
- #get(path, query = {}) ⇒ Object
-
#initialize(api_key:, base_url: nil, timeout: 60, connection: nil) ⇒ Http
constructor
A new instance of Http.
- #post(path, body = nil) ⇒ Object
- #post_form(path, fields) ⇒ Object
- #put(path, body = nil) ⇒ Object
Constructor Details
#initialize(api_key:, base_url: nil, timeout: 60, connection: nil) ⇒ Http
Returns a new instance of Http.
9 10 11 12 13 14 15 |
# File 'lib/formable/http.rb', line 9 def initialize(api_key:, base_url: nil, timeout: 60, connection: nil) raise ArgumentError, "Formable API key is required" if api_key.nil? || api_key.strip.empty? @api_key = api_key @base_url = (base_url || DEFAULT_BASE_URL).sub(%r{/+\z}, "") @connection = connection || build_connection(timeout) end |
Instance Method Details
#close ⇒ Object
33 34 35 |
# File 'lib/formable/http.rb', line 33 def close @connection.close if @connection.respond_to?(:close) end |
#get(path, query = {}) ⇒ Object
17 18 19 |
# File 'lib/formable/http.rb', line 17 def get(path, query = {}) request(:get, path, query: query) end |
#post(path, body = nil) ⇒ Object
21 22 23 |
# File 'lib/formable/http.rb', line 21 def post(path, body = nil) request(:post, path, json: body) end |
#post_form(path, fields) ⇒ Object
29 30 31 |
# File 'lib/formable/http.rb', line 29 def post_form(path, fields) request(:post, path, form: fields) end |
#put(path, body = nil) ⇒ Object
25 26 27 |
# File 'lib/formable/http.rb', line 25 def put(path, body = nil) request(:put, path, json: body) end |