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
-
#delete(url, options = {}, &block) ⇒ String
Performs a delete request.
-
#get(url, options = {}, &block) ⇒ String
Performs a get request.
- #host ⇒ Object
-
#initialize(a_hash) ⇒ Client
constructor
A new instance of Client.
- #path ⇒ Object
- #port ⇒ Object
-
#post(url, payload, options = {}, &block) ⇒ String
Performs a post request.
-
#put(url, payload, options = {}, &block) ⇒ String
Performs a put request.
- #scheme ⇒ Object
- #service_uri ⇒ Object
- #site ⇒ Object
Constructor Details
#initialize(a_hash) ⇒ Client
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
#delete(url, options = {}, &block) ⇒ String
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 |
#get(url, options = {}, &block) ⇒ String
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 |
#host ⇒ Object
37 38 39 |
# File 'lib/coach4rb/client.rb', line 37 def host @service_uri.host end |
#path ⇒ Object
22 23 24 |
# File 'lib/coach4rb/client.rb', line 22 def path @service_uri.path end |
#port ⇒ Object
32 33 34 |
# File 'lib/coach4rb/client.rb', line 32 def port @service_uri.port end |
#post(url, payload, options = {}, &block) ⇒ String
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 |
#put(url, payload, options = {}, &block) ⇒ String
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 |
#scheme ⇒ Object
42 43 44 |
# File 'lib/coach4rb/client.rb', line 42 def scheme @service_uri.scheme end |
#service_uri ⇒ Object
17 18 19 |
# File 'lib/coach4rb/client.rb', line 17 def service_uri @service_uri end |
#site ⇒ Object
27 28 29 |
# File 'lib/coach4rb/client.rb', line 27 def site @service_uri.site end |