class Africastalking::Subscription
Public Class Methods
create(data)
click to toggle source
# File lib/africastalking/subscription.rb, line 5 def create(data) validate_attributes(%w(phone_number short_code keyword), data) post("/version1/subscription/create", build_subscription(data)) end
delete(data)
click to toggle source
# File lib/africastalking/subscription.rb, line 10 def delete(data) validate_attributes(%w(phone_number short_code keyword), data) post("/version1/subscription/delete", build_subscription(data)) end
fetch(data)
click to toggle source
# File lib/africastalking/subscription.rb, line 15 def fetch(data) validate_attributes(%w(short_code keyword), data) fetch_url = %{ /version1/subscription? username=#{Africastalking.config.username}& shortCode=#{data.fetch(:short_code)}&keyword=#{data.fetch(:keyword)}& lastReceivedId=#{data.fetch(:last_received_id, 0)} } get(fetch_url) end
Private Class Methods
build_subscription(data)
click to toggle source
# File lib/africastalking/subscription.rb, line 40 def build_subscription(data) { username: Africastalking.config.username, keyword: data.fetch(:keyword), phoneNumber: data.fetch(:phone_number), shortCode: data.fetch(:short_code) } end
validate_attributes(attrbs, data)
click to toggle source
# File lib/africastalking/subscription.rb, line 30 def validate_attributes(attrbs, data) attrbs.each do |value| fail "#{value} can not be blank!" if value_present?(data, value) end end
value_present?(data, value)
click to toggle source
# File lib/africastalking/subscription.rb, line 36 def value_present?(data, value) data[value.to_sym].empty? end