Module: OperatorFinder

Extended by:
Configuration
Defined in:
lib/operator_finder.rb,
lib/operator_finder/version.rb,
lib/generators/operator_finder/install_generator.rb

Defined Under Namespace

Modules: Generators

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Configuration

configuration, define_setting

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



13
14
15
# File 'lib/operator_finder.rb', line 13

def client_id
  @client_id
end

#uriObject

Returns the value of attribute uri.



13
14
15
# File 'lib/operator_finder.rb', line 13

def uri
  @uri
end

Class Method Details

.executeObject



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
# File 'lib/operator_finder.rb', line 32

def self.execute
  begin
    @uri.query = URI.encode_www_form(@params)
    @response = Net::HTTP.get_response(@uri)
    result = JSON.parse(@response.body)
    circle_code = ""
    operator = ""

    if CIRCLEOPERATOR["circle_code"].keys.include?(result["circle_code"].to_i)
      circle_code = CIRCLEOPERATOR["circle_code"][result["circle_code"].to_i]
    end

    if CIRCLEOPERATOR["operator"].keys.include?(result["operator_code"].to_i)
      operator = CIRCLEOPERATOR["operator"][result["operator_code"].to_i]
    end

    final_result = operator+" "+circle_code
    return final_result
    
  rescue
    {:error=>"Transaction Failed",:status=>false}
  rescue => err_msg
    {:error=>"#{err_msg}",:status=>false}
  end
end

.get_operator_detail(number) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/operator_finder.rb', line 58

def self.get_operator_detail(number)
  @uri = URI("https://joloapi.com/api/findoperator.php?")
  if number.length != 10
    final_result = "Please pass 10 digits mobile number(ex: 8888888888)"
  else
    params = {
      mob: number,
      type: 'json'
    }
    OperatorFinder.run_action params
  end
end

.run_action(params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/operator_finder.rb', line 18

def self.run_action(params = {})
 if OperatorFinder.jolo_api_token.nil? || OperatorFinder.jolo_api_token == "" || OperatorFinder.jolo_user_id.nil? || OperatorFinder.jolo_user_id.nil?
  final_result = "Please provide jolo api token in config/initializers/operator_finder.rb, Ex: config.jolo_api_token = \\'name\\'"
 elsif OperatorFinder.jolo_api_token.include? 'Please'
  final_result = "Please Update Operator Finder Configuration."
 else
  @params = params.merge({
    userid: OperatorFinder.jolo_user_id,
    key: OperatorFinder.jolo_api_token
  })
  OperatorFinder.execute
 end
end