class Opic
Public Class Methods
get(name_n, options = {})
click to toggle source
# File lib/opic.rb, line 13 def get(name_n, options = {}) defaults = { width: 100, aspect: 's' } options = defaults.merge(options) "#{@endpoint}#{name_n}?width=#{options[:width]}&aspect=#{options[:aspect]}" end
post(name_n, file)
click to toggle source
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
# 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