Class: Streamio::Resource
- Inherits:
-
Object
- Object
- Streamio::Resource
- Defined in:
- lib/streamio/resource.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, parameters = {}) ⇒ Object
-
#initialize(name) ⇒ Resource
constructor
A new instance of Resource.
- #post(path, parameters = {}) ⇒ Object
- #put(path, parameters = {}) ⇒ Object
Constructor Details
#initialize(name) ⇒ Resource
Returns a new instance of Resource.
5 6 7 8 9 10 11 12 13 |
# File 'lib/streamio/resource.rb', line 5 def initialize(name) @name = name @resource_path = "/api/v1/#{@name}" uri = URI.parse(Streamio.protocol+Streamio.host) @net = Net::HTTP.new(uri.host, uri.port) @net.use_ssl = Streamio.use_ssl @net.verify_mode = OpenSSL::SSL::VERIFY_NONE if Streamio.skip_ssl_verification end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/streamio/resource.rb', line 3 def name @name end |
Instance Method Details
#delete(path) ⇒ Object
31 32 33 |
# File 'lib/streamio/resource.rb', line 31 def delete(path) validate_and_return @net.request(net_request(Net::HTTP::Delete, path)) end |
#get(path, parameters = {}) ⇒ Object
15 16 17 |
# File 'lib/streamio/resource.rb', line 15 def get(path, parameters = {}) validate_and_return @net.request(net_request(Net::HTTP::Get, path, parameters)) end |
#post(path, parameters = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/streamio/resource.rb', line 19 def post(path, parameters = {}) request_class = parameters.any? do |key, value| value.is_a?(File) end ? Net::HTTP::Post::Multipart : Net::HTTP::Post validate_and_return @net.request(net_request(request_class, path, parameters)) end |
#put(path, parameters = {}) ⇒ Object
27 28 29 |
# File 'lib/streamio/resource.rb', line 27 def put(path, parameters = {}) validate_and_return @net.request(net_request(Net::HTTP::Put, path, parameters)) end |