Class: Binnacle::Resource
- Inherits:
-
Object
- Object
- Binnacle::Resource
- Defined in:
- lib/binnacle/resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
writeonly
Sets the attribute connection.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#connection=(value) ⇒ Object (writeonly)
Sets the attribute connection
6 7 8 |
# File 'lib/binnacle/resource.rb', line 6 def connection=(value) @connection = value end |
#route ⇒ Object (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
#post ⇒ Object
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_asynch ⇒ Object
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 |