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.
- #schedule_message(args = {}) ⇒ Object
- #scheduled_messages ⇒ Object (also: #list_scheduled_messages)
- #send_message(args = {}) ⇒ Object
- #show_account ⇒ Object (also: #account)
- #show_delivery(delivery_id) ⇒ Object (also: #delivery)
- #show_scheduled_message(schedule_id) ⇒ Object (also: #scheduled_message)
- #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 |
#schedule_message(args = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elibom/client.rb', line 32 def (args={}) raise ArgumentError, "No args provided" if args.nil? raise ArgumentError, "Missing key ':to'" if args[:to].nil? raise ArgumentError, "Missing key ':text'" if args[:text].nil? raise ArgumentError, "Invalid argument ':text'. Too long, max 160 characters" if args[:text].length > 160 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 = { "to" => args[:to], "text" => args[:text], "scheduleDate" => args[:schedule_date].strftime('%Y-%m-%d %H:%M') } if !args[:campaign].nil? then body["campaign"] = args[:campaign] end post '/messages', body end |
#scheduled_messages ⇒ Object Also known as: list_scheduled_messages
54 55 56 |
# File 'lib/elibom/client.rb', line 54 def get "/schedules/scheduled" end |
#send_message(args = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/elibom/client.rb', line 18 def (args={}) raise ArgumentError, "No args provided" if args.nil? raise ArgumentError, "Missing key ':to'" if args[:to].nil? raise ArgumentError, "Missing key ':text'" if args[:text].nil? raise ArgumentError, "Text is too long, max 160 characters" if args[:text].length > 160 body = { "to" => args[:to], "text" => args[:text] } if !args[:campaign].nil? then body["campaign"] = args[:campaign] 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_delivery(delivery_id) ⇒ Object Also known as: delivery
48 49 50 51 |
# File 'lib/elibom/client.rb', line 48 def show_delivery(delivery_id) raise ArgumentError, "'delivery_id' cannot be nil or empty" if delivery_id.nil? || delivery_id.empty? get "/messages/#{delivery_id}" end |
#show_scheduled_message(schedule_id) ⇒ Object Also known as: scheduled_message
59 60 61 62 |
# File 'lib/elibom/client.rb', line 59 def (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 |