Class: Inkdit::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/inkdit/resource.rb

Overview

some resource (in the REST sense) in the system

Direct Known Subclasses

Contract, Entity, FormContract

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • client (Client)

    the client to use this resource with

  • opts (String, Hash)

    either the resource’s URL, or a hash describing the resource



9
10
11
12
13
14
15
16
17
18
# File 'lib/inkdit/resource.rb', line 9

def initialize(client, opts)
  @client = client

  if opts.is_a? String
    @url    = opts
    @params = []
  else
    self.params = opts
  end
end

Instance Attribute Details

#urlObject (readonly)

the URL of this resource



5
6
7
# File 'lib/inkdit/resource.rb', line 5

def url
  @url
end

Instance Method Details

#==(other_resource) ⇒ Object



26
27
28
# File 'lib/inkdit/resource.rb', line 26

def ==(other_resource)
  self.url == other_resource.url
end

#fetch!Object

retrieve this resource using its URL.



21
22
23
24
# File 'lib/inkdit/resource.rb', line 21

def fetch!
  response = @client.get(self.url)
  @params  = response.parsed
end

#inspectObject



30
31
32
# File 'lib/inkdit/resource.rb', line 30

def inspect
  "#<#{self.class.inspect} params=#{@params}>"
end