Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"$id"=>"1", "Message"=>"Authorization has been denied for this request."}
- # Service object
- class Abc
- include HTTParty
- base_uri 'api.thirdparty.com'
- def questions
- result = self.class.post("/end_point/of/third/party/", body: {key: value,...})
- result # error in result : {"$id"=>"1", "Message"=>"Authorization has been denied for this request."}
- end
- end
- # request header
- {
- content-type:"application/json"
- cache-control:"no-cache"
- postman-token:"94a40ead-1e76-41ab-9563-172f656f213a"
- user-agent:"PostmanRuntime/7.1.5"
- accept:"*/*"
- host:"happiness.com"
- accept-encoding:"gzip, deflate"
- content-length:137
- }
- # Request body
- {
- password:"1234567890"
- password_confirmation:"1234567890"
- approve_policy:true
- telephone:"xx832xxxxxxx"
- step:4
- }
- # Response header
- {
- content-type:"application/json; charset=utf-8"
- transfer-encoding:"chunked"
- connection:"keep-alive"
- status:"200 OK"
- cache-control:"max-age=0, private, must-revalidate"
- strict-transport-security:"max-age=15552000; includeSubDomains"
- x-request-id:"e11c82ed-e828-4c5e-b8b9-ae477be18a81"
- etag:"W/"1eca77bcc78b5bada08cb47c78aa04e1""
- x-runtime:"0.789290"
- date:"Fri, 01 Jun 2018 10:32:47 GMT"
- x-powered-by:"Phusion Passenger 5.2.3"
- server:"nginx/1.12.2 + Phusion Passenger 5.2.3"
- }
- # Response body (customized)
- {
- status:"0"
- status_code:422
- message:"Authorization has been denied for this request."
- }
- # app/lib/connection.rb
- class Connection
- include HTTParty
- base_uri "https://anotherserver.com"
- def register
- response = HTTParty.post('/api/tenantAccounts/', body: create_request_body, headers: auth_header)
- response # <= {"$id"=>"1", "Message"=>"Authorization has been denied for this request."}
- end
- def request_body
- {
- "accountPassword": "123456",
- "tenantAccountCode": "prod-dr104",
- "accountUserName": "jignesh-khokhani-104",
- "accountLockStatus": 0,
- "loginFailNum": 0,
- "birthDate": "Sun, 01 Jun 1958 19:25:16 JST +09:00",
- "restingHr": 80,
- "maxHr": 160,
- "normalHr": 100,
- "upperLimitHr": 180,
- "lowerLimitHr": 60,
- "durationHr": 60,
- "duration180Hs": 60,
- "duration220Hs": 60,
- "thresholdDurationHs": 60,
- "thresholdDurationWs": 60,
- "imageFlg": "0",
- "createAccountId": "10003608"
- }
- end
- private
- def auth_header
- {
- 'Authorization': "bearer #{auth_details.access_token}"
- }
- end
- def auth_details
- # 3rd party server login and get token
- HTTParty.post('/login', {
- body: {
- username: 'username',
- password: 'secret_password,
- scope: 'scope',
- grant_type: 'password'
- }
- })
- end
- end
Add Comment
Please, Sign In to add comment