Class: SerwerSMS::Resources::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/serwersms/resources/messages.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Messages

Returns a new instance of Messages.



4
5
6
# File 'lib/serwersms/resources/messages.rb', line 4

def initialize(client)
  @client = client
end

Instance Method Details

#delete(id, unique_id = nil) ⇒ Hash

Delete message from the scheduler

Parameters:

  • id (String)
  • unique_id (String) (defaults to: nil)

Returns:

  • (Hash)

    @option return [Boolean] :success



223
224
225
# File 'lib/serwersms/resources/messages.rb', line 223

def delete(id, unique_id = nil)
  @client.call('messages/delete', 'id' => id, 'unique_id' => unique_id)
end

#received(type, params = {}) ⇒ Hash

List of received messages

Parameters:

  • type (String)

    eco|nd|ndi|mms

  • params (Hash) (defaults to: {})

    @option params [String] :ndi Filtering by NDI @option params [String] :phone Filtering by phone @option params [String] :date_from Start date @option params [String] :date_to End date @option params [Boolean] :read Mark as read @option params [Integer] :page The number of the displayed page @option params [Integer] :limit Limit items displayed on single page @option params [String] :order asc|desc

Returns:

  • (Hash)

    @option return [Hash] :paging @option return [Array] :items @option item [Integer] :id @option item [String] :type eco|nd|ndi|mms @option item [String] :phone @option item [String] :received Date of received message @option item [String] :message_id ID of outgoing message (only for ECO SMS) @option item [Boolean] :blacklist Is the phone blacklisted? @option item [String] :text Message @option item [String] :to_number Number of the recipient (for MMS) @option item [String] :title Title of message (for MMS) @option item [Array] :attachments (for MMS) @option item [Hash] :contact



212
213
214
215
# File 'lib/serwersms/resources/messages.rb', line 212

def received(type, params = {})
  params['type'] = type
  @client.call('messages/received', params)
end

#reports(params = {}) ⇒ Hash

Check message delivery reports

Parameters:

  • params (Hash) (defaults to: {})

    @option params [String,Array] :id Message ID @option params [String,Array] :unique_id Message unique ID @option params [String,Array] :phone @option params [String] :date_from Start date @option params [String] :date_to End date @option params [String] :status delivered|undelivered|pending|sent|unsent @option params [String] :type eco|full|mms|voice @option params [Integer] :stat_id Package ID @option params [Boolean] :show_contact Show details of the recipient from contacts @option params [Integer] :page The number of the displayed page @option params [Integer] :limit Limit items displayed on single page @option params [String] :order asc|desc

Returns:

  • (Hash)

    @option return [Hash] :paging @option paging [Integer] :page @option paging [Integer] :count @option return [Array] :items



182
183
184
# File 'lib/serwersms/resources/messages.rb', line 182

def reports(params = {})
  @client.call('messages/reports', params)
end

#send_mms(phone, title, params = {}) ⇒ Hash

Send MMS

Parameters:

  • phone (String, Array)
  • title (String)

    Title of message (max 40 chars)

  • params (Hash) (defaults to: {})

    @option params [String] :file_id File ID @option params [String,Array] :file File in base64 encoding @option params [String] :date Set the date of sending @option params [Boolean] :test Test mode @option params [Integer,Array] :group_id Sending to the group instead of a phone number

Returns:

  • (Hash)

    @option return [Boolean] :success @option return [Integer] :queued @option return [Integer] :unsent @option return [Array] :items



108
109
110
111
112
# File 'lib/serwersms/resources/messages.rb', line 108

def send_mms(phone, title, params = {})
  params['phone'] = phone
  params['title'] = title
  @client.call('messages/send_mms', params)
end

#send_nd(phone, text) ⇒ Hash

Send message to ND/SC number

Parameters:

  • phone (String)

    Sender phone number

  • text (String)

    Message

Returns:

  • (Hash)

    @option return [Boolean] :success



120
121
122
# File 'lib/serwersms/resources/messages.rb', line 120

def send_nd(phone, text)
  @client.call('messages/send_nd', 'phone' => phone, 'text' => text)
end

#send_ndi(phone, text, ndi_number) ⇒ Hash

Send message to NDI/SCI number

Parameters:

  • phone (String)

    Sender phone number

  • text (String)

    Message

  • ndi_number (String)

    Recipient phone number

Returns:

  • (Hash)

    @option return [Boolean] :success



131
132
133
# File 'lib/serwersms/resources/messages.rb', line 131

def send_ndi(phone, text, ndi_number)
  @client.call('messages/send_ndi', 'phone' => phone, 'text' => text, 'ndi_number' => ndi_number)
