Class: Elibom::Client
- Inherits:
-
Object
- Object
- Elibom::Client
- Defined in:
- lib/elibom/client.rb
Instance Method Summary collapse
- #cancel_schedule(schedule_id) ⇒ Object (also: #unschedule)
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #messages(delivery_id) ⇒ Object (also: #list_messages)
- #schedule_message(args = {}) ⇒ Object
- #scheduled ⇒ Object (also: #list_scheduled_messages, #schedules, #list_schedules)
- #send_message(args = {}) ⇒ Object
- #show_account ⇒ Object (also: #account)
- #show_schedule(schedule_id) ⇒ Object
- #show_user(user_id) ⇒ Object (also: #user)
- #users ⇒ Object (also: #list_users)
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 |
# File 'lib/elibom/client.rb', line 9 def initialize(={}) @host = [:host] || "https://www.elibom.com" @user = [:user] @api_password = [: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
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
47 48 49 50 |
# File 'lib/elibom/client.rb', line 47 def (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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/elibom/client.rb', line 30 def (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 |
#scheduled ⇒ Object 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 (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_account ⇒ Object Also known as: account
82 83 84 |
# File 'lib/elibom/client.rb', line 82 def show_account get '/account' end |
#show_schedule(schedule_id) ⇒ Object
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
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 |
#users ⇒ Object Also known as: list_users
71 72 73 |
# File 'lib/elibom/client.rb', line 71 def users get "/users" end |