Class: Opic

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/opic.rb

Class Method Summary collapse

Class Method Details

.get(name_n, options = {}) ⇒ Object



13
14
15
16
17
# 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) ⇒ 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