Class: MitakeApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mitake_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
# File 'lib/mitake_api/client.rb', line 8

def initialize(settings)
  @username = settings[:username]
  @password = settings[:password]
  @charset =  settings[:charset] || 'UTF8'
  @callback_url = settings[:callback_url]
  @url = "https://#{settings[:url]&.gsub(%r{https?://}, '')}"
end

Instance Attribute Details

#charsetObject (readonly)

Returns the value of attribute charset.



6
7
8
# File 'lib/mitake_api/client.rb', line 6

def charset
  @charset
end

#mitake_msgObject (readonly)

Returns the value of attribute mitake_msg.



6
7
8
# File 'lib/mitake_api/client.rb', line 6

def mitake_msg
  @mitake_msg
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/mitake_api/client.rb', line 6

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/mitake_api/client.rb', line 6

def url
  @url
end

Instance Method Details

#send_message(message) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/mitake_api/client.rb', line 16

def send_message(message)
  @mitake_msg = Message.new(message)
  mitake_msg.response = connection.post('api/mtk/SmSend') do |req|
    req.params = { CharsetURL: charset }
    req.headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
    req.body = URI.encode_www_form(credentials.merge(mitake_msg.to_h))
  end
end