Class: ShiftPlanning::Connection
- Inherits:
-
Object
- Object
- ShiftPlanning::Connection
- Defined in:
- lib/shift_planning/connection.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
- #call(method, command, params = {}) ⇒ Object
-
#initialize(key) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(key) ⇒ Connection
Returns a new instance of Connection.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/shift_planning/connection.rb', line 4 def initialize(key) @key = key @token = nil @http = Faraday.new(url: "http://www.shiftplanning.com") do |conn| conn.request :url_encoded conn.response :json conn.response :logger conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
2 3 4 |
# File 'lib/shift_planning/connection.rb', line 2 def http @http end |
Instance Method Details
#call(method, command, params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shift_planning/connection.rb', line 17 def call(method, command, params = {}) request_params = { request: params.merge( method: method, module: command ), output: 'json' } response = http.post('/api/', data: JSON::generate(signed_params(request_params))).body ShiftPlanning::ApiError.parse(response['status']) parse_data response do |data| @token = data['token'] if data.has_key?('token') end end |