Class: TRMNLP::APIClient
- Inherits:
-
Object
- Object
- TRMNLP::APIClient
- Defined in:
- lib/trmnlp/api_client.rb
Instance Method Summary collapse
- #get_plugin_setting_archive(id) ⇒ Object
-
#initialize(config) ⇒ APIClient
constructor
A new instance of APIClient.
- #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
#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 path to the temp file Pathname.new(temp_file.path) else raise Error, "failed to download plugin settings archive: #{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 |
# File 'lib/trmnlp/api_client.rb', line 28 def post_plugin_setting_archive(id, path) payload = { file: Faraday::Multipart::FilePart.new(path, 'application/zip') } response = conn.post("plugin_settings/#{id}/archive", payload) if response.status == 200 true else raise Error, "failed to upload plugin settings archive: #{response.status} #{response.body}" end end |