Class: JustCall::SMS

Inherits:
Base
  • Object
show all
Includes:
API
Defined in:
lib/justcall_ruby/sms.rb

Constant Summary collapse

LIST_ATTRS =
{
  permitted: i[
    page per_page sort order from_datetime to_datetime contact_number
    justcall_number sms_direction sms_content last_sms_id_fetched
  ].freeze,
}.freeze
CHECK_REPLY_ATTRS =
{
  permitted: i[contact_number justcall_number].freeze,
  required: i[contact_number].freeze,
}.freeze
SEND_ATTRS =
{
  permitted: i[justcall_number body contact_number media_url restrict_once].freeze,
  required: i[justcall_number body contact_number].freeze,
}.freeze
ENDPOINTS =
{
  list: "texts?%s".freeze,
  fetch: "texts/%s".freeze,
  check_reply: "texts/checkreply".freeze,
  send: "texts/new".freeze,
}.freeze

Constants included from API

API::ROOT_URL, API::USER_AGENT

Instance Method Summary collapse

Methods inherited from Base

requires!

Constructor Details

#initialize(client:) ⇒ SMS

Returns a new instance of SMS.



31
32
33
# File 'lib/justcall_ruby/sms.rb', line 31

def initialize(client:)
  @client = client
end

Instance Method Details

#check_reply(params) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/justcall_ruby/sms.rb', line 48

def check_reply(params)
  requires!(params, *CHECK_REPLY_ATTRS[:required])

  endpoint = ENDPOINTS[:check_reply]
  params = standardize_body_data(submitted_attrs: params, permitted_attrs: CHECK_REPLY_ATTRS[:permitted])

  post_request(client: @client, endpoint: endpoint, data: params)
end

#fetch(sms_id) ⇒ Object



42
43
44
45
46
# File 'lib/justcall_ruby/sms.rb', line 42

def fetch(sms_id)
  endpoint = ENDPOINTS[:fetch] % sms_id

  get_request(client: @client, endpoint: endpoint)
end

#list(params = {}) ⇒ Object



35
36
37
38
39
40
# File 'lib/justcall_ruby/sms.rb', line 35

def list(params = {})
  params = standardize_body_data(submitted_attrs: params, permitted_attrs: LIST_ATTRS[:permitted])
  endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)

  get_request(client: @client, endpoint: endpoint)
end

#send(params) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/justcall_ruby/sms.rb', line 57

def send(params)
  requires!(params, *SEND_ATTRS[:required])

  endpoint = ENDPOINTS[:send]
  params = standardize_body_data(submitted_attrs: params, permitted_attrs: SEND_ATTRS[:permitted])

  post_request(client: @client, endpoint: endpoint, data: params)
end