gyftwrapper 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +3 -0
- data/gyftwrapper.gemspec +30 -0
- data/lib/gyftwrapper.rb +13 -0
- data/lib/gyftwrapper/api.rb +67 -0
- data/lib/gyftwrapper/version.rb +3 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_error.yml +54 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_unsuccessful_result.yml +54 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_error.yml +52 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_unsuccessful_result.yml +52 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_response.yml +52 -0
- data/spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_successful_result.yml +52 -0
- data/spec/config/gyftwrapper.yml +4 -0
- data/spec/gyftwrapper/api_spec.rb +74 -0
- data/spec/gyftwrapper_spec.rb +21 -0
- data/spec/spec_helper.rb +14 -0
- data/tasks/rspec.rake +3 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45ae9c41cac6ac566923edd15dc1bbc3ecf363b4
|
4
|
+
data.tar.gz: 053cdca66820bbc0d5112573054853490c61b8b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53241b1b0a125e5f53208c1b29222b902c367a65a1a10156ca0cf46f7cb8cc86e0b03dfb0b1844dfc7aa6546df709367fb8fc0fd1dab0606a33c34157a81e610
|
7
|
+
data.tar.gz: a512e552e96b857e7de11b1e9160d7d7a6a504b032218e9c8b914f972fa3c7b65749b8f4f62535ee35fe6040d5e29bd6735620837b735184cefc6bccc49ca614
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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,53 @@
|
|
1
|
+
# Gyftwrapper
|
2
|
+
|
3
|
+
The Gyftwrapper provides Ruby APIs to purchase cards using the Gyft API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gyftwrapper'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gyftwrapper
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create a configuration file(`config/gyftwrapper.yml`):
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
development: &default
|
27
|
+
api_key: your_key
|
28
|
+
api_secret: your_secret
|
29
|
+
endpoint: https://apitest.gyft.com/mashery/v1
|
30
|
+
|
31
|
+
test:
|
32
|
+
<<: *default
|
33
|
+
|
34
|
+
production:
|
35
|
+
api_key: your_key
|
36
|
+
api_secret: your_secret
|
37
|
+
endpoint: https://api.gyft.com/mashery/v1
|
38
|
+
```
|
39
|
+
|
40
|
+
Purchase shop card
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
Gyftwrapper.purchase_card(shop_card_id: 123, to_email: 'test@email.com')
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( https://github.com/[my-github-username]/gyftwrapper/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/gyftwrapper.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gyftwrapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gyftwrapper"
|
8
|
+
spec.version = Gyftwrapper::VERSION
|
9
|
+
spec.authors = ["Ruslan Milevskiy"]
|
10
|
+
spec.email = ["rpmilevskiy@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby gem for Gyft API}
|
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 'rest-client'
|
22
|
+
spec.add_dependency 'resultable'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'vcr'
|
28
|
+
spec.add_development_dependency 'webmock'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
data/lib/gyftwrapper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "gyftwrapper/version"
|
2
|
+
require "gyftwrapper/api"
|
3
|
+
|
4
|
+
module Gyftwrapper
|
5
|
+
def self.purchase_card(params)
|
6
|
+
self.send_request(:purchase_card, params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.send_request(call_type, params)
|
10
|
+
api = Gyftwrapper::API.new
|
11
|
+
api.send(call_type, params)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'rest-client'
|
3
|
+
require "ostruct"
|
4
|
+
require "pathname"
|
5
|
+
require "yaml"
|
6
|
+
require "erb"
|
7
|
+
require 'resultable'
|
8
|
+
|
9
|
+
module Gyftwrapper
|
10
|
+
class API
|
11
|
+
include Resultable
|
12
|
+
|
13
|
+
CALLS = {
|
14
|
+
purchase_card: '/reseller/purchase/card'
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :result, :config
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
self.result = Result.new
|
21
|
+
self.config = parse_config_file
|
22
|
+
end
|
23
|
+
|
24
|
+
def purchase_card(params)
|
25
|
+
send_request do
|
26
|
+
RestClient.post(url_for(:purchase_card), params, 'x-sig-timestamp' => timestamp)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def send_request
|
33
|
+
return result unless config
|
34
|
+
|
35
|
+
begin
|
36
|
+
result.response = OpenStruct.new(JSON.parse(yield))
|
37
|
+
result.successful!
|
38
|
+
rescue => e
|
39
|
+
result.response = e.response
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def url_for(call_type)
|
46
|
+
"#{config.endpoint}#{CALLS[call_type]}?api_key=#{config.api_key}&sig=#{signature}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def timestamp
|
50
|
+
Time.now.getutc.to_i.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def signature
|
54
|
+
signature_string = config.api_key + config.api_secret + timestamp
|
55
|
+
Digest::SHA256.new.hexdigest(signature_string)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_config_file
|
59
|
+
file = Rails.root.join("config").join("gyftwrapper.yml")
|
60
|
+
data = YAML.load(ERB.new(IO.read(file)).result)[Rails.env] rescue nil
|
61
|
+
|
62
|
+
result.response = 'Provide configs in gyftwrapper.yml file' unless data
|
63
|
+
|
64
|
+
data ? OpenStruct.new(data) : data
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=57df75e96cd2d78290071e17dde29f9be30910542dfa6441e1c9564e606a7a3b
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=111
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564398'
|
16
|
+
Content-Length:
|
17
|
+
- '16'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 400
|
25
|
+
message: Bad Request
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:39 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Content-Length:
|
44
|
+
- '253'
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: "[ServiceException] Cannot find shop card for purchase: kwpbn8ff4cb5aueu329kq5u7,
|
50
|
+
ResellerPurchaseCardRequest{shop_card_id=111, reseller_reference=null, to_email=null,
|
51
|
+
return_direct_link=false, first_name=null, last_name=null, gender=null, birthday=null}"
|
52
|
+
http_version:
|
53
|
+
recorded_at: Thu, 05 Mar 2015 14:06:39 GMT
|
54
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=135f041ea54ef965eea78d4f21bf9870c3a9453a0d702acb11f1398ad3a55dab
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=111
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564397'
|
16
|
+
Content-Length:
|
17
|
+
- '16'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 400
|
25
|
+
message: Bad Request
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:37 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Transfer-Encoding:
|
44
|
+
- chunked
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: "[ServiceException] Cannot find shop card for purchase: kwpbn8ff4cb5aueu329kq5u7,
|
50
|
+
ResellerPurchaseCardRequest{shop_card_id=111, reseller_reference=null, to_email=null,
|
51
|
+
return_direct_link=false, first_name=null, last_name=null, gender=null, birthday=null}"
|
52
|
+
http_version:
|
53
|
+
recorded_at: Thu, 05 Mar 2015 14:06:38 GMT
|
54
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=c062b24cc15d920a33ca5087ea42fcf8fc4f1f3c16f6c19f483abd77acc451b0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=3266&to_email=123
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564400'
|
16
|
+
Content-Length:
|
17
|
+
- '30'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 400
|
25
|
+
message: Bad Request
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:41 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Transfer-Encoding:
|
44
|
+
- chunked
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: "[ServiceException] Email address is not valid: 123"
|
50
|
+
http_version:
|
51
|
+
recorded_at: Thu, 05 Mar 2015 14:06:41 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=455ce60ef50e9ddf642ad969aa7347e63694c3e2d5bf072345ac7cae58ae903d
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=3266&to_email=123
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564399'
|
16
|
+
Content-Length:
|
17
|
+
- '30'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 400
|
25
|
+
message: Bad Request
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:39 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Content-Length:
|
44
|
+
- '50'
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: "[ServiceException] Email address is not valid: 123"
|
50
|
+
http_version:
|
51
|
+
recorded_at: Thu, 05 Mar 2015 14:06:40 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=9b7349a83f7bf92d1e036adde01dbc7f65c1277cfdf57fb05c58beca23ad7b47
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=3266&to_email=rpmilevskiy%40gmail.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564396'
|
16
|
+
Content-Length:
|
17
|
+
- '50'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:37 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Content-Length:
|
44
|
+
- '55'
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: '{"id":21191,"url":"https://apptest.gyft.com/redirect/"}'
|
50
|
+
http_version:
|
51
|
+
recorded_at: Thu, 05 Mar 2015 14:06:37 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://apitest.gyft.com/mashery/v1/reseller/purchase/card?api_key=kwpbn8ff4cb5aueu329kq5u7&sig=a63d5051de8d828717c9ed64dbc2833040253bca6d48c1d291fc66245a5788cc
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: shop_card_id=3266&to_email=rpmilevskiy%40gmail.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
X-Sig-Timestamp:
|
15
|
+
- '1425564395'
|
16
|
+
Content-Length:
|
17
|
+
- '50'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
User-Agent:
|
21
|
+
- Ruby
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, max-age=0, must-revalidate, private
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Thu, 05 Mar 2015 14:06:36 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Apache-Coyote/1.1
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15768000
|
41
|
+
Vary:
|
42
|
+
- Accept-Encoding
|
43
|
+
Content-Length:
|
44
|
+
- '55'
|
45
|
+
Connection:
|
46
|
+
- keep-alive
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: '{"id":21190,"url":"https://apptest.gyft.com/redirect/"}'
|
50
|
+
http_version:
|
51
|
+
recorded_at: Thu, 05 Mar 2015 14:06:36 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gyftwrapper::API do
|
4
|
+
subject { Gyftwrapper::API.new }
|
5
|
+
|
6
|
+
class Rails
|
7
|
+
def self.root
|
8
|
+
Pathname.new(".").realpath
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.env
|
12
|
+
'test'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with configs' do
|
17
|
+
before do
|
18
|
+
path_to_configs = Pathname.new("./spec").realpath
|
19
|
+
allow(Rails).to receive(:root).and_return(path_to_configs)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.purchase_card', :vcr do
|
23
|
+
context 'for valid params' do
|
24
|
+
let(:params) {{ shop_card_id: 3266, to_email: 'rpmilevskiy@gmail.com' }}
|
25
|
+
|
26
|
+
it 'returns successful result' do
|
27
|
+
expect(subject.purchase_card(params).successful?).to be_truthy
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns response' do
|
31
|
+
expect(subject.purchase_card(params).response.id).to_not be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'for invalid params' do
|
36
|
+
context 'shop_card_id' do
|
37
|
+
let(:params) {{ shop_card_id: 111 }}
|
38
|
+
|
39
|
+
it 'returns unsuccessful result' do
|
40
|
+
expect(subject.purchase_card(params).successful?).to be_falsey
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns error' do
|
44
|
+
expect(subject.purchase_card(params).response).to include('Cannot find shop card for purchase')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'to_email' do
|
49
|
+
let(:params) {{ shop_card_id: 3266, to_email: '123' }}
|
50
|
+
|
51
|
+
it 'returns unsuccessful result' do
|
52
|
+
expect(subject.purchase_card(params).successful?).to be_falsey
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns error' do
|
56
|
+
expect(subject.purchase_card(params).response).to include('Email address is not valid')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'without configs' do
|
64
|
+
let(:params) {{ shop_card_id: 3266, to_email: 'rpmilevskiy@gmail.com' }}
|
65
|
+
|
66
|
+
it 'returns unsuccessful result' do
|
67
|
+
expect(subject.purchase_card(params).successful?).to be_falsey
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns error' do
|
71
|
+
expect(subject.purchase_card(params).response).to eq('Provide configs in gyftwrapper.yml file')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gyftwrapper do
|
4
|
+
describe '.purchase_card' do
|
5
|
+
it 'calls send request method with appropriate call type' do
|
6
|
+
expect(Gyftwrapper).to receive(:send_request).with(:purchase_card, {})
|
7
|
+
Gyftwrapper.purchase_card({})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.send_request' do
|
12
|
+
let(:api) { double('api', purchase: true) }
|
13
|
+
|
14
|
+
before { allow(Gyftwrapper::API).to receive(:new).and_return(api) }
|
15
|
+
|
16
|
+
it 'calls appropriate api method' do
|
17
|
+
expect(api).to receive(:purchase).and_return(true)
|
18
|
+
Gyftwrapper.send_request(:purchase, {})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'gyftwrapper'
|
2
|
+
require 'vcr'
|
3
|
+
require 'webmock'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
VCR.configure do |c|
|
7
|
+
c.cassette_library_dir = 'spec/cassettes'
|
8
|
+
c.hook_into :webmock
|
9
|
+
c.configure_rspec_metadata!
|
10
|
+
c.default_cassette_options = {
|
11
|
+
:match_requests_on => [:method,
|
12
|
+
VCR.request_matchers.uri_without_param(:sig)]
|
13
|
+
}
|
14
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gyftwrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruslan Milevskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
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: resultable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
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: vcr
|
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: webmock
|
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
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: ''
|
126
|
+
email:
|
127
|
+
- rpmilevskiy@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- gyftwrapper.gemspec
|
138
|
+
- lib/gyftwrapper.rb
|
139
|
+
- lib/gyftwrapper/api.rb
|
140
|
+
- lib/gyftwrapper/version.rb
|
141
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_error.yml
|
142
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_unsuccessful_result.yml
|
143
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_error.yml
|
144
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_unsuccessful_result.yml
|
145
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_response.yml
|
146
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_successful_result.yml
|
147
|
+
- spec/config/gyftwrapper.yml
|
148
|
+
- spec/gyftwrapper/api_spec.rb
|
149
|
+
- spec/gyftwrapper_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- tasks/rspec.rake
|
152
|
+
homepage: ''
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.4.6
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Ruby gem for Gyft API
|
176
|
+
test_files:
|
177
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_error.yml
|
178
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/shop_card_id/returns_unsuccessful_result.yml
|
179
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_error.yml
|
180
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_invalid_params/to_email/returns_unsuccessful_result.yml
|
181
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_response.yml
|
182
|
+
- spec/cassettes/Gyftwrapper_API/with_configs/_purchase_card/for_valid_params/returns_successful_result.yml
|
183
|
+
- spec/config/gyftwrapper.yml
|
184
|
+
- spec/gyftwrapper/api_spec.rb
|
185
|
+
- spec/gyftwrapper_spec.rb
|
186
|
+
- spec/spec_helper.rb
|