Class: Coach4rb::Client
- Inherits:
-
Object
- Object
- Coach4rb::Client
- Defined in:
- lib/coach4rb/client.rb
Overview
This class provides a simple http client.
Instance Method Summary (collapse)
-
- (String) delete(url, options = {}, &block)
Performs a delete request.
-
- (String) get(url, options = {}, &block)
Performs a get request.
- - (Object) host
-
- (Client) initialize(a_hash)
constructor
A new instance of Client.
- - (Object) path
- - (Object) port
-
- (String) post(url, payload, options = {}, &block)
Performs a post request.
-
- (String) put(url, payload, options = {}, &block)
Performs a put request.
- - (Object) scheme
- - (Object) service_uri
- - (Object) site
Constructor Details
- (Client) initialize(a_hash)
Returns a new instance of Client
8 9 10 11 12 13 14 |
# File 'lib/coach4rb/client.rb', line 8 def initialize(a_hash) @service_uri = Addressable::URI.new a_hash @basic_options = { accept: :json, content_type: :xml } end |
Instance Method Details
- (String) delete(url, options = {}, &block)
Performs a delete request.
105 106 107 108 109 110 111 112 |
# File 'lib/coach4rb/client.rb', line 105 def delete(url, ={}, &block) = .merge(@basic_options) if block_given? RestClient.delete(url, , &block) else RestClient.delete(url, ) end end |
- (String) get(url, options = {}, &block)
Performs a get request.
53 54 55 56 57 58 59 60 |
# File 'lib/coach4rb/client.rb', line 53 def get(url, ={}, &block) = .merge(@basic_options) if block_given? RestClient.get(url, , &block) else RestClient.get(url, ) end end |
- (Object) host
37 38 39 |
# File 'lib/coach4rb/client.rb', line 37 def host @service_uri.host end |
- (Object) path
22 23 24 |
# File 'lib/coach4rb/client.rb', line 22 def path @service_uri.path end |
- (Object) port
32 33 34 |
# File 'lib/coach4rb/client.rb', line 32 def port @service_uri.port end |
- (String) post(url, payload, options = {}, &block)
Performs a post request.
88 89 90 91 92 93 94 95 |
# File 'lib/coach4rb/client.rb', line 88 def post(url, payload, ={}, &block) = .merge(@basic_options) if block_given? RestClient.post(url, payload, , &block) else RestClient.post(url, payload, ) end end |
- (String) put(url, payload, options = {}, &block)
Performs a put request.
70 71 72 73 74 75 76 77 78 |
# File 'lib/coach4rb/client.rb', line 70 def put(url, payload, ={}, &block) = .merge(@basic_options) if block_given? RestClient.put(url, payload, , &block) else RestClient.put(url, payload, ) end end |
- (Object) scheme
42 43 44 |
# File 'lib/coach4rb/client.rb', line 42 def scheme @service_uri.scheme end |
- (Object) service_uri
17 18 19 |
# File 'lib/coach4rb/client.rb', line 17 def service_uri @service_uri end |
- (Object) site
27 28 29 |
# File 'lib/coach4rb/client.rb', line 27 def site @service_uri.site end |