Class: Bwclient::BwApi

Inherits:
Object
  • Object
show all
Defined in:
lib/bwclient.rb

Instance Method Summary collapse

Instance Method Details

#check_balance(user) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bwclient.rb', line 59

def check_balance(user)
  response = RestClient.post('https://paybits.binarywallet.com/api/checkbal/checkbal.php',
    :api_key => user.api_key,
    :acc_id => user.acc_id
  )
  
  splited_response = response.split("<br/>")
  splited_status = splited_response[0].split(":")
  
  if splited_status[1] == "Success"
    return [
              {
                "status"=>200
              },
              {
                "balance"=>splited_response[1].split(":")[1],
                "last_deposit_date"=>splited_response[2].split("=")[1]
              }
            ]
  else
    return [
              {
                "status"=>422
              },
              {
                "error"=>response
              }
            ]
  end
end

#create_account(user) ⇒ 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bwclient.rb', line 8

def (user)
  address = "#{user.address_1}, #{user.address_2}, #{user.city}, #{user.state}, #{user.postal_code}" ,
  response = RestClient.post('https://paybits.binarywallet.com/api/createaccount/new.php',
    :api_id => Rails.application.secrets[:bw_api_id],
    :fname => user.first_name,
    :lname => user.last_name,
    :dob => '',
    :gender => 'Male',
    :addr => address,
    :phno => user.phone,
    :email => user.email,
    :emp_name => 'Paybits',
    :emp_addr => '',
    :src_funds => 'employer',
    :est_turnover => '2600',
    :photo_id => File.open(File.join(Rails.root, '/app/assets/images/photo1.jpg')),
    :address_proof => File.open(File.join(Rails.root, '/app/assets/images/proof_of_address.jpg')),
    :pass => sample_password
  )

  splited_response = response.split("<br/>")
  splited_status = splited_response[0].split("=")
  
  if splited_status[1] == "success"
    return [
              {
                "status"=>201
              },
              {
                "message"=>splited_response[1].split("=")[1],
                "acc_id"=>splited_response[2].split("=")[1],
                "api_key"=>splited_response[3].split("=")[1]
              }
            ]
  else
    return [
              {
                "status"=>422
              },
              {
                "error"=>response
              }
            ]
  end
  
end

#resume_account(user) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/bwclient.rb', line 121

def (user)
  response = RestClient.post('https://paybits.binarywallet.com/api/accountstatus/chngestatus.php',
    :api_key => user.api_key,
    :acc_id => user.acc_id,
    :status => 'Active'
  )

  splited_response = response.split("<br/>")
  splited_status = splited_response[0].split(":")
  
  if splited_status[1] == "Success"
    return [
              {
                "status"=>200
              },
              {
                "message"=>"Success"
              }
            ]
  else
    return [
              {
                "status"=>422
              },
              {
                "error"=>response
              }
            ]
  end
end

#sample_passwordObject



55
56
57
# File 'lib/bwclient.rb', line 55

def sample_password
  ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]-%w(0 1 I O)).sample(8).join
end

#suspend_account(user) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/bwclient.rb', line 90

def (user)
  response = RestClient.post('https://paybits.binarywallet.com/api/accountstatus/chngestatus.php',
    :api_key => user.api_key,
    :acc_id => user.acc_id,
    :status => 'Inactive'
  )

  splited_response = response.split("<br/>")
  splited_status = splited_response[0].split(":")
  
  if splited_status[1] == "Success"
    return [
              {
                "status"=>200
              },
              {
                "message"=>"Success"
              }
            ]
  else
    return [
              {
                "status"=>422
              },
              {
                "error"=>response
              }
            ]
  end
end