Class: ATS::HttpAPI
- Inherits:
-
Object
- Object
- ATS::HttpAPI
- Defined in:
- lib/ats/http_api.rb
Instance Method Summary collapse
- #execute(uri, request) ⇒ Object
- #get(uri, headers: {}, body: {}) ⇒ Object
-
#initialize(headers: {}, debug: false) ⇒ HttpAPI
constructor
A new instance of HttpAPI.
- #post(uri, headers: {}, body: {}) ⇒ Object
- #put(uri, headers: {}, body: {}) ⇒ Object
Constructor Details
#initialize(headers: {}, debug: false) ⇒ HttpAPI
Returns a new instance of HttpAPI.
3 4 5 6 |
# File 'lib/ats/http_api.rb', line 3 def initialize(headers: {}, debug: false) @default_headers = headers @debug = debug end |
Instance Method Details
#execute(uri, request) ⇒ Object
8 9 10 |
# File 'lib/ats/http_api.rb', line 8 def execute(uri, request) http_for(uri).request(request) end |
#get(uri, headers: {}, body: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/ats/http_api.rb', line 12 def get(uri, headers: {}, body: {}) request = get_for(uri, headers: headers, body: body) response = execute(uri, request) if block_given? yield request, response else response end end |
#post(uri, headers: {}, body: {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/ats/http_api.rb', line 22 def post(uri, headers: {}, body: {}) request = post_for(uri, headers: headers, body: body) response = execute(uri, request) if block_given? yield request, response else response end end |
#put(uri, headers: {}, body: {}) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/ats/http_api.rb', line 32 def put(uri, headers: {}, body: {}) request = put_for(uri, headers: headers, body: body) response = execute(uri, request) if block_given? yield request, response else response end end |