Class: StreamlyFFI::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/streamly_ffi/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



6
7
8
# File 'lib/streamly_ffi/connection.rb', line 6

def initialize
  self.connection = StreamlyFFI::PersistentRequest.new
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/streamly_ffi/connection.rb', line 4

def connection
  @connection
end

Instance Method Details

#delete(url, headers = {}, &block) ⇒ Object

A helper method to make HEAD requests a dead-simple one-liner

Example:

Streamly.delete("www.somehost.com/some_resource/1")

Streamly.delete("www.somehost.com/some_resource/1") do |chunk|
  # do something with _chunk_
end

Parameters: url should be a String, the url to request headers should be a Hash and is optional

This method also accepts a block, which will stream the response body in chunks to the caller



106
107
108
109
110
# File 'lib/streamly_ffi/connection.rb', line 106

def delete(url, headers={}, &block)
  opts = {:method => :delete, :url => url, :headers => headers}
  opts[:response_body_handler] = block if block_given?
  self.connection.execute(opts)
end

#escape(_string) ⇒ Object



112
113
114
# File 'lib/streamly_ffi/connection.rb', line 112

def escape(_string)
  self.connection.escape(_string)
end

#get(url, headers = nil, &block) ⇒ Object

A helper method to make HEAD requests a dead-simple one-liner

Example:

Streamly.get("www.somehost.com/some_resource/1")

Streamly.get("www.somehost.com/some_resource/1") do |chunk|
  # do something with _chunk_
end

Parameters: url should be a String, the url to request headers should be a Hash and is optional

This method also accepts a block, which will stream the response body in chunks to the caller



44
45
46
47
48
# File 'lib/streamly_ffi/connection.rb', line 44

def get(url, headers=nil, &block)
  opts = {:method => :get, :url => url, :headers => headers}
  opts[:response_body_handler] = block if block_given?
  self.connection.execute(opts)
end

#head(url, headers = nil, &block) ⇒ Object

A helper method to make HEAD requests a dead-simple one-liner

Example:

Streamly.head("www.somehost.com/some_resource/1")

Streamly.head("www.somehost.com/some_resource/1") do |header_chunk|
  # do something with _header_chunk_
end

Parameters: url should be a String, the url to request headers should be a Hash and is optional

This method also accepts a block, which will stream the response headers in chunks to the caller



24
25
26
27
28
# File 'lib/streamly_ffi/connection.rb', line 24

def head(url, headers=nil, &block)
  opts = {:method => :head, :url => url, :headers => headers}
  opts[:response_header_handler] = block if block_given?
  self.connection.execute(opts)
end

#post(url, payload, headers = nil, &block) ⇒ Object

A helper method to make HEAD requests a dead-simple one-liner

Example:

Streamly.post("www.somehost.com/some_resource", "asset[id]=2&asset[name]=bar")

Streamly.post("www.somehost.com/some_resource", "asset[id]=2&asset[name]=bar") do |chunk|
  # do something with _chunk_
end

Parameters: url should be a String (the url to request) and is required payload should be a String and is required headers should be a Hash and is optional

This method also accepts a block, which will stream the response body in chunks to the caller



65
66
67
68
69
# File 'lib/streamly_ffi/connection.rb', line 65

def post(url, payload, headers=nil, &block)
  opts = {:method => :post, :url => url, :payload => payload, :headers => headers}
  opts[:response_body_handler] = block if block_given?
  self.connection.execute(opts)
end

#put(url, payload, headers = nil, &block) ⇒ Object

A helper method to make HEAD requests a dead-simple one-liner

Example:

Streamly.put("www.somehost.com/some_resource/1", "asset[name]=foo")

Streamly.put("www.somehost.com/some_resource/1", "asset[name]=foo") do |chunk|
  # do something with _chunk_
end

Parameters: url should be a String (the url to request) and is required payload should be a String and is required headers should be a Hash and is optional

This method also accepts a block, which will stream the response body in chunks to the caller



86
87
88
89
90
# File 'lib/streamly_ffi/connection.rb', line 86

def put(url, payload, headers=nil, &block)
  opts = {:method => :put, :url => url, :payload => payload, :headers => headers}
  opts[:response_body_handler] = block if block_given?
  self.connection.execute(opts)
end