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.
5 6 7 8 |
# File 'lib/ats/http_api.rb', line 5 def initialize(headers: {}, debug: false) @default_headers = headers @debug = debug end |
Instance Method Details
#execute(uri, request) ⇒ Object
10 11 12 |
# File 'lib/ats/http_api.rb', line 10 def execute(uri, request) http_for(uri).request(request) end |
#get(uri, headers: {}, body: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ats/http_api.rb', line 14 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
24 25 26 27 28 29 30 31 32 |
# File 'lib/ats/http_api.rb', line 24 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
34 35 36 37 38 39 40 41 42 |
# File 'lib/ats/http_api.rb', line 34 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 |