Class: Ferto::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/ferto/callback.rb

Defined Under Namespace

Classes: ParserError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Callback

Returns a new instance of Callback.

Parameters:

  • params (Hash{String => Boolean, String, Integer})

    the options to create the Callback with

Options Hash (params):

  • :success (Boolean)

    Whether the download job was successful

  • :error (String)

    The error message of the download

  • :download_url (String)

    The URL from which the resulting downloaded file can be fetched

  • :resource_url (String)

    The original resource URL of the job

  • :job_id (String)

    The job id generated by the Downloader

  • :response_code (Integer)

    The status code returned by the upstream server when the download was attempted

  • :extra (String)

    Any extra information sent by the client



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ferto/callback.rb', line 35

def initialize(params)
  params = parse(params)

  @success = params[:success]
  @error = params[:error]
  @extra = params[:extra]
  @download_url = params[:download_url]
  @resource_url = params[:resource_url]
  @job_id = params[:job_id]
  @response_code = params[:response_code]
  @mime_error = params[:mime_error]
end

Instance Attribute Details

#download_urlString (readonly)

Returns The URL from which the resulting downloaded file can be fetched.

Returns:

  • (String)

    The URL from which the resulting downloaded file can be fetched.



12
13
14
# File 'lib/ferto/callback.rb', line 12

def download_url
  @download_url
end

#errorString, NilClass (readonly)

Returns The error message of the download or nil if there was no error.

Returns:

  • (String, NilClass)

    The error message of the download or nil if there was no error.



5
6
7
# File 'lib/ferto/callback.rb', line 5

def error
  @error
end

#extraHash (readonly)

Returns Any extra information sent by the client.

Returns:

  • (Hash)

    Any extra information sent by the client.



8
9
10
# File 'lib/ferto/callback.rb', line 8

def extra
  @extra
end

#job_idString (readonly)

Returns The job id generated by the Downloader.

Returns:

  • (String)

    The job id generated by the Downloader.



18
19
20
# File 'lib/ferto/callback.rb', line 18

def job_id
  @job_id
end

#resource_urlString (readonly)

Returns The original resource URL of the job.

Returns:

  • (String)

    The original resource URL of the job.



15
16
17
# File 'lib/ferto/callback.rb', line 15

def resource_url
  @resource_url
end

#response_codeInteger (readonly)

Returns The status code returned by the upstream server when the download was attempted.

Returns:

  • (Integer)

    The status code returned by the upstream server when the download was attempted.



22
23
24
# File 'lib/ferto/callback.rb', line 22

def response_code
  @response_code
end

Instance Method Details

#download_successful?Boolean

Returns Whether the download job was successful.

Returns:

  • (Boolean)

    Whether the download job was successful.



68
69
70
# File 'lib/ferto/callback.rb', line 68

def download_successful?
  @success
end

#matching_url?(url) ⇒ Boolean

Determines whether the URL of the download is the same with the one the downloader used for the download.

Examples:

self.resource_url # => "https://img-morhipo.mncdn.com/%5Bimg%5D%5B4%5D%5B1%5D.jpg"
self.url?("https://img-morhipo.mncdn.com/[img][4][1].jpg") # => true

Parameters:

  • url (String)

Returns:

  • (Boolean)


58
59
60
# File 'lib/ferto/callback.rb', line 58

def matching_url?(url)
  resource_url == url
end

#mime_error?Boolean

Return true if there is a Mime type mismatch.

Returns:

  • (Boolean)

    Return true if there is a Mime type mismatch.



63
64
65
# File 'lib/ferto/callback.rb', line 63

def mime_error?
  @mime_error
end