Class: StateWTTX

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/wttx/updatepostcps.rb

Instance Method Summary collapse

Instance Method Details

#getrest_cps(imsi) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/imperituroard/projects/wttx/updatepostcps.rb', line 41

def getrest_cps(imsi)

  url = "http://172.24.220.77:8080/custrefdata/wttx/_query?imsi=#{imsi}"
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  response = http.request(Net::HTTP::Get.new(uri.request_uri))
  p content = response.body
  p result_code = response.to_s.include?("OK")
  #Rails.logger = Logger.new(STDOUT)
  #logger.info "WTTX service getrestCPS result code: #{response.to_s}"
  #logger.info "WTTX service getrestCPS soap body: #{content.to_s}"



  if !result_code
    "false"
  else
    reg_imsi = /<field code="imsi" value="([0-9]{10,15})"/
    reg_imei = /<field code="imei" value="([0-9]{10,17})"/

    m1 = reg_imsi.match(content)
    m2 = reg_imei.match(content)
    imsi = m1[1]
    imei = m2[1]

    res = result_code.to_s + " " + imsi + " " + imei
    p res
    res
  end

end

#update_statuswttx(imsi, imei) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/imperituroard/projects/wttx/updatepostcps.rb', line 8

def update_statuswttx(imsi, imei)

  doc = REXML::Document.new
  #doc.context[:attribute_quote] = :quote  # <-- Set double-quote as the attribute value delimiter
  root = doc.add_element('row')

  attr1 = root.add_element('key')
  attr1.add_attribute('code', 'imsi')
  attr1.add_attribute('value', imsi)

  attr2 = root.add_element('field')
  attr2.add_attribute('code', 'imei')
  attr2.add_attribute('value', imei)

  attr3 = root.add_element('field')
  attr3.add_attribute('code', 'status')
  attr3.add_attribute('value', 'TRUE')

  xmlout = ""
  doc.write xmlout
  p xmlout

  url_string = "http://172.24.220.77:8080/custrefdata/wttx/_update"
  xml_string = xmlout
  uri = URI.parse url_string
  request = Net::HTTP::Post.new uri.path
  p request.body = xml_string
  request.content_type = 'application/xml'
  p  response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
  p response.body
end