Class: Octadesk::Api
- Inherits:
-
Object
- Object
- Octadesk::Api
- Defined in:
- lib/octadesk.rb
Instance Attribute Summary collapse
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
- #delete_request(action, params = {}, headers = {}) ⇒ Object
- #get_request(action, params = {}, headers = {}) ⇒ Object
- #head_request(action, params = {}, headers = {}) ⇒ Object
-
#initialize(args = {}) ⇒ Api
constructor
Aqui nós recebemos a chave da Api quando o usuário inicializa a nossa classe.
- #patch_request(action, params = {}, headers = {}) ⇒ Object
- #post_request(action, params = {}, headers = {}) ⇒ Object
- #put_request(action, params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Api
Aqui nós recebemos a chave da Api quando o usuário inicializa a nossa classe
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/octadesk.rb', line 11 def initialize(args={}) @user_email = args[:user_email] @api_token = args[:api_token] raise ArgumentError if (args[:user_email] == nil or args[:user_email] == "") and (args[:api_token] == nil or args[:api_token] == "") if args[:endpoint_url] @endpoint_url = args[:endpoint_url] else @endpoint_url = 'https://api.octadesk.services' end @user_token = get_token(@user_email).body['token'] #raise ArgumentError if @token == false end |
Instance Attribute Details
#user_token ⇒ Object
Returns the value of attribute user_token.
8 9 10 |
# File 'lib/octadesk.rb', line 8 def user_token @user_token end |
Instance Method Details
#delete_request(action, params = {}, headers = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/octadesk.rb', line 117 def delete_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.delete("#{@endpoint_url}#{action}", params)) rescue => e parse_response('object', e.response) end end |
#get_request(action, params = {}, headers = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/octadesk.rb', line 27 def get_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers))) rescue => e parse_response('object', e.response) end end |
#head_request(action, params = {}, headers = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/octadesk.rb', line 99 def head_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.head("#{@endpoint_url}#{action}", params)) rescue => e parse_response('object', e.response) end end |
#patch_request(action, params = {}, headers = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/octadesk.rb', line 81 def patch_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.patch("#{@endpoint_url}#{action}", params, headers)) rescue => e parse_response('object', e.response) end end |
#post_request(action, params = {}, headers = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/octadesk.rb', line 45 def post_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.post("#{@endpoint_url}#{action}", params, headers)) rescue => e parse_response('object', e.response) end end |
#put_request(action, params = {}, headers = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/octadesk.rb', line 63 def put_request(action, params={}, headers={}) begin headers = headers.merge({ 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@user_token}" }) api_response_kind = headers.delete('api_response_kind') api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil? api_response_kind = 'object' if api_response_kind.nil? parse_response(api_response_kind, RestClient.put("#{@endpoint_url}#{action}", params, headers)) rescue => e parse_response('object', e.response) end end |