Class: Newslettre::Letter::Schedule

Inherits:
APIModule
  • Object
show all
Defined in:
lib/newslettre/letter.rb

Instance Attribute Summary collapse

Attributes inherited from APIModule

#api

Instance Method Summary collapse

Constructor Details

#initialize(letter, api) ⇒ Schedule

Returns a new instance of Schedule.



78
79
80
81
# File 'lib/newslettre/letter.rb', line 78

def initialize letter, api
  @letter = letter
  @api = api
end

Instance Attribute Details

#letterObject (readonly)

Returns the value of attribute letter.



76
77
78
# File 'lib/newslettre/letter.rb', line 76

def letter
  @letter
end

Instance Method Details

#deleteObject



93
94
95
96
97
# File 'lib/newslettre/letter.rb', line 93

def delete
  request :delete, :name => letter

  true
end

#deliver(options = {}) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/newslettre/letter.rb', line 83

def deliver options = {}
  require 'time'
  data = { :name => letter }
  at = options.delete :at
  unless at.nil?
    data[:at] = at.iso8601
  end
  request :add, data
end

#getObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/newslettre/letter.rb', line 99

def get
  require 'time'
  begin
    date = request(:get, :name => letter)["date"]
  rescue Newslettre::API::ClientFailure
    raise NotScheduledFailure, "not found"
  end

  unless date.nil? or date.size.zero?
    parse_utc_date date
  else
    raise NotScheduledFailure, "invalid date"
  end
end