Class: NeverBounce::API::Request::JobsCreate

Inherits:
Base
  • Object
show all
Defined in:
lib/never_bounce/api/request/jobs_create.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#api_key, #api_url, #headers, #user_agent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_curl, #to_httparty

Instance Attribute Details

#auto_parseBoolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/never_bounce/api/request/jobs_create.rb', line 7

def auto_parse
  @auto_parse
end

#auto_startBoolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/never_bounce/api/request/jobs_create.rb', line 10

def auto_start
  @auto_start
end

#filenameString

Returns:

  • (String)


13
14
15
# File 'lib/never_bounce/api/request/jobs_create.rb', line 13

def filename
  @filename
end

#inputString, Array<Array<email, name>>

Input specification.

Returns:

  • (String)

    URL if input_location is <tt>“remote”.

  • (Array<Array<email, name>>)

    Structure if input_location is “supplied”.



18
19
20
# File 'lib/never_bounce/api/request/jobs_create.rb', line 18

def input
  @input
end

#input_locationString

Returns:

  • (String)


21
22
23
# File 'lib/never_bounce/api/request/jobs_create.rb', line 21

def input_location
  @input_location
end

#run_sampleBoolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/never_bounce/api/request/jobs_create.rb', line 24

def run_sample
  @run_sample
end

Class Method Details

.http_methodSymbol

Returns:

  • (Symbol)


27
28
29
# File 'lib/never_bounce/api/request/jobs_create.rb', line 27

def self.http_method
  :post
end

.pathString

Returns:

  • (String)


32
33
34
# File 'lib/never_bounce/api/request/jobs_create.rb', line 32

def self.path
  "jobs/create"
end

.response_klassResponse::JobsCreate



37
38
39
# File 'lib/never_bounce/api/request/jobs_create.rb', line 37

def self.response_klass
  Response::JobsCreate
end

Instance Method Details

#mode_hHash

Return a ready-to-merge mode attributes hash.

Returns:

  • (Hash)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/never_bounce/api/request/jobs_create.rb', line 43

def mode_h
  @mode_h ||= {}.tap do |_|
    unless (v = auto_start).nil?
      _[:auto_start] = v
    end

    unless (v = auto_parse).nil?
      _[:auto_parse] = v
    end

    unless (v = run_sample).nil?
      _[:run_sample] = v
    end
  end
end

#to_hHash

Returns:

  • (Hash)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/never_bounce/api/request/jobs_create.rb', line 60

def to_h
  input = require_attr(:input)
  input_location = require_attr(:input_location)

  # Validate `input_location` and `input`.

  if not ["remote_url", "supplied"].include? input_location
    raise AttributeError, "Unknown `input_location`: #{input_location.inspect}"
  end

  if input_location == "supplied"
    raise AttributeError, "Invalid `input` for `input_location` == #{input_location.inspect}: #{input.inspect}" if not input.is_a? Array

    # Skim through elements of `input`, raise if invalid structure detected, with details.
    input.each do |elem|
      em = [AttributeError, "Invalid `input` element: #{elem.inspect}"]
      raise(*em) unless elem.is_a? Array
      raise(*em) unless elem.map(&:class) == [String, String]
    end
  end

  # Result.
  {
    input: input,
    input_location: input_location,
    filename: require_attr(:filename),
    key: require_attr(:api_key),
  }.merge(mode_h)
end