Class: EventMachine::Smsified::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/em-smsified/base.rb

Direct Known Subclasses

OneAPI, Reporting, Subscriptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Intantiate a new class to work with OneAPI

Parameters:

  • params (required, Hash)

    to create the user

Raises:

  • (ArgumentError)

    if :username is not passed as an option

  • (ArgumentError)

    if :password is not passed as an option



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/em-smsified/base.rb', line 21

def initialize(options)
  raise ArgumentError, 'an options Hash is required' if !options.instance_of?(Hash)
  raise ArgumentError, ':username required' if options[:username].nil?
  raise ArgumentError, ':password required' if options[:password].nil?
  
  @base_uri = options[:base_uri] || SMSIFIED_ONEAPI_PUBLIC_URI
  @auth = { :username => options[:username], :password => options[:password] }
  
  @destination_address = options[:destination_address]
  @sender_address      = options[:sender_address]
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



7
8
9
# File 'lib/em-smsified/base.rb', line 7

def auth
  @auth
end

#base_uriObject (readonly)

Returns the value of attribute base_uri.



7
8
9
# File 'lib/em-smsified/base.rb', line 7

def base_uri
  @base_uri
end

#destination_addressObject (readonly)

Returns the value of attribute destination_address.



7
8
9
# File 'lib/em-smsified/base.rb', line 7

def destination_address
  @destination_address
end

#sender_addressObject (readonly)

Returns the value of attribute sender_address.



7
8
9
# File 'lib/em-smsified/base.rb', line 7

def sender_address
  @sender_address
end

Instance Method Details

#delete(url, headers) ⇒ Object

HTTP DELETE’s a request

Parameters:

  • :url (required, String)

    to GET from



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/em-smsified/base.rb', line 55

def delete(url, headers)
  conn = create_connection_object(url)

  http = conn.delete(:head => add_authorization_to_header(headers, @auth))

  action = proc do
    response = Response.new(http.response.parsed, http)#.response.raw)
    yield response if block_given?
  end

  http.callback &action
  http.errback &action 
end

#get(url, headers) ⇒ Object

HTTP GET’s a request

Parameters:

  • :url (required, String)

    to GET from



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/em-smsified/base.rb', line 37

def get(url, headers)
  conn = create_connection_object(url)

  http = conn.get(:head => add_authorization_to_header(headers, @auth))

  action = proc do
    response = Response.new(http.response.parsed, http)#.response.raw)
    yield response if block_given?
  end

  http.callback &action
  http.errback &action 
end

#post(url, body, headers) ⇒ Object

HTTP POST’s a request

Parameters:

  • :url (required, String)

    to GET from



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/em-smsified/base.rb', line 73

def post(url, body, headers)
  conn = create_connection_object(url)

  http = conn.post(:body => body,
                   :head => add_authorization_to_header(headers, @auth))

  action = proc do
    response = Response.new(http.response.parsed, http)#.response.raw)
    yield response if block_given?
  end

  http.callback &action
  http.errback &action 
end