Module: Wavecrest

Defined in:
lib/wavecrest.rb,
lib/wavecrest/version.rb,
lib/wavecrest/configuration.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auth_tokenObject

Returns the value of attribute auth_token.



11
12
13
# File 'lib/wavecrest.rb', line 11

def auth_token
  @auth_token
end

.auth_token_issuedObject

Returns the value of attribute auth_token_issued.



11
12
13
# File 'lib/wavecrest.rb', line 11

def auth_token_issued
  @auth_token_issued
end

.configurationObject

Returns the value of attribute configuration.



11
12
13
# File 'lib/wavecrest.rb', line 11

def configuration
  @configuration
end

Class Method Details

.authObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wavecrest.rb', line 36

def self.auth
  url = configuration.endpoint + "/v3/services/authenticator"

  headers = {
      "DeveloperId" => configuration.user,
      "DeveloperPassword" => configuration.password,
      "X-Method-Override" => 'login',
      accept: :json,
      content_type: :json
  }

  RestClient.proxy = configuration.proxy if configuration.proxy
  request = RestClient::Request.new(method: :post, url: url, headers: headers)
  response = request.execute.body
  data = JSON.parse response
  self.auth_token = data["token"]
  self.auth_token_issued = Time.now
end

.auth_need?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/wavecrest.rb', line 32

def self.auth_need?
  not auth_token or auth_token_issued and auth_token_issued + 1.hour < Time.now
end

.balance(user_id, proxy) ⇒ Object



103
104
105
106
# File 'lib/wavecrest.rb', line 103

def self.balance user_id, proxy
  resp = send_request :get, "/users/#{user_id}/cards/#{proxy}/balance"
  resp['avlBal'].to_i
end

.configure {|configuration| ... } ⇒ Object

Yields:



14
15
16
17
# File 'lib/wavecrest.rb', line 14

def self.configure
  self.configuration ||= Wavecrest::Configuration.new
  yield(configuration)
end

.countriesObject



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

def self.countries
  [
      'AX', 'AL', 'AD', 'AI', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'BS', 'BH', 'BB', 'BY', 'BE', 'BZ', 'BM', 'BT',
      'BQ', 'BA', 'BR', 'BN', 'BG', 'CA', 'CV', 'KY', 'CL', 'CN', 'CO', 'CR', 'HR', 'CW', 'CY', 'CZ', 'DK', 'DM',
      'DO', 'EC', 'SV', 'EE', 'FK', 'FO', 'FI', 'FR', 'GF', 'GE', 'DE', 'GI', 'GR', 'GL', 'GD', 'GP', 'GT', 'GG',
      'GY', 'HK', 'HU', 'IS', 'ID', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KR', 'XK', 'KW', 'LV',
      'LI', 'LT', 'LU', 'MK', 'MY', 'MV', 'MT', 'MQ', 'MU', 'YT', 'MX', 'MD', 'MC', 'MN', 'ME', 'MA', 'NP', 'NL',
      'NZ', 'NI', 'NO', 'OM', 'PA', 'PG', 'PY', 'PE', 'PH', 'PL', 'PT', 'QA', 'RE', 'RO', 'RU', 'BL', 'KN', 'LC',
      'MF', 'VC', 'SM', 'SA', 'RS', 'SC', 'SG', 'SX', 'SK', 'SI', 'ZA', 'ES', 'SR', 'SE', 'CH', 'TW', 'TH', 'TT',
      'TR', 'TC', 'UA', 'AE', 'GB', 'UY', 'VE', 'VG'
  ]
end

.details(user_id, proxy) ⇒ Object



109
110
111
# File 'lib/wavecrest.rb', line 109

def self.details user_id, proxy
  send_request :get, "/users/#{user_id}/cards/#{proxy}/carddetails"
end

.load_money(user_id, proxy, params = {}) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/wavecrest.rb', line 94

def self.load_money(user_id, proxy, params= {})
  default_params = {
      "channelType" => "1",
      "agentId" => configuration.partner_id
  }
  payload = default_params.merge params
  send_request :post, "/users/#{user_id}/cards/#{proxy}/load", payload
end

.request_card(params) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/wavecrest.rb', line 82

def self.request_card(params)
  default_params = {
      "cardProgramId" => "0",
      "Businesspartnerid" => configuration.partner_id,
      "channelType" => "1",
      # "deliveryType" => 'Standard Delivery Type',
      "localeTime" => Time.now
  }
  payload = default_params.merge params
  send_request :post, "/cards", payload
end

.send_request(method, path, params = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wavecrest.rb', line 56

def self.send_request method, path, params={}
  auth if auth_need?

  url = configuration.endpoint + "/v3/services" + path
  payload = params.to_json
  headers = {
      "DeveloperId" => configuration.user,
      "DeveloperPassword" => configuration.password,
      "AuthenticationToken" => auth_token,
      accept: :json,
      content_type: :json
  }

  begin
    RestClient.proxy = configuration.proxy if configuration.proxy
    request = RestClient::Request.new(method: method, url: url, payload: payload, headers: headers)
    response = request.execute.body
    RestClient.proxy = nil
    JSON.parse response
  rescue => e
    puts e.message, e.response
    return JSON.parse e.response
  end
end

.transactions(user_id, proxy) ⇒ Object



113
114
115
# File 'lib/wavecrest.rb', line 113

def self.transactions user_id, proxy
  send_request :post, "/users/#{user_id}/cards/#{proxy}/transactions", {txnCount: 10000}
end