Class: MultiInfo::API

Inherits:
Object
  • Object
show all
Defined in:
lib/multiinfo/api.rb,
lib/multiinfo/api/error.rb,
lib/multiinfo/api/command.rb,
lib/multiinfo/api/executor.rb,
lib/multiinfo/api/response.rb

Overview

This module provides the core implementation of the Clickatell HTTP service.

Defined Under Namespace

Classes: Command, Error, Executor, FakeHttpResponse, Response

Constant Summary collapse

DEFAULT_CONFIG_PATH =

Defaults for config file location

File.join(ENV['HOME'], 'multiinfo')
DEFAULT_CONFIG_FILE =
'multiinfo.yml'
API_SERVICE_HOST =
'https://api1.multiinfo.plus.pl/'
API_SCRIPT_TYPE =
'aspx'
DEFAULT_CERT_FILE =
'multiinfo.crt'
DEFAULT_KEY_FILE =
'multiinfo.pem'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_options = nil) ⇒ API

Creates a new API instance using the specified auth_options. auth_options is a hash containing :username, :password, :service_id and optionally :client_cert, :client_key



36
37
38
# File 'lib/multiinfo/api.rb', line 36

def initialize(auth_options = nil)
  @auth_options = auth_options || self.class.load_auth_options       
end

Class Attribute Details

.debug_modeObject

Set to true to enable debugging (off by default)



13
14
15
# File 'lib/multiinfo/api.rb', line 13

def debug_mode
  @debug_mode
end

.test_modeObject

Set to true to test message sending; this will not actually send messages but will collect sent messages in a testable collection. (off by default)



18
19
20
# File 'lib/multiinfo/api.rb', line 18

def test_mode
  @test_mode
end

Instance Attribute Details

#auth_optionsObject

Returns the value of attribute auth_options.



9
10
11
# File 'lib/multiinfo/api.rb', line 9

def auth_options
  @auth_options
end

Class Method Details

.load_auth_options(config_location = nil) ⇒ Object

Load credentials from config file



21
22
23
24
25
26
# File 'lib/multiinfo/api.rb', line 21

def load_auth_options(config_location = nil)                    
  config_file = File.open(config_location || File.join(DEFAULT_CONFIG_PATH, DEFAULT_CONFIG_FILE))
  auth_options = YAML.load(config_file).symbolize_keys
  raise MultiInfo::API::Error.new(-9999, 'Missing config params') if auth_options.only(:login, :password, :service_id).size != 3
  auth_options
end

Instance Method Details

#cancel_message(sms_id) ⇒ Object

Returns the status of a message. Use sms ID returned from original send_message call.



72
73
74
75
# File 'lib/multiinfo/api.rb', line 72

def cancel_message(sms_id)
  response = execute_command('cancelsms',  :sms_id => sms_id)
  parse_response(response)
end

#get_message(opts = {}) ⇒ Object



77
78
79
80
81
# File 'lib/multiinfo/api.rb', line 77

def get_message(opts={})
  valid_options = opts.only(:timeout).merge(service_id)
  response = execute_command('getsms', valid_options)
  parse_response(response)
end

#message_info(sms_id) ⇒ Object

Returns the status of a message. Use sms ID returned from original send_message call.



58
59
60
61
# File 'lib/multiinfo/api.rb', line 58

def message_info(sms_id)
  response = execute_command('infosms',  :sms_id => sms_id)
  parse_response(response)
end

#package_info(package_id) ⇒ Object

Returns the status of a package of messages. Use package id returned from original send_package call.



65
66
67
68
# File 'lib/multiinfo/api.rb', line 65

def package_info(package_id)
  response = execute_command('packageinfo',  :package_id => package_id)
  parse_response(response)      
end

#send_message(recipient, message_text, opts = {}) ⇒ Object

Sends a message message_text to recipient. Recipient number should have an international dialing prefix



42
43
44
45
46
# File 'lib/multiinfo/api.rb', line 42

def send_message(recipient, message_text, opts={})
  valid_options = opts.only(:valid_to, :deliv_notif_request).merge(service_id)
  response = execute_command( 'sendsms', {:text => message_text, :dest => recipient}.merge(valid_options) ) 
  parse_response(response)
end

#send_packageObject

Sends a package of messages. Recipient number should have an international dialing prefix



51
52
53
# File 'lib/multiinfo/api.rb', line 51

def send_package
  # todo
end

#sms_requestsObject

:nodoc:



83
84
85
# File 'lib/multiinfo/api.rb', line 83

def sms_requests #:nodoc:
  @sms_requests ||= []
end