class EasySMS::Client
Attributes
uri[R]
Public Class Methods
new(url = nil)
click to toggle source
# File lib/easy_sms/client.rb, line 5 def initialize(url = nil) @url = url || ENV['EASYSMS_URL'] || ENV['EASY_SMS_URL'] raise 'Resource URL not set. Please pass a valid URL to initializer, or set EASYSMS_URL environment variable.' unless @url @resource = RestClient::Resource.new(@url) @uri = URI.parse(@url) end
Public Instance Methods
account()
click to toggle source
# File lib/easy_sms/client.rb, line 20 def account AccountResource.new(self) end
delete(path)
click to toggle source
# File lib/easy_sms/client.rb, line 52 def delete(path) begin @resource[path].delete(content_type: :json, accept: :json) rescue RestClient::Exception => e json = JSON.parse(e.response) rescue nil raise Error.new([e, json].compact.join(' ')) end end
get(path, attrs)
click to toggle source
# File lib/easy_sms/client.rb, line 24 def get(path, attrs) begin #TODO: add attrs to url or let it be handled by RestClient @resource[path].get(content_type: :json, accept: :json) rescue RestClient::Exception => e json = JSON.parse(e.response) rescue nil raise Error.new([e, json].compact.join(' ')) end end
messages()
click to toggle source
# File lib/easy_sms/client.rb, line 12 def messages MessageResource.new(self) end
phone_numbers()
click to toggle source
# File lib/easy_sms/client.rb, line 16 def phone_numbers PhoneNumberResource.new(self) end
post(path, attrs)
click to toggle source
# File lib/easy_sms/client.rb, line 34 def post(path, attrs) begin @resource[path].post(attrs.to_json, content_type: :json, accept: :json) rescue RestClient::Exception => e json = JSON.parse(e.response) rescue nil raise Error.new([e, json].compact.join(' ')) end end
put(path, attrs)
click to toggle source
# File lib/easy_sms/client.rb, line 43 def put(path, attrs) begin @resource[path].put(attrs.to_json, content_type: :json, accept: :json) rescue RestClient::Exception => e json = JSON.parse(e.response) rescue nil raise Error.new([e, json].compact.join(' ')) end end