Class: Opic
Class Method Summary collapse
- .get(name_n, options = {}) ⇒ Object
-
.post(name_n, file) ⇒ Object
TODO: I don’t like the fact that we’re using rest_client here…I would rather use net/http because it’s part of the ruby stdlib.
Class Method Details
.get(name_n, options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/opic.rb', line 13 def get(name_n, = {}) defaults = { width: 100, aspect: 's' } = defaults.merge() "#{@endpoint}#{name_n}?width=#{[:width]}&aspect=#{[:aspect]}" end |
.post(name_n, file) ⇒ Object
TODO: I don’t like the fact that we’re using rest_client here…I would rather use net/http because it’s part of the ruby stdlib
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opic.rb', line 22 def post(name_n, file) begin raise "API Key not set!" if @api_key.nil? # If we were passed only a path then make a File file = File.new(file) unless file.is_a? File headers = { "X-API-Key" => @api_key } data = { avatar: file, name_n: name_n } r = RestClient.post("#{@endpoint}api/avatars", data, headers) return false unless r.code == 201 rescue => e @error = e return false end return true end |