Class: Ferto::Client
- Inherits:
-
Object
- Object
- Ferto::Client
- Defined in:
- lib/ferto/client.rb
Instance Attribute Summary collapse
-
#aggr_limit ⇒ Fixnum
readonly
The maximum concurrent download requests that you allow the service to make.
- #connect_timeout ⇒ Fixnum readonly
- #host ⇒ String readonly
-
#path ⇒ String
readonly
The Downloader service path for enqueueing new downloads.
- #port ⇒ String readonly
- #scheme ⇒ String readonly
-
#timeout ⇒ Fixnum
readonly
The maximum time in seconds that you allow the ‘libcurl` transfer operation to take.
Instance Method Summary collapse
-
#download(aggr_id:, aggr_limit: @aggr_limit, url:, callback_url:, mime_type: "", extra: {}) ⇒ Ferto::Client::Response
Sends a request to Downloader and returns its reply.
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ferto/client.rb', line 34 def initialize(opts = {}) opts = DEFAULT_CONFIG.merge(opts) @scheme = opts[:scheme] @host = opts[:host] @path = opts[:path] @port = opts[:port] @connect_timeout = opts[:connect_timeout] @timeout = opts[:timeout] @aggr_limit = opts[:aggr_limit] end |
Instance Attribute Details
#aggr_limit ⇒ Fixnum (readonly)
Returns The maximum concurrent download requests that you allow the service to make.
24 25 26 |
# File 'lib/ferto/client.rb', line 24 def aggr_limit @aggr_limit end |
#connect_timeout ⇒ Fixnum (readonly)
16 17 18 |
# File 'lib/ferto/client.rb', line 16 def connect_timeout @connect_timeout end |
#host ⇒ String (readonly)
7 8 9 |
# File 'lib/ferto/client.rb', line 7 def host @host end |
#path ⇒ String (readonly)
Returns The Downloader service path for enqueueing new downloads.
10 11 12 |
# File 'lib/ferto/client.rb', line 10 def path @path end |
#port ⇒ String (readonly)
13 14 15 |
# File 'lib/ferto/client.rb', line 13 def port @port end |
#scheme ⇒ String (readonly)
4 5 6 |
# File 'lib/ferto/client.rb', line 4 def scheme @scheme end |
#timeout ⇒ Fixnum (readonly)
Returns The maximum time in seconds that you allow the ‘libcurl` transfer operation to take.
20 21 22 |
# File 'lib/ferto/client.rb', line 20 def timeout @timeout end |
Instance Method Details
#download(aggr_id:, aggr_limit: @aggr_limit, url:, callback_url:, mime_type: "", extra: {}) ⇒ Ferto::Client::Response
Sends a request to Downloader and returns its reply.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ferto/client.rb', line 58 def download(aggr_id:, aggr_limit: @aggr_limit, url:, callback_url:, mime_type: "", extra: {}) uri = URI::HTTP.build( scheme: scheme, host: host, port: port, path: path ) body = build_body( aggr_id, aggr_limit, url, callback_url, mime_type, extra) # Curl.post reuses the same handler res = Curl.post(uri.to_s, body.to_json) do |handle| handle.headers = build_header(aggr_id) handle.connect_timeout = connect_timeout handle.timeout = timeout end Ferto::Response.new res end |