Class: Elibom::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/elibom/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/elibom/client.rb', line 9

def initialize(options={})
  @host = options[:host] || "https://www.elibom.com"
  @user = options[:user]
  @api_password = options[:api_password]

  raise ArgumentError, "Missing key ':user'" if @user.nil? || @user.empty?
  raise ArgumentError, "Missing key ':api_password'" if @api_password.nil? || @api_password.empty?
end

Instance Method Details

#cancel_schedule(schedule_id) ⇒ Object Also known as: unschedule

Raises:

  • (ArgumentError)


65
66
67
68
# File 'lib/elibom/client.rb', line 65

def cancel_schedule(schedule_id)
  raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
  delete "/schedules/#{schedule_id}"
end

#messages(delivery_id) ⇒ Object Also known as: list_messages

Raises:

  • (ArgumentError)


47
48
49
50
# File 'lib/elibom/client.rb', line 47

def messages(delivery_id)
  raise ArgumentError, "'delivery_id' cannot be nil or empty" if delivery_id.nil? || delivery_id.empty?
  get "/messages/#{delivery_id}"
end

#schedule_message(args = {}) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/elibom/client.rb', line 30

def schedule_message(args={})
  body = {}

  required_args = [:to, :text]
  required_args.each do |arg|
    raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
    body[arg] = args[arg]
  end

  raise ArgumentError, "Missing key ':schedule_date'" if args[:schedule_date].nil?
  raise ArgumentError, "Invalid argument ':schedule_date'" unless args[:schedule_date].respond_to?('strftime')

  body['scheduleDate'] =  args[:schedule_date].strftime('%Y-%m-%d %H:%M')

  post '/messages', body
end

#scheduledObject Also known as: list_scheduled_messages, schedules, list_schedules



53
54
55
# File 'lib/elibom/client.rb', line 53

def scheduled
  get "/schedules/scheduled"
end

#send_message(args = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elibom/client.rb', line 18

def send_message(args={})
  body = {}

  required_args = [:to, :text]
  required_args.each do |arg|
    raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
    body[arg] = args[arg]
  end

  post '/messages', body
end

#show_accountObject Also known as: account



82
83
84
# File 'lib/elibom/client.rb', line 82

def 
  get '/account'
end

#show_schedule(schedule_id) ⇒ Object

Raises:

  • (ArgumentError)


60
61
62
63
# File 'lib/elibom/client.rb', line 60

def show_schedule(schedule_id)
  raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
  get "/schedules/#{schedule_id}"
end

#show_user(user_id) ⇒ Object Also known as: user

Raises:

  • (ArgumentError)


76
77
78
79
# File 'lib/elibom/client.rb', line 76

def show_user(user_id)
  raise ArgumentError, "'user_id' cannot be nil" if user_id.nil?
  get "/users/#{user_id}"
end

#usersObject Also known as: list_users



71
72
73
# File 'lib/elibom/client.rb', line 71

def users
  get "/users"
end