Class: TodaysPlan::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/todays_plan/connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/todays_plan/connector.rb', line 3

def body
  @body
end

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/todays_plan/connector.rb', line 3

def client
  @client
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/todays_plan/connector.rb', line 3

def response
  @response
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



3
4
5
# File 'lib/todays_plan/connector.rb', line 3

def timeout
  @timeout
end

#uriObject (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

#getObject

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()
  options={
    method: :get, 
    headers:{ accept: :json}
  }
  run(options)
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 = {})
  options={method: :post, 
    payload: payload, 
    headers:{content_type: :json, accept: :json}
  }
  run(options)
end