Class: IDTBeyond::Service::IATU

Inherits:
Object
  • Object
show all
Defined in:
lib/idtbeyond/services/imtu.rb

Instance Method Summary collapse

Constructor Details

#initialize(app_id = nil, app_key = nil, term_id = nil) ⇒ IATU

Constructor



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/idtbeyond/services/imtu.rb', line 8

def initialize(app_id = nil, app_key = nil, term_id = nil)
  raise "app_id, app_key and term_id are required" if app_key.nil? || app_id.nil? || term_id.nil?
  @app_id = app_id
  @app_key = app_key
  @term_id = term_id
  @url = ENV["IDTBEYOND_API_URL"] || "https://api.idtbeyond.com"
  @plan_type = ENV["IDTBEYOND_PLAN_TYPE"] || "Production"
  @conn = Faraday.new(:url => @url, :headers => {
    "x-idt-beyond-app-id" => @app_id,
    "x-idt-beyond-app-key" => @app_key
  }) do |faraday|
    faraday.request :url_encoded
    faraday.response :logger
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#client_transaction_id_search(client_transaction_id, date_from, date_to) ⇒ Object

API Methods



27
28
29
30
31
32
33
34
35
# File 'lib/idtbeyond/services/imtu.rb', line 27

def client_transaction_id_search(client_transaction_id, date_from, date_to)
  response = @conn.post "/v1/iatu/topups/reports", {
  :client_transaction_id => client_transaction_id,
  :type_of_report => "client_transaction_id",
  :date_from => date_from,
  :date_to => date_to
  }
  JSON response.body
end

#get_all_charges(date_from, date_to) ⇒ Object



36
37
38
39
40
# File 'lib/idtbeyond/services/imtu.rb', line 36

def get_all_charges(date_from, date_to)
  response = @conn.get "/v1/iatu/charges/reports/all", {:date_from => date_from, :date_to => date_to}
  return JSON response.body if response.status == 200
  false
end

#get_all_topups(date_from, date_to) ⇒ Object



41
42
43
44
45
# File 'lib/idtbeyond/services/imtu.rb', line 41

def get_all_topups(date_from, date_to)
  response = @conn.get "/v1/iatu/topups/reports/all", {:date_from => date_from, :date_to => date_to}
  return JSON response.body if response.status == 200
  false
end

#get_all_topups_totals(date_from, date_to) ⇒ Object



46
47
48
49
50
# File 'lib/idtbeyond/services/imtu.rb', line 46

def get_all_topups_totals(date_from, date_to)
  response = @conn.get "/v1/iatu/topups/reports/totals", {:date_from => date_from, :date_to => date_to}
  return JSON response.body if response.status == 200
  false
end

#get_app_idObject



51
52
53
# File 'lib/idtbeyond/services/imtu.rb', line 51

def get_app_id
  @app_id
end

#get_app_keyObject



55
56
57
# File 'lib/idtbeyond/services/imtu.rb', line 55

def get_app_key
  @app_key
end

#get_balanceObject



58
59
60
61
62
# File 'lib/idtbeyond/services/imtu.rb', line 58

def get_balance
  response = @conn.get "/v1/iatu/balance"
  return JSON response.body if response.status == 200
  false
end

#get_local_value(amount, carrier_code, country_code, currency_code) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/idtbeyond/services/imtu.rb', line 63

def get_local_value(amount, carrier_code, country_code, currency_code)
  response = @conn.get "/v1/iatu/products/reports/local-value", {
  :carrier_code => carrier_code,
  :country_code => country_code,
  :currency_code => currency_code,
  :amount => amount
  }
  JSON response.body
end

#get_statusObject



73
74
75
76
77
78
# File 'lib/idtbeyond/services/imtu.rb', line 73

def get_status
  response = @conn.get "/v1/status"
  p response
  return JSON response.body if response.status == 200
  false
end

#post_topup(amount, carrier_code, country_code, mobile_number) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/idtbeyond/services/imtu.rb', line 80

def post_topup(amount, carrier_code, country_code, mobile_number )
  client_transaction_id = @app_id + "-" + "%06d" % Random.rand(0..999999)
  response = @conn.post "/v1/iatu/topups", {
  :country_code => country_code,
  :carrier_code => carrier_code,
  :client_transaction_id => client_transaction_id,
  :terminal_id => @term_id,
  :mobile_number => mobile_number,
  :plan => @plan_type,
  :amount => amount
  }
  JSON response.body
end

#reverse_topup(client_transaction_id, to_service_number) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/idtbeyond/services/imtu.rb', line 93

def reverse_topup(client_transaction_id, to_service_number)
  response = @conn.post "/v1/iatu/topups/reverse", {
                                                     :client_transaction_id => client_transaction_id,
                                                     :to_service_number => to_service_number
                                                 }
  JSON response.body
end

#to_service_number_search(to_service_number) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/idtbeyond/services/imtu.rb', line 100

def to_service_number_search(to_service_number)
  response = @conn.post "/v1/iatu/topups/reports", {
  :to_service_number => to_service_number,
  :type_of_report => "to_service_number"
  }
  JSON response.body
end

#validate_number(country_code, mobile_number) ⇒ Object



107
108
109
110
111
# File 'lib/idtbeyond/services/imtu.rb', line 107

def validate_number(country_code, mobile_number)
  response = @conn.get "/v1/iatu/number-validator", {
                                                      :country_code => country_code, :mobile_number => mobile_number}
  JSON response.body
end