Class: ShiftPlanning::Interface
- Defined in:
- lib/shiftplanning/interface.rb
Instance Attribute Summary collapse
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#last_response_raw ⇒ Object
readonly
Returns the value of attribute last_response_raw.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Attributes inherited from Config
Instance Method Summary collapse
-
#initialize(api_key, options = {}) ⇒ Interface
constructor
**********************************.
-
#submit(*args) ⇒ Object
**********************************.
Constructor Details
#initialize(api_key, options = {}) ⇒ Interface
**********************************
29 30 31 32 33 34 |
# File 'lib/shiftplanning/interface.rb', line 29 def initialize api_key, = {} super(api_key, ) @request = Net::HTTP::Post.new(@@api_path) @last_response = nil @last_request = nil end |
Instance Attribute Details
#last_request ⇒ Object
Returns the value of attribute last_request.
26 27 28 |
# File 'lib/shiftplanning/interface.rb', line 26 def last_request @last_request end |
#last_response ⇒ Object
Returns the value of attribute last_response.
26 27 28 |
# File 'lib/shiftplanning/interface.rb', line 26 def last_response @last_response end |
#last_response_raw ⇒ Object (readonly)
Returns the value of attribute last_response_raw.
26 27 28 |
# File 'lib/shiftplanning/interface.rb', line 26 def last_response_raw @last_response_raw end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
26 27 28 |
# File 'lib/shiftplanning/interface.rb', line 26 def requests @requests end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
26 27 28 |
# File 'lib/shiftplanning/interface.rb', line 26 def responses @responses end |
Instance Method Details
#submit(*args) ⇒ Object
**********************************
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/shiftplanning/interface.rb', line 37 def submit *args @requests = []; @responses = [] msgs = [] resp = [] args.each{ |_request| _request.params[:module] = _request.module _request.params[:method] = _request.method req = {:key => api_key, :output => output, :request => _request.params} req[:token] = token unless token.nil? @requests << req req = JSON::generate(req) self.last_request = req#_request.to_json request.set_form_data({"data" => req}) response = @@http.request(request) @last_response_raw = response if http_error?(response) raise HTTPError, response.code else (output == 'json' ? (self.last_response = JSON.parse(response.body); @responses << JSON.parse(response.body)) : (self.last_response = response.body; @responses << response.body) ) @session[:sp_token] = last_response['token'] if(output == 'json' && @session != nil) self.token = last_response['token'] if output == 'json' self.token = @session[:sp_token] unless @session.nil? msgs << response_msg(last_response['status']) if output == 'json' resp << self.last_response end } return resp, msgs end |