Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.48 KB | None | 0 0
  1. module Alfa
  2.   module Telia
  3.     class Client
  4.  
  5.       attr_reader :params
  6.  
  7.       ENDPOINT = 'https://teenused.elion.ee:443/external/services/index.php'
  8.       WSDL = 'https://teenused.elion.ee/external/services/index.php?wsdl'
  9.       USER = '3726557071@elion.ee'
  10.       PASSWORD = 'ave4weYH'
  11.  
  12.       def initialize(params)
  13.         @params = params
  14.       end
  15.  
  16.       def get_call_history(number)
  17.         send_request(:get_call_history, call_history_message(number))
  18.       end
  19.  
  20.       def call_number(number_from, number_to)
  21.         send_request(:click_to_call, click_to_call_message(number_from, number_to))
  22.       end
  23.  
  24.  
  25.       private
  26.  
  27.       def client
  28.         @client  ||= Savon.client(
  29.           wsdl: WSDL,
  30.           endpoint: ENDPOINT,
  31.           wsse_auth: [USER, PASSWORD],
  32.           convert_request_keys_to: :camelcase,
  33.           log_level: :debug,
  34.           log: true,
  35.           pretty_print_xml: true,
  36.         )
  37.       end
  38.  
  39.       def send_request(action, message)
  40.         client.call(action, message: message.deep_symbolize_keys)
  41.       rescue Savon::InvalidResponseError
  42.         raise('Invalid reponse from Telia')
  43.       end
  44.  
  45.       def call_history_message
  46.         { 'getCallHistory' => params }
  47.       end
  48.  
  49.       def click_to_call_message
  50.         { 'click_to_call' => params }
  51.       end
  52.  
  53.     end
  54.   end
  55. end
  56.  
  57. Alfa::Telia::Client.new('Anumber' => number_from, 'Bnumber' => number_to).call_number
  58. Alfa::Telia::Client.new('Anumber' => '12356').get_call_history
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement