Class: TRMNLP::APIClient
- Inherits:
-
Object
- Object
- TRMNLP::APIClient
- Defined in:
- lib/trmnlp/api_client.rb
Instance Method Summary collapse
- #delete_plugin_setting(id) ⇒ Object
- #get_plugin_setting_archive(id) ⇒ Object
-
#initialize(config) ⇒ APIClient
constructor
A new instance of APIClient.
- #post_plugin_setting(params) ⇒ Object
- #post_plugin_setting_archive(id, path) ⇒ Object
Constructor Details
#initialize(config) ⇒ APIClient
Returns a new instance of APIClient.
8 9 10 |
# File 'lib/trmnlp/api_client.rb', line 8 def initialize(config) @config = config end |
Instance Method Details
#delete_plugin_setting(id) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/trmnlp/api_client.rb', line 56 def delete_plugin_setting(id) response = conn.delete("plugin_settings/#{id}") if response.status == 204 true else raise Error, "failed to delete plugin setting: #{response.status} #{response.body}" end end |
#get_plugin_setting_archive(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trmnlp/api_client.rb', line 12 def get_plugin_setting_archive(id) response = conn.get("plugin_settings/#{id}/archive") if response.status == 200 temp_file = Tempfile.new(["plugin_settings_#{id}", '.zip']) temp_file.binmode temp_file.write(response.body) temp_file.rewind # return the temp file IO temp_file else raise Error, "failed to download plugin settings archive: #{response.status} #{response.body}" end end |
#post_plugin_setting(params) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/trmnlp/api_client.rb', line 46 def post_plugin_setting(params) response = conn.post("plugin_settings", params.to_json, content_type: 'application/json') if response.status == 200 JSON.parse(response.body) else raise Error, "failed to create plugin setting: #{response.status} #{response.body}" end end |
#post_plugin_setting_archive(id, path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trmnlp/api_client.rb', line 28 def post_plugin_setting_archive(id, path) filepart = Faraday::Multipart::FilePart.new(path, 'application/zip') payload = { file: filepart } response = conn.post("plugin_settings/#{id}/archive", payload) filepart.close if response.status == 200 JSON.parse(response.body) else raise Error, "failed to upload plugin settings archive: #{response.status} #{response.body}" end end |