Class: TodaysPlan::Connector
- Inherits:
-
Object
- Object
- TodaysPlan::Connector
- Defined in:
- lib/todays_plan/connector.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#get ⇒ Object
Internal: Run GET request.
-
#initialize(path, client = nil) ⇒ Connector
constructor
A new instance of Connector.
-
#post(payload = {}) ⇒ Object
Internal: Run GET request.
Constructor Details
#initialize(path, client = nil) ⇒ Connector
Returns a new instance of Connector.
5 6 7 8 9 |
# File 'lib/todays_plan/connector.rb', line 5 def initialize(path, client = nil) @client = client || Client.new(TodaysPlan.username, TodaysPlan.password) @uri = TodaysPlan.endpoint + path @timeout = TodaysPlan.timeout end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/todays_plan/connector.rb', line 3 def body @body end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/todays_plan/connector.rb', line 3 def client @client end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/todays_plan/connector.rb', line 3 def response @response end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/todays_plan/connector.rb', line 3 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/todays_plan/connector.rb', line 3 def uri @uri end |
Instance Method Details
#get ⇒ Object
Internal: Run GET request.
Returns the parsed JSON response body.
14 15 16 17 18 19 20 |
# File 'lib/todays_plan/connector.rb', line 14 def get() ={ method: :get, headers:{ accept: :json} } run() end |
#post(payload = {}) ⇒ Object
Internal: Run GET request.
Returns the parsed JSON response body.
25 26 27 28 29 30 31 |
# File 'lib/todays_plan/connector.rb', line 25 def post(payload = {}) ={method: :post, payload: payload, headers:{content_type: :json, accept: :json} } run() end |