wavecrest 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a49d66cf3209565478aa3034bc45457e2b1fd43
4
+ data.tar.gz: 910c61b075575da63bf6b25c13f3a99eac063c21
5
+ SHA512:
6
+ metadata.gz: 8378500b478341c779e55d3d6529c9d630db50baef65170c7acac0b694eddfa5b04581b99f519e040d33aec95bd6a0c4b8dc797254d15f13772efada6b117a25
7
+ data.tar.gz: 4712ae59303167fdf48af7ecb31bb73c55e2b8e46791cd4189af9328a0a5caf18aba2c38ecb3732b6c84d21d2c649600ed67bdb137ed04de3439a2f8a2ca727d
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 vadim
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Wavecrest
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wavecrest'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wavecrest
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Wavecrest
2
+ class Configuration
3
+ attr_accessor :endpoint, :user, :password, :partner_id, :proxy
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Wavecrest
2
+ VERSION = "0.0.1"
3
+ end
data/lib/wavecrest.rb ADDED
@@ -0,0 +1,116 @@
1
+ require 'rest_client'
2
+ require 'net/http'
3
+ require 'json'
4
+ require "wavecrest/version"
5
+ require "wavecrest/configuration"
6
+
7
+
8
+ module Wavecrest
9
+ # autoload :Wavecrest, 'wavecrest'
10
+ class << self
11
+ attr_accessor :configuration, :auth_token, :auth_token_issued
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Wavecrest::Configuration.new
16
+ yield(configuration)
17
+ end
18
+
19
+ def self.countries
20
+ [
21
+ 'AX', 'AL', 'AD', 'AI', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'BS', 'BH', 'BB', 'BY', 'BE', 'BZ', 'BM', 'BT',
22
+ 'BQ', 'BA', 'BR', 'BN', 'BG', 'CA', 'CV', 'KY', 'CL', 'CN', 'CO', 'CR', 'HR', 'CW', 'CY', 'CZ', 'DK', 'DM',
23
+ 'DO', 'EC', 'SV', 'EE', 'FK', 'FO', 'FI', 'FR', 'GF', 'GE', 'DE', 'GI', 'GR', 'GL', 'GD', 'GP', 'GT', 'GG',
24
+ 'GY', 'HK', 'HU', 'IS', 'ID', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KR', 'XK', 'KW', 'LV',
25
+ 'LI', 'LT', 'LU', 'MK', 'MY', 'MV', 'MT', 'MQ', 'MU', 'YT', 'MX', 'MD', 'MC', 'MN', 'ME', 'MA', 'NP', 'NL',
26
+ 'NZ', 'NI', 'NO', 'OM', 'PA', 'PG', 'PY', 'PE', 'PH', 'PL', 'PT', 'QA', 'RE', 'RO', 'RU', 'BL', 'KN', 'LC',
27
+ 'MF', 'VC', 'SM', 'SA', 'RS', 'SC', 'SG', 'SX', 'SK', 'SI', 'ZA', 'ES', 'SR', 'SE', 'CH', 'TW', 'TH', 'TT',
28
+ 'TR', 'TC', 'UA', 'AE', 'GB', 'UY', 'VE', 'VG'
29
+ ]
30
+ end
31
+
32
+ def self.auth_need?
33
+ not auth_token or auth_token_issued and auth_token_issued + 1.hour < Time.now
34
+ end
35
+
36
+ def self.auth
37
+ url = configuration.endpoint + "/v3/services/authenticator"
38
+
39
+ headers = {
40
+ "DeveloperId" => configuration.user,
41
+ "DeveloperPassword" => configuration.password,
42
+ "X-Method-Override" => 'login',
43
+ accept: :json,
44
+ content_type: :json
45
+ }
46
+
47
+ RestClient.proxy = configuration.proxy if configuration.proxy
48
+ request = RestClient::Request.new(method: :post, url: url, headers: headers)
49
+ response = request.execute.body
50
+ data = JSON.parse response
51
+ self.auth_token = data["token"]
52
+ self.auth_token_issued = Time.now
53
+ end
54
+
55
+
56
+ def self.send_request method, path, params={}
57
+ auth if auth_need?
58
+
59
+ url = configuration.endpoint + "/v3/services" + path
60
+ payload = params.to_json
61
+ headers = {
62
+ "DeveloperId" => configuration.user,
63
+ "DeveloperPassword" => configuration.password,
64
+ "AuthenticationToken" => auth_token,
65
+ accept: :json,
66
+ content_type: :json
67
+ }
68
+
69
+ begin
70
+ RestClient.proxy = configuration.proxy if configuration.proxy
71
+ request = RestClient::Request.new(method: method, url: url, payload: payload, headers: headers)
72
+ response = request.execute.body
73
+ RestClient.proxy = nil
74
+ JSON.parse response
75
+ rescue => e
76
+ puts e.message, e.response
77
+ return JSON.parse e.response
78
+ end
79
+ end
80
+
81
+
82
+ def self.request_card(params)
83
+ default_params = {
84
+ "cardProgramId" => "0",
85
+ "Businesspartnerid" => configuration.partner_id,
86
+ "channelType" => "1",
87
+ # "deliveryType" => 'Standard Delivery Type',
88
+ "localeTime" => Time.now
89
+ }
90
+ payload = default_params.merge params
91
+ send_request :post, "/cards", payload
92
+ end
93
+
94
+ def self.load_money(user_id, proxy, params= {})
95
+ default_params = {
96
+ "channelType" => "1",
97
+ "agentId" => configuration.partner_id
98
+ }
99
+ payload = default_params.merge params
100
+ send_request :post, "/users/#{user_id}/cards/#{proxy}/load", payload
101
+ end
102
+
103
+ def self.balance user_id, proxy
104
+ resp = send_request :get, "/users/#{user_id}/cards/#{proxy}/balance"
105
+ resp['avlBal'].to_i
106
+ end
107
+
108
+
109
+ def self.details user_id, proxy
110
+ send_request :get, "/users/#{user_id}/cards/#{proxy}/carddetails"
111
+ end
112
+
113
+ def self.transactions user_id, proxy
114
+ send_request :post, "/users/#{user_id}/cards/#{proxy}/transactions", {txnCount: 10000}
115
+ end
116
+ end
data/wavecrest.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/wavecrest/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "wavecrest"
6
+ spec.version = Wavecrest::VERSION
7
+ spec.authors = ["Vadim Marchenko"]
8
+ spec.email = ["just.zimer@gmail.com"]
9
+ spec.description = 'Gem for wavecrest API'
10
+ spec.summary = ''
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+
22
+ spec.add_runtime_dependency 'rest-client'
23
+ spec.add_runtime_dependency 'json'
24
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wavecrest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vadim Marchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem for wavecrest API
70
+ email:
71
+ - just.zimer@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - lib/wavecrest.rb
81
+ - lib/wavecrest/configuration.rb
82
+ - lib/wavecrest/version.rb
83
+ - wavecrest.gemspec
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.14
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: ''
108
+ test_files: []