Class: Editframe::APIResource
- Inherits:
-
Object
- Object
- Editframe::APIResource
- Defined in:
- lib/editframe/api_resource.rb
Direct Known Subclasses
Class Method Summary collapse
- .all ⇒ Object
- .base_url ⇒ Object
- .find(identifier) ⇒ Object
- .perform_get_request(url = '', params: {}, options: {}) ⇒ Object
- .perform_post_request(url = '', body: {}, options: {}, is_form: false) ⇒ Object
- .retrieve_headers ⇒ Object
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/editframe/api_resource.rb', line 10 def self.all perform_get_request()['data'] end |
.base_url ⇒ Object
6 7 8 |
# File 'lib/editframe/api_resource.rb', line 6 def self.base_url "https://#{Editframe::api_host}/v#{Editframe::api_version}/#{self::OBJECT_PATH}" end |
.find(identifier) ⇒ Object
14 15 16 |
# File 'lib/editframe/api_resource.rb', line 14 def self.find(identifier) perform_get_request("#{identifier}")['data'] end |
.perform_get_request(url = '', params: {}, options: {}) ⇒ Object
18 19 20 21 |
# File 'lib/editframe/api_resource.rb', line 18 def self.perform_get_request(url = '', params: {}, options: {}) response = Faraday.new(url: base_url, params: params, headers: retrieve_headers).get(url) JSON.parse(response.body) end |
.perform_post_request(url = '', body: {}, options: {}, is_form: false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/editframe/api_resource.rb', line 23 def self.perform_post_request(url = '', body: {}, options: {}, is_form: false) headers = retrieve_headers request = Faraday.new(url: base_url, headers: headers) if is_form headers.delete('Accept') headers.delete('Content-Type') request = Faraday.new(url: base_url, headers: headers) do |f| f.request :multipart end end request = request.post(url, body) JSON.parse(request.body) end |
.retrieve_headers ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/editframe/api_resource.rb', line 37 def self.retrieve_headers headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{Editframe::api_key}", 'Editframe-Client-Id' => "#{Editframe.client_id}" } headers end |