Class: Paperlex::Base

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/paperlex/base/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, attrs = {}) ⇒ Base

Returns a new instance of Base.



35
36
37
# File 'lib/paperlex/base/base.rb', line 35

def initialize(uuid, attrs = {})
  super(uuid.is_a?(Hash) ? uuid.merge(attrs) : attrs.merge(:uuid => uuid))
end

Class Method Details

.[](uuid) ⇒ Object



14
15
16
# File 'lib/paperlex/base/base.rb', line 14

def [](uuid)
  new(uuid)
end

.delete(url, attrs = {}) ⇒ Object



30
31
32
# File 'lib/paperlex/base/base.rb', line 30

def delete(url, attrs = {})
  parse(RestClient.delete("#{Paperlex.base_url}/#{url}?#{attrs.merge(:token => Paperlex.token).to_query}"))
end

.get(url, attrs = {}) ⇒ Object



18
19
20
# File 'lib/paperlex/base/base.rb', line 18

def get(url, attrs = {})
  parse(RestClient.get("#{Paperlex.base_url}/#{url}?#{attrs.merge(:token => Paperlex.token).to_query}"))
end

.parse(result) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/paperlex/base/base.rb', line 6

def parse(result)
  if result == "null"
    nil
  else
    JSON.parse(result)
  end
end

.post(url, attrs = {}) ⇒ Object



22
23
24
# File 'lib/paperlex/base/base.rb', line 22

def post(url, attrs = {})
  parse(RestClient.post("#{Paperlex.base_url}/#{url}", attrs.merge(:token => Paperlex.token)))
end

.put(url, attrs = {}) ⇒ Object



26
27
28
# File 'lib/paperlex/base/base.rb', line 26

def put(url, attrs = {})
  parse(RestClient.put("#{Paperlex.base_url}/#{url}", attrs.merge(:token => Paperlex.token)))
end

Instance Method Details

#to_uuid(object) ⇒ Object



39
40
41
# File 'lib/paperlex/base/base.rb', line 39

def to_uuid(object)
  object.respond_to?(:uuid) ? object.uuid : object
end