end

#send_personalized(messages, sender = nil, params = {}) ⇒ Hash

Send personalized messages

Parameters:

  • messages (Array)

    @option message [String] :phone @option message [String] :text

  • sender (String) (defaults to: nil)

    Sender name — only for FULL SMS

  • params (Hash) (defaults to: {})

    @option params [Boolean] :details Show details of messages @option params [Boolean] :utf Change encoding to UTF-8 (only for FULL SMS) @option params [Boolean] :flash @option params [Boolean] :speed Priority canal — only for FULL SMS @option params [Boolean] :test Test mode @option params [String] :date Set the date of sending @option params [Integer,Array] :group_id Sending to the group instead of a phone number @option params [String] :text Message if group_id is set @option params [String,Array] :unique_id Own identifiers of messages @option params [Boolean] :voice Send VMS

Returns:

  • (Hash)

    @option return [Boolean] :success @option return [Integer] :queued @option return [Integer] :unsent @option return [Array] :items



67
68
69
70
71
# File 'lib/serwersms/resources/messages.rb', line 67

def send_personalized(messages, sender = nil, params = {})
  params['messages'] = messages
  params['sender']   = sender
  @client.call('messages/send_personalized', params)
end

#send_sms(phone, text, sender = nil, params = {}) ⇒ Hash

Send SMS message

Parameters:

  • phone (String)
  • text (String)

    Message content

  • sender (String) (defaults to: nil)

    Sender name — only for FULL SMS

  • params (Hash) (defaults to: {})

    @option params [Boolean] :details Show details of messages @option params [Boolean] :utf Change encoding to UTF-8 (only for FULL SMS) @option params [Boolean] :flash @option params [Boolean] :speed Priority canal — only for FULL SMS @option params [Boolean] :test Test mode @option params [Boolean] :vcard vCard message @option params [String] :wap_push WAP Push URL address @option params [String] :date Set the date of sending @option params [Integer] :group_id Sending to the group instead of a phone number @option params [Integer] :contact_id Sending to phone from contacts @option params [String] :unique_id Own identifiers of messages

Returns:

  • (Hash)

    @option return [Boolean] :success @option return [Integer] :queued Number of queued messages @option return [Integer] :unsent Number of unsent messages @option return [Array] :items @option item [String] :id @option item [String] :phone @option item [String] :status queued|unsent @option item [String] :queued Date of enqueued @option item [Integer] :parts Number of parts @option item [Integer] :error_code @option item [String] :error_message @option item [String] :text



38
39
40
41
42
43
# File 'lib/serwersms/resources/messages.rb', line 38

def send_sms(phone, text, sender = nil, params = {})
  params['phone']  = phone
  params['text']   = text
  params['sender'] = sender
  @client.call('messages/send_sms', params)
end

#send_voice(phone, params = {}) ⇒ Hash

Send Voice message

Parameters:

  • phone (String)
  • params (Hash) (defaults to: {})

    @option params [String] :text Text to speech @option params [String] :file_id ID of wav file @option params [String] :date Set the date of sending @option params [Boolean] :test Test mode @option params [Integer,Array] :group_id Sending to the group instead of a phone number @option params [Integer,Array] :contact_id Sending to phone from contacts

Returns:

  • (Hash)

    @option return [Boolean] :success @option return [Integer] :queued @option return [Integer] :unsent @option return [Array] :items



88
89
90
91
# File 'lib/serwersms/resources/messages.rb', line 88

def send_voice(phone, params = {})
  params['phone'] = phone
  @client.call('messages/send_voice', params)
end

#view(id, params = {}) ⇒ Hash

View single message

Parameters:

  • id (String)
  • params (Hash) (defaults to: {})

    @option params [String] :unique_id @option params [Boolean] :show_contact Show details of the recipient from contacts

Returns:

  • (Hash)

    @option return [String] :id @option return [String] :phone @option return [String] :status delivered|undelivered|sent|unsent|in_progress|saved @option return [String] :queued Date of enqueued @option return [String] :sent Date of sending @option return [String] :delivered Date of delivery @option return [String] :sender @option return [String] :type eco|full|mms|voice @option return [String] :text @option return [String] :reason message_expired|unsupported_number|message_rejected| missed_call|wrong_number|limit_exhausted|lock_send| wrong_message|operator_error|wrong_sender_name| number_is_blacklisted|sending_to_foreign_networks_is_locked| no_permission_to_send_messages|other_error @option return [Hash] :contact



157
158
159
160
# File 'lib/serwersms/resources/messages.rb', line 157

def view(id, params = {})
  params['id'] = id
  @client.call('messages/view', params)
end