Class: Binnacle::Resource

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

Direct Known Subclasses

Event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection=(value) ⇒ Object (writeonly)

Sets the attribute connection

Parameters:

  • value

    the value to set the attribute connection to.



6
7
8
# File 'lib/binnacle/resource.rb', line 6

def connection=(value)
  @connection = value
end

#routeObject (readonly)

Returns the value of attribute route.



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

def route
  @route
end

Class Method Details

.get(connection, path, query_params) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/binnacle/resource.rb', line 28

def self.get(connection, path, query_params)
  response = connection.get do |req|
    req.url path
    req.headers['Content-Type'] = 'application/json'
    query_params.each do |n,v|
      req.params[n] = v if v
    end
  end

  if response.status == 401
    Binnacle.binnacle_logger.error("Error communicating with Binnacle: #{response.body}")
  else
    JSON.parse(response.body).map { |r| self.from_hash(r) }
  end
end

Instance Method Details

#postObject



18
19
20
21
22
23
24
25
26
# File 'lib/binnacle/resource.rb', line 18

def post
  response = response_from_post(@connection, self.route, self.to_json)

  if response.status == 401
    Binnacle.binnacle_logger.error("Error communicating with Binnacle: #{response.body}")
  else
    JSON.parse(response.body)
  end
end

#post_asynchObject



8
9
10
11
12
13
14
15
16
# File 'lib/binnacle/resource.rb', line 8

def post_asynch
  Thread.new do
    response = response_from_post(@connection, self.route, self.to_json)

    if response.status == 401
      Binnacle.binnacle_logger.error("Error communicating with Binnacle: #{response.body}")
    end
  end
end