buyatabwrapper 0.1.2

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: c6d54ed29b78ba6e06ead5327f42b4b1818bad7b
4
+ data.tar.gz: 98d819452b64442fc753bda8472111b1e26e14d5
5
+ SHA512:
6
+ metadata.gz: ebf46892e638755ce5684b2c042654abad16a1a4f3b3bcaf8c73b0d2583819756897a2b9ea4d9217b73cc3e99cf273c3d73bac3f416fb1d93a57090e55570bc7
7
+ data.tar.gz: e94570defcff710ae6124873a3bb380b59c9f33f8e583b6db18f1effcf360ac778533596d073fc299a29a307f2d484928a9a52e9c2576117294a4705f89a78fc
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buyatabwrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ruslan Milevskiy
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,60 @@
1
+ # Buyatabwrapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'buyatabwrapper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install buyatabwrapper
20
+
21
+ ## Usage
22
+
23
+ Create a configuration file(`config/buyatabwrapper.yml`):
24
+
25
+ ```yaml
26
+ development: &default
27
+ user_name: your_username
28
+ password: your_password
29
+ api_token: your_apitoken
30
+ host: www.buyatab.com
31
+
32
+ test:
33
+ <<: *default
34
+
35
+ production:
36
+ user_name: your_username
37
+ password: your_password
38
+ api_token: your_apitoken
39
+ host: production_host
40
+ ```
41
+
42
+ Get merchants list
43
+
44
+ ```ruby
45
+ Buyatabwrapper.get_merchants
46
+ ```
47
+
48
+ Purchase card
49
+
50
+ ```ruby
51
+ Buyatabwrapper.purchase_card(merchant_id: '22', amount: '10.00')
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/[my-github-username]/buyatabwrapper/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buyatabwrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buyatabwrapper"
8
+ spec.version = Buyatabwrapper::VERSION
9
+ spec.authors = ["Ruslan Milevskiy"]
10
+ spec.email = ["rpmilevskiy@gmail.com"]
11
+ spec.summary = "Buyatabwarpper"
12
+ spec.description = ""
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'resultable'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'vcr'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'pry'
29
+ end
@@ -0,0 +1,92 @@
1
+ require 'net/http'
2
+ require 'resultable'
3
+ require "ostruct"
4
+ require "pathname"
5
+ require "yaml"
6
+ require "erb"
7
+ require 'json'
8
+
9
+ module Buyatabwrapper
10
+ class API
11
+ include Resultable
12
+
13
+ CALLS = {
14
+ get_merchants: {
15
+ url: '/gcp/services/BuyatabWS.asmx/GetMerchantList',
16
+ field_to_return: 'Merchants',
17
+ action_type: :get,
18
+ default_params: {}
19
+ },
20
+ purchase_card: {
21
+ url: '/gcp/services/BuyatabWS.asmx/PurchaseCard',
22
+ field_to_return: 'BATOrderNumber',
23
+ action_type: :post,
24
+ default_params: {
25
+ cardstyle_id: '0',
26
+ msg: '',
27
+ quantity: '1',
28
+ recipient_name: '',
29
+ recipient_email: '',
30
+ sender_name: '',
31
+ sender_email: '',
32
+ handle_delivery: 'true',
33
+ customer_ref_id: '',
34
+ opt_in: 'true'
35
+ }
36
+ }
37
+ }
38
+
39
+ attr_accessor :result, :config
40
+
41
+ def initialize
42
+ self.result = Result.new
43
+ self.config = parse_config_file
44
+ end
45
+
46
+ def send_request(type, params)
47
+ return result unless config
48
+
49
+ request = Net::HTTP::Post.new(CALLS[type][:url], initheader = {'Content-Type' => 'application/json'})
50
+ request.body = default_params(type).merge(params).to_json
51
+
52
+ http = Net::HTTP.new(config.host, 443).tap do |http|
53
+ http.use_ssl = true
54
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
+ end
56
+ response = http.request(request)
57
+ response = JSON.parse(response.body)["d"]
58
+
59
+ if response["Status"]["Success"]
60
+ if CALLS[type][:action_type] == :get
61
+ self.result = response[CALLS[type][:field_to_return]]
62
+ else
63
+ result.response = response[CALLS[type][:field_to_return]]
64
+ result.successful!
65
+ end
66
+ else
67
+ result.response = response["Status"]['Error']['Message']
68
+ end
69
+
70
+ result
71
+ end
72
+
73
+ private
74
+
75
+ def default_params(type)
76
+ {
77
+ username: config.user_name,
78
+ password: config.password,
79
+ apitoken: config.api_token
80
+ }.merge(CALLS[type][:default_params])
81
+ end
82
+
83
+ def parse_config_file
84
+ file = Rails.root.join("config").join("buyatabwrapper.yml")
85
+ data = YAML.load(ERB.new(IO.read(file)).result)[Rails.env] rescue nil
86
+
87
+ result.response = 'Provide configs in buyatabwrapper.yml file' unless data
88
+
89
+ data ? OpenStruct.new(data) : data
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Buyatabwrapper
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "buyatabwrapper/version"
2
+ require "buyatabwrapper/api"
3
+
4
+ module Buyatabwrapper
5
+ def self.purchase_card(params)
6
+ self.send_request(:purchase_card, params)
7
+ end
8
+
9
+ def self.get_merchants
10
+ self.send_request(:get_merchants)
11
+ end
12
+
13
+ def self.send_request(call_type, params = {})
14
+ api = Buyatabwrapper::API.new
15
+ api.send_request(call_type, params)
16
+ end
17
+ end
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.buyatab.com/gcp/services/BuyatabWS.asmx/GetMerchantList
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"username":"who2tryapi","password":"P8dFwyR22ed7dDjxxL","apitoken":"e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M="}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - private, max-age=0
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Access-Control-Allow-Origin:
32
+ - https://portal.buyatab.com
33
+ Access-Control-Allow-Headers:
34
+ - Content-Type
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, OPTIONS
37
+ Date:
38
+ - Wed, 08 Apr 2015 10:16:52 GMT
39
+ Content-Length:
40
+ - '757'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"d":{"__type":"MerchantResponse","Status":{"__type":"gcp.objects.Status","Error":{"ErrorCode":0,"Message":"SUCCESS","ExceptionDetails":"Test
44
+ Mode. Automatic Success."},"Success":true},"ServerTime":"08 April 2015 03:16:52","Merchants":[{"Id":22,"Name":"Test
45
+ Merchant","Amount":{"InitialAmount":100,"MinVal":10,"MaxVal":1000,"MaxTransVal":5000,"Open":true,"Range":"10,25,50,100,500"},"StyleUrl":"https://img.buyatab.com/gcp/view/cards/7/21/big/G01.jpg","StyleId":2994,"CardRestrictions":"None"},{"Id":12345,"Name":"Test
46
+ Merch 2","Amount":{"InitialAmount":50,"MinVal":10,"MaxVal":500,"MaxTransVal":5000,"Open":true,"Range":"10,25,50,100,500"},"StyleUrl":"https://images.buyatab.com/gcp/view/cards/7/21/big/G01.jpg","StyleId":2994,"CardRestrictions":"None"}]}}'
47
+ http_version:
48
+ recorded_at: Wed, 08 Apr 2015 10:18:18 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.buyatab.com/gcp/services/BuyatabWS.asmx/PurchaseCard
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"username":"wrong user","password":"P8dFwyR22ed7dDjxxL","apitoken":"e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M=","cardstyle_id":"0","msg":"","quantity":"1","recipient_name":"","recipient_email":"","sender_name":"","sender_email":"","handle_delivery":"true","customer_ref_id":"","opt_in":"true","merchant_id":"22","amount":"10.00"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - private, max-age=0
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Access-Control-Allow-Origin:
32
+ - https://portal.buyatab.com
33
+ Access-Control-Allow-Headers:
34
+ - Content-Type
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, OPTIONS
37
+ Date:
38
+ - Tue, 07 Apr 2015 12:35:22 GMT
39
+ Content-Length:
40
+ - '481'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"d":{"__type":"PurchaseResponse","Status":{"__type":"gcp.objects.Status","Error":{"ErrorCode":901,"Message":"Unauthorized
44
+ attempt. Please check credentials and try again.","ExceptionDetails":"Unauthorized
45
+ Access"},"Success":false},"ServerTime":"07 April 2015 05:35:22","AdditionalNotes":"","RemainingBalance":-1,"BATOrderNumber":0,"CustomerReferenceId":"","CustomerReferenceId2":"","OptIn":false,"Links":null,"CardNumbers":null,"CardPins":null,"ExternalURLs":null,"Secrets":null}}'
46
+ http_version:
47
+ recorded_at: Tue, 07 Apr 2015 12:36:48 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.buyatab.com/gcp/services/BuyatabWS.asmx/PurchaseCard
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"username":"wrong user","password":"P8dFwyR22ed7dDjxxL","apitoken":"e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M=","cardstyle_id":"0","msg":"","quantity":"1","recipient_name":"","recipient_email":"","sender_name":"","sender_email":"","handle_delivery":"true","customer_ref_id":"","opt_in":"true","merchant_id":"22","amount":"10.00"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - private, max-age=0
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Access-Control-Allow-Origin:
32
+ - https://portal.buyatab.com
33
+ Access-Control-Allow-Headers:
34
+ - Content-Type
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, OPTIONS
37
+ Date:
38
+ - Tue, 07 Apr 2015 12:35:21 GMT
39
+ Content-Length:
40
+ - '481'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"d":{"__type":"PurchaseResponse","Status":{"__type":"gcp.objects.Status","Error":{"ErrorCode":901,"Message":"Unauthorized
44
+ attempt. Please check credentials and try again.","ExceptionDetails":"Unauthorized
45
+ Access"},"Success":false},"ServerTime":"07 April 2015 05:35:21","AdditionalNotes":"","RemainingBalance":-1,"BATOrderNumber":0,"CustomerReferenceId":"","CustomerReferenceId2":"","OptIn":false,"Links":null,"CardNumbers":null,"CardPins":null,"ExternalURLs":null,"Secrets":null}}'
46
+ http_version:
47
+ recorded_at: Tue, 07 Apr 2015 12:36:47 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.buyatab.com/gcp/services/BuyatabWS.asmx/PurchaseCard
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"username":"who2tryapi","password":"P8dFwyR22ed7dDjxxL","apitoken":"e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M=","cardstyle_id":"0","msg":"","quantity":"1","recipient_name":"","recipient_email":"","sender_name":"","sender_email":"","handle_delivery":"true","customer_ref_id":"","opt_in":"true","merchant_id":"22","amount":"10.00"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - private, max-age=0
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Access-Control-Allow-Origin:
32
+ - https://portal.buyatab.com
33
+ Access-Control-Allow-Headers:
34
+ - Content-Type
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, OPTIONS
37
+ Date:
38
+ - Tue, 07 Apr 2015 12:35:20 GMT
39
+ Content-Length:
40
+ - '562'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"d":{"__type":"PurchaseResponse","Status":{"__type":"gcp.objects.Status","Error":{"ErrorCode":0,"Message":"SUCCESS","ExceptionDetails":"Test
44
+ Mode Success."},"Success":true},"ServerTime":"07 April 2015 05:35:20","AdditionalNotes":"|
45
+ Test Mode Enabled.\r\n","RemainingBalance":12345.00,"BATOrderNumber":12345,"CustomerReferenceId":"","CustomerReferenceId2":"","OptIn":false,"Links":["https://www.buyatab.com/gcp/ecard.aspx?Id=JjD4DcN3vDv7IINuKFrweg%3d%3d"],"CardNumbers":["1234567890123456"],"CardPins":["1234"],"ExternalURLs":["someurl.com"],"Secrets":["shhh"]}}'
46
+ http_version:
47
+ recorded_at: Tue, 07 Apr 2015 12:36:46 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.buyatab.com/gcp/services/BuyatabWS.asmx/PurchaseCard
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"username":"who2tryapi","password":"P8dFwyR22ed7dDjxxL","apitoken":"e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M=","cardstyle_id":"0","msg":"","quantity":"1","recipient_name":"","recipient_email":"","sender_name":"","sender_email":"","handle_delivery":"true","customer_ref_id":"","opt_in":"true","merchant_id":"22","amount":"10.00"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - private, max-age=0
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Access-Control-Allow-Origin:
32
+ - https://portal.buyatab.com
33
+ Access-Control-Allow-Headers:
34
+ - Content-Type
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, OPTIONS
37
+ Date:
38
+ - Tue, 07 Apr 2015 12:35:17 GMT
39
+ Content-Length:
40
+ - '562'
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"d":{"__type":"PurchaseResponse","Status":{"__type":"gcp.objects.Status","Error":{"ErrorCode":0,"Message":"SUCCESS","ExceptionDetails":"Test
44
+ Mode Success."},"Success":true},"ServerTime":"07 April 2015 05:35:17","AdditionalNotes":"|
45
+ Test Mode Enabled.\r\n","RemainingBalance":12345.00,"BATOrderNumber":12345,"CustomerReferenceId":"","CustomerReferenceId2":"","OptIn":false,"Links":["https://www.buyatab.com/gcp/ecard.aspx?Id=JjD4DcN3vDv7IINuKFrweg%3d%3d"],"CardNumbers":["1234567890123456"],"CardPins":["1234"],"ExternalURLs":["someurl.com"],"Secrets":["shhh"]}}'
46
+ http_version:
47
+ recorded_at: Tue, 07 Apr 2015 12:36:43 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,5 @@
1
+ test:
2
+ user_name: who2tryapi
3
+ password: P8dFwyR22ed7dDjxxL
4
+ api_token: e2ZE7/H6mASptB3pfTjGgj/nYXQxGn8b3ltiLEkQc4M=
5
+ host: www.buyatab.com
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buyatabwrapper::API do
4
+ subject { Buyatabwrapper::API.new }
5
+
6
+ class Rails
7
+ def self.root
8
+ Pathname.new("./spec/").realpath
9
+ end
10
+
11
+ def self.env
12
+ 'test'
13
+ end
14
+ end
15
+
16
+ describe '.send_request', :vcr do
17
+ context 'with configs' do
18
+ context 'for purchase_card call' do
19
+ let(:params) {{ merchant_id: '22', amount: '10.00' }}
20
+
21
+ it 'returns successful result' do
22
+ expect(subject.send_request(:purchase_card, params).successful?).to be_truthy
23
+ end
24
+
25
+ it 'returns response' do
26
+ expect(subject.send_request(:purchase_card, params).response).to eq(12345)
27
+ end
28
+ end
29
+
30
+ context 'for get_merchants call' do
31
+ it 'returns list of merchants' do
32
+ expect(subject.send_request(:get_merchants, {}).map{ |m| m['Id']}).to eq([22, 12345])
33
+ end
34
+ end
35
+
36
+ context 'for invalid params' do
37
+ let(:params) {{ merchant_id: '22', amount: '10.00', username: 'wrong user' }}
38
+
39
+ it 'returns unsuccessful result' do
40
+ expect(subject.send_request(:purchase_card, params).successful?).to be_falsey
41
+ end
42
+
43
+ it 'returns error' do
44
+ expect(subject.send_request(:purchase_card, params).response).to eq('Unauthorized attempt. Please check credentials and try again.')
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'without configs' do
50
+ let(:params) {{ shop_card_id: 3266, to_email: 'rpmilevskiy@gmail.com' }}
51
+
52
+ before do
53
+ allow(Rails).to receive(:env).and_return('wrong')
54
+ end
55
+
56
+ it 'returns unsuccessful result' do
57
+ expect(subject.send_request(:purchase_card, params).successful?).to be_falsey
58
+ end
59
+
60
+ it 'returns error' do
61
+ expect(subject.send_request(:purchase_card, params).response).to eq('Provide configs in buyatabwrapper.yml file')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buyatabwrapper do
4
+ describe '.purchase_card' do
5
+ let(:params) {{ card_number: 123 }}
6
+
7
+ it 'calls selfs send_request' do
8
+ expect(Buyatabwrapper).to receive(:send_request).with(:purchase_card, card_number: 123)
9
+ Buyatabwrapper.purchase_card(params)
10
+ end
11
+ end
12
+
13
+ describe '.get_merchants' do
14
+ it 'calls selfs send_request' do
15
+ expect(Buyatabwrapper).to receive(:send_request).with(:get_merchants)
16
+ Buyatabwrapper.get_merchants
17
+ end
18
+ end
19
+
20
+ describe '.send_request' do
21
+ let(:params) {{ card_number: 123 }}
22
+ let(:api) { double('api') }
23
+
24
+ before { allow(Buyatabwrapper::API).to receive(:new).and_return(api) }
25
+
26
+ it 'calls apis send_request' do
27
+ expect(api).to receive(:send_request).with(:purchase_card, card_number: 123)
28
+ Buyatabwrapper.send_request(:purchase_card, params)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'buyatabwrapper'
2
+ require 'pry'
3
+ require 'vcr'
4
+ require 'webmock'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/cassettes'
8
+ c.hook_into :webmock
9
+ c.configure_rspec_metadata!
10
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buyatabwrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Ruslan Milevskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: resultable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ''
112
+ email:
113
+ - rpmilevskiy@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - buyatabwrapper.gemspec
124
+ - lib/buyatabwrapper.rb
125
+ - lib/buyatabwrapper/api.rb
126
+ - lib/buyatabwrapper/version.rb
127
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_get_merchants_call/returns_list_of_merchants.yml
128
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_invalid_params/returns_error.yml
129
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_invalid_params/returns_unsuccessful_result.yml
130
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_purchase_card_call/returns_response.yml
131
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_purchase_card_call/returns_successful_result.yml
132
+ - spec/config/buyatabwrapper.yml
133
+ - spec/lib/buyatabwrapper/api_spec.rb
134
+ - spec/lib/buyatabwrapper_spec.rb
135
+ - spec/spec_helper.rb
136
+ - tasks/rspec.rake
137
+ homepage: ''
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Buyatabwarpper
161
+ test_files:
162
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_get_merchants_call/returns_list_of_merchants.yml
163
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_invalid_params/returns_error.yml
164
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_invalid_params/returns_unsuccessful_result.yml
165
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_purchase_card_call/returns_response.yml
166
+ - spec/cassettes/Buyatabwrapper_API/_send_request/with_configs/for_purchase_card_call/returns_successful_result.yml
167
+ - spec/config/buyatabwrapper.yml
168
+ - spec/lib/buyatabwrapper/api_spec.rb
169
+ - spec/lib/buyatabwrapper_spec.rb
170
+ - spec/spec_helper.rb