Class: Gmsgms_2

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/mhub/gms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gms_t_login, gms_t_password, gms_r_login, gms_r_password, telegram_api_url, telegram_chat_id) ⇒ Gmsgms_2

Returns a new instance of Gmsgms_2.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/imperituroard/projects/mhub/gms.rb', line 9

def initialize(, gms_t_password, , gms_r_password, telegram_api_url, telegram_chat_id)
  @gms_t_login = 
  @gms_t_password = gms_t_password
  @gms_r_login = 
  @gms_r_password = gms_r_password

  @gms_t_connector = Gms_2.new(, gms_t_password, telegram_api_url, telegram_chat_id)
  @gms_r_connector = Gms_2.new(, gms_r_password, telegram_api_url, telegram_chat_id)

  @internal_func = InternalFunc.new
  @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id)

end

Instance Attribute Details

#gms_r_connectorObject

Returns the value of attribute gms_r_connector.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def gms_r_connector
  @gms_r_connector
end

#gms_r_loginObject

Returns the value of attribute gms_r_login.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def 
  @gms_r_login
end

#gms_r_passwordObject

Returns the value of attribute gms_r_password.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def gms_r_password
  @gms_r_password
end

#gms_t_connectorObject

Returns the value of attribute gms_t_connector.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def gms_t_connector
  @gms_t_connector
end

#gms_t_loginObject

Returns the value of attribute gms_t_login.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def 
  @gms_t_login
end

#gms_t_passwordObject

Returns the value of attribute gms_t_password.



6
7
8
# File 'lib/imperituroard/projects/mhub/gms.rb', line 6

def gms_t_password
  @gms_t_password
end

Instance Method Details

#get_r_status_external_2(external_id) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/imperituroard/projects/mhub/gms.rb', line 80

def get_r_status_external_2(external_id)
  output = {}
  begin
    ans = gms_r_connector.get_advanced_by_external(external_id)
    parsed = gms_parsing(ans)
    output = {:gms_answer => ans, :parsed_answer => parsed}
  rescue
    pars = {:code => "505", :result => "Failed", :body => {"status_code": "", "status": "", "phone_number": "", "message_id": ""}}
    output = {:gms_answer => ans, :parsed_answer => pars}
  end
  output
end

#get_t_status_external_2(external_id) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/imperituroard/projects/mhub/gms.rb', line 66

def get_t_status_external_2(external_id)
  output = {}
  begin
    ans = gms_t_connector.get_advanced_by_external(external_id)
    parsed = gms_parsing(ans)
    output = {:gms_answer => ans, :parsed_answer => parsed}
  rescue
    pars = {:code => "505", :result => "Failed", :body => {"status_code": "", "status": "", "phone_number": "", "message_id": ""}}
    output = {:gms_answer => ans, :parsed_answer => pars}
  end
  output
end

#gms_parsing(gms_answer) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/imperituroard/projects/mhub/gms.rb', line 23

def gms_parsing(gms_answer)
  output = {}

  status_dic = {
      12033 => 'Sent to Viber',
      36013 => 'Viber internal failure',
      36023 => 'Viber invalid service id',
      36033 => 'Viber invalid data',
      36043 => 'Viber blocked message type',
      36053 => 'Viber bad message type',
      36063 => 'Viber bad parameters',
      36073 => 'Viber timeout',
      36083 => 'Viber user blocked',
      36093 => 'Viber not viber user',
      36103 => 'Viber no suitable device',
      36113 => 'Viber unauthorized ip',
      36123 => 'Viber already sent',
      36133 => 'Viber not permitted',
      36143 => 'Viber billing failure',
      36153 => 'Viber word in black list',
      36163 => 'Viber internal process error',
      36173 => 'Viber wrong or missing Label',
      36183 => 'Viber invalid TTL value',
      23033 => 'Viber delivered',
      35015 => 'Viber expired',
      24013 => 'Viber delivered(seen)',
      28013 => 'Viber delivered(overdue)',
      -1 => 'in progress'
  }

  if gms_answer[:code] == 200
    dt1 = gms_answer[:body][:res_body]['reports'][0]
    hyber_status = dt1['hyber_status']
    output = {:code => 200, :result => 'Processed', :body => {'status_code': hyber_status, 'status': status_dic[hyber_status], 'phone_number': dt1['phone_number'], 'message_id': dt1['extra_id']}}
  elsif gms_answer[:code] == 404
    output = {:code => 404, :result => 'Not found', :body => {'status_code': '', 'status': '', 'phone_number': '', 'message_id': gms_answer[:body][:request_message][:external_id]}}
  else
    output = {:code => gms_answer[:code], :result => gms_answer[:result], :body => {'status_code': '', 'status': '', 'phone_number': '', 'message_id': gms_answer[:body][:request_message][:external_id]}}
  end
  output
end