Module: EDH::Passport::RestAPIMethods
- Included in:
- API
- Defined in:
- lib/edh/api/rest_api.rb
Overview
Methods used to interact with Passport’s REST API.
Instance Method Summary collapse
-
#create(pp_method, args = {}, options = {}) ⇒ Object
convenience methods.
- #delete(pp_action_uid, args = {}, options = {}) ⇒ Object
-
#rest_call(pp_method, args = {}, options = {}, verb = "get") ⇒ Object
Make a call to the REST API.
- #update(pp_action_uid, args = {}, options = {}) ⇒ Object
Instance Method Details
#create(pp_method, args = {}, options = {}) ⇒ Object
convenience methods
9 10 11 |
# File 'lib/edh/api/rest_api.rb', line 9 def create pp_method, args = {}, = {} rest_call("me/#{pp_method}", args, , :post) end |
#delete(pp_action_uid, args = {}, options = {}) ⇒ Object
13 14 15 |
# File 'lib/edh/api/rest_api.rb', line 13 def delete pp_action_uid, args = {}, = {} rest_call("actions/#{pp_action_uid}", args, , :delete) end |
#rest_call(pp_method, args = {}, options = {}, verb = "get") ⇒ Object
Note:
The order of the last two arguments is non-standard (for historical reasons). Sorry.
Make a call to the REST API.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/edh/api/rest_api.rb', line 30 def rest_call(pp_method, args = {}, = {}, verb = "get") args = MultiJson.load(args) if args.is_a?(String) api("#{pp_method}", args.merge('format' => 'json'), verb, ) do |response| # check for REST API-specific errors if response.status >= 400 begin response_hash = MultiJson.load(response.body) rescue MultiJson::DecodeError response_hash = {} end error_info = { 'code' => response_hash['error_code'], 'error_subcode' => response_hash['error_subcode'], 'message' => response_hash['error_msg'] } if response.status >= 500 raise ServerError.new(response.status, response.body, error_info) else raise ClientError.new(response.status, response.body, error_info) end end end end |
#update(pp_action_uid, args = {}, options = {}) ⇒ Object
17 18 19 |
# File 'lib/edh/api/rest_api.rb', line 17 def update pp_action_uid, args = {}, = {} rest_call("actions/#{pp_action_uid}", args, , :put) end |