aws_agcod 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/LICENSE.txt +1 -1
- data/README.md +9 -7
- data/lib/aws_agcod.rb +1 -1
- data/lib/aws_agcod/cancel_gift_card.rb +2 -2
- data/lib/aws_agcod/config.rb +3 -2
- data/lib/aws_agcod/create_gift_card.rb +12 -4
- data/lib/aws_agcod/gift_card_activity_list.rb +2 -2
- data/lib/aws_agcod/request.rb +5 -5
- data/lib/aws_agcod/response.rb +1 -1
- data/lib/aws_agcod/signature.rb +3 -3
- data/lib/aws_agcod/version.rb +2 -2
- data/spec/aws_agcod/cancel_gift_card_spec.rb +27 -0
- data/spec/aws_agcod/config_spec.rb +14 -0
- data/spec/aws_agcod/create_gift_card_spec.rb +83 -0
- data/spec/aws_agcod/gift_card_activity_list_spec.rb +74 -0
- data/spec/aws_agcod/request_spec.rb +48 -0
- data/spec/aws_agcod/response_spec.rb +66 -0
- data/spec/aws_agcod_spec.rb +12 -0
- data/spec/spec_helper.rb +17 -0
- metadata +35 -18
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjZjNzkxNmZhZWVmYzA4OTQzNTUxNWFhMmFjYmNjMDM5MjQwN2Q3OQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 655c7b1368611cacb12fba40bb8c7d41c2dc4df9
|
4
|
+
data.tar.gz: ec16be753d4e8488b1c9b642cfe3edc467649d9c
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NGM5NDIyZjI3YWUwZjAxYjkzZGJkZmNkOWZiZDA5MGM3ODEwOGM5ZmJhZTJh
|
11
|
-
YzdiZTc5YTFkNjIzYWY2OWU2OWRkZjNjY2UyNDU5MjM0M2I1ODM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmMyYzE5ODZiMjc0YThmMDQzY2U4ZDkzZWJhNThkZjI5NmM0MWIyNTMzNGU1
|
14
|
-
MmQ4M2QwODUxNDcwMGVjMzAyM2E3ZjE2Y2Q1Yjc4MTg2YWY0NTE3YTEzZDhj
|
15
|
-
OTI1YjRiZGY0Njk4OWQyYWE4NjAwM2YyN2Y5MmI3OTdhNThlYzY=
|
6
|
+
metadata.gz: 15bb4600aa4d6f812359f511855d7f42659ffe8a6d8b730b7b95f54bb014a45b5539fecda80f6fbbd7f9bf6ed7d0caf9b133a8ddfdc16185d36966e62f8a23c6
|
7
|
+
data.tar.gz: 0ec38ce66e43f14b6b98086d19f31df5604dd68e0a69759e8a4b75baf535650e82207e7d8fcb93d93686248077619349e7ac3fdee5ce8022e762d35c2e8da063
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# AGCOD
|
2
2
|
|
3
3
|
Amazon Gift Code On Demand (AGCOD) API v2 implementation for distribute Amazon gift cards (gift codes) instantly in any denomination.
|
4
4
|
|
@@ -25,12 +25,13 @@ Or install it yourself as:
|
|
25
25
|
```ruby
|
26
26
|
require "aws_agcod"
|
27
27
|
|
28
|
-
|
28
|
+
AGCOD.configure do |config|
|
29
29
|
config.access_key = "YOUR_ACCESS_KEY"
|
30
30
|
config.secret_key = "YOUR_SECRET_KEY"
|
31
31
|
config.partner_id = "PARTNER_ID"
|
32
32
|
config.uri = "https://agcod-v2-gamma.amazon.com" # default, sandbox endpoint
|
33
|
-
config.
|
33
|
+
config.region = "us-east-1" # default
|
34
|
+
config.timeout = 30 # default
|
34
35
|
end
|
35
36
|
```
|
36
37
|
|
@@ -38,9 +39,10 @@ end
|
|
38
39
|
|
39
40
|
```ruby
|
40
41
|
request_id = "test"
|
41
|
-
amount = 10
|
42
|
+
amount = 10
|
43
|
+
currency = "USD" # default to USD, available types are: USD, EUR, JPY, CNY, CAD
|
42
44
|
|
43
|
-
request =
|
45
|
+
request = AGCOD::CreateGiftCard.new(request_id, amount, currency)
|
44
46
|
|
45
47
|
# When succeed
|
46
48
|
if request.success?
|
@@ -59,7 +61,7 @@ end
|
|
59
61
|
request_id = "test"
|
60
62
|
gc_id = "test_gc_id"
|
61
63
|
|
62
|
-
request =
|
64
|
+
request = AGCOD::CancelGiftCard.new(request_id, gc_id)
|
63
65
|
|
64
66
|
# When failed
|
65
67
|
unless request.success?
|
@@ -77,7 +79,7 @@ page = 1
|
|
77
79
|
per_page = 100
|
78
80
|
show_no_ops = false # Wehther to show activities with no operation or not
|
79
81
|
|
80
|
-
request =
|
82
|
+
request = AGCOD::GiftCardActivityList.new(request_id, start_time, end_time, page, per_page, show_no_ops)
|
81
83
|
|
82
84
|
# When succeed
|
83
85
|
if request.success?
|
data/lib/aws_agcod.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "aws_agcod/request"
|
2
2
|
|
3
|
-
module
|
3
|
+
module AGCOD
|
4
4
|
class CancelGiftCard
|
5
5
|
extend Forwardable
|
6
6
|
|
@@ -8,7 +8,7 @@ module AwsAgcod
|
|
8
8
|
|
9
9
|
def initialize(request_id, gc_id)
|
10
10
|
@response = Request.new("CancelGiftCard",
|
11
|
-
"creationRequestId" => "#{
|
11
|
+
"creationRequestId" => "#{AGCOD.config.partner_id}#{request_id}",
|
12
12
|
"gcId" => gc_id
|
13
13
|
).response
|
14
14
|
end
|
data/lib/aws_agcod/config.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module AGCOD
|
2
2
|
class Config
|
3
|
-
attr_accessor :access_key, :secret_key, :uri, :partner_id, :region
|
3
|
+
attr_accessor :access_key, :secret_key, :uri, :partner_id, :region, :timeout
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
# API defaults
|
7
7
|
@uri = "https://agcod-v2-gamma.amazon.com"
|
8
8
|
@region = "us-east-1"
|
9
|
+
@timeout = 30
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -1,16 +1,24 @@
|
|
1
1
|
require "aws_agcod/request"
|
2
2
|
|
3
|
-
module
|
3
|
+
module AGCOD
|
4
|
+
class CreateGiftCardError < StandardError; end
|
5
|
+
|
4
6
|
class CreateGiftCard
|
5
7
|
extend Forwardable
|
6
8
|
|
9
|
+
CURRENCIES = %w(USD EUR JPY CNY CAD)
|
10
|
+
|
7
11
|
def_delegators :@response, :success?, :error_message
|
8
12
|
|
9
|
-
def initialize(request_id, amount)
|
13
|
+
def initialize(request_id, amount, currency = "USD")
|
14
|
+
unless CURRENCIES.include?(currency.to_s)
|
15
|
+
raise CreateGiftCardError, "Currency #{currency} not supported, available types are #{CURRENCIES.join(", ")}"
|
16
|
+
end
|
17
|
+
|
10
18
|
@response = Request.new("CreateGiftCard",
|
11
|
-
"creationRequestId" => "#{
|
19
|
+
"creationRequestId" => "#{AGCOD.config.partner_id}#{request_id}",
|
12
20
|
"value" => {
|
13
|
-
"currencyCode" =>
|
21
|
+
"currencyCode" => currency,
|
14
22
|
"amount" => amount
|
15
23
|
}
|
16
24
|
).response
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "aws_agcod/request"
|
2
2
|
|
3
|
-
module
|
3
|
+
module AGCOD
|
4
4
|
class GiftCardActivityListError < StandardError; end
|
5
5
|
|
6
6
|
class GiftCardActivity
|
@@ -34,7 +34,7 @@ module AwsAgcod
|
|
34
34
|
def_delegators :@response, :success?, :error_message
|
35
35
|
|
36
36
|
def initialize(request_id, start_time, end_time, page = 1, per_page = 100, show_no_ops = false)
|
37
|
-
raise
|
37
|
+
raise GiftCardActivityListError, "Only #{LIMIT} records allowed per request." if per_page > LIMIT
|
38
38
|
|
39
39
|
@response = Request.new("GetGiftCardActivityPage",
|
40
40
|
"requestId" => request_id,
|
data/lib/aws_agcod/request.rb
CHANGED
@@ -3,7 +3,7 @@ require "aws_agcod/response"
|
|
3
3
|
require "httparty"
|
4
4
|
require "yaml"
|
5
5
|
|
6
|
-
module
|
6
|
+
module AGCOD
|
7
7
|
class Request
|
8
8
|
TIME_FORMAT = "%Y%m%dT%H%M%SZ"
|
9
9
|
|
@@ -13,7 +13,7 @@ module AwsAgcod
|
|
13
13
|
@action = action
|
14
14
|
@params = params
|
15
15
|
|
16
|
-
@response = Response.new(HTTParty.post(uri, body: body, headers: signed_headers, timeout:
|
16
|
+
@response = Response.new(HTTParty.post(uri, body: body, headers: signed_headers, timeout: AGCOD.config.timeout).body)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
@@ -30,16 +30,16 @@ module AwsAgcod
|
|
30
30
|
"date" => time.to_s
|
31
31
|
}
|
32
32
|
|
33
|
-
Signature.new(
|
33
|
+
Signature.new(AGCOD.config).sign(uri, headers, body)
|
34
34
|
end
|
35
35
|
|
36
36
|
def uri
|
37
|
-
@uri ||= URI("#{
|
37
|
+
@uri ||= URI("#{AGCOD.config.uri}/#{@action}")
|
38
38
|
end
|
39
39
|
|
40
40
|
def body
|
41
41
|
@body ||= @params.merge(
|
42
|
-
"partnerId" =>
|
42
|
+
"partnerId" => AGCOD.config.partner_id
|
43
43
|
).to_json
|
44
44
|
end
|
45
45
|
end
|
data/lib/aws_agcod/response.rb
CHANGED
data/lib/aws_agcod/signature.rb
CHANGED
@@ -6,7 +6,7 @@ require "openssl"
|
|
6
6
|
require "uri"
|
7
7
|
require "pathname"
|
8
8
|
|
9
|
-
module
|
9
|
+
module AGCOD
|
10
10
|
class Signature
|
11
11
|
SERVICE = "AGCODService"
|
12
12
|
|
@@ -85,11 +85,11 @@ module AwsAgcod
|
|
85
85
|
# is a mechanism for calculating a message authentication code
|
86
86
|
# involving a hash function in combination with a secret key
|
87
87
|
def hmac(key, value)
|
88
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest
|
88
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), key, value)
|
89
89
|
end
|
90
90
|
|
91
91
|
def hexhmac(key, value)
|
92
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest
|
92
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), key, value)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
data/lib/aws_agcod/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module AGCOD
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/cancel_gift_card"
|
3
|
+
|
4
|
+
describe AGCOD::CancelGiftCard do
|
5
|
+
let(:partner_id) { "Testa" }
|
6
|
+
|
7
|
+
before do
|
8
|
+
AGCOD.configure do |config|
|
9
|
+
config.partner_id = partner_id
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context ".new" do
|
14
|
+
let(:request_id) { "test1" }
|
15
|
+
let(:gc_id) { "FOO" }
|
16
|
+
|
17
|
+
it "makes cancel request" do
|
18
|
+
expect(AGCOD::Request).to receive(:new) do |action, params|
|
19
|
+
expect(action).to eq("CancelGiftCard")
|
20
|
+
expect(params["creationRequestId"]).to eq("#{partner_id}#{request_id}")
|
21
|
+
expect(params["gcId"]).to eq(gc_id)
|
22
|
+
end.and_return(spy)
|
23
|
+
|
24
|
+
AGCOD::CancelGiftCard.new(request_id, gc_id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/config"
|
3
|
+
|
4
|
+
describe AGCOD::Config do
|
5
|
+
context ".new" do
|
6
|
+
let!(:config) { AGCOD::Config.new }
|
7
|
+
|
8
|
+
it "sets default uri and region" do
|
9
|
+
expect(config.uri).not_to be_nil
|
10
|
+
expect(config.region).not_to be_nil
|
11
|
+
expect(config.timeout).not_to be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/create_gift_card"
|
3
|
+
|
4
|
+
describe AGCOD::CreateGiftCard do
|
5
|
+
let(:partner_id) { "Testa" }
|
6
|
+
let(:request_id) { "test1" }
|
7
|
+
let(:amount) { 10 }
|
8
|
+
let(:currency) { AGCOD::CreateGiftCard::CURRENCIES.first }
|
9
|
+
let(:response) { spy }
|
10
|
+
|
11
|
+
before do
|
12
|
+
AGCOD.configure do |config|
|
13
|
+
config.partner_id = partner_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".new" do
|
18
|
+
context "when currency available" do
|
19
|
+
it "makes create request" do
|
20
|
+
expect(AGCOD::Request).to receive(:new) do |action, params|
|
21
|
+
expect(action).to eq("CreateGiftCard")
|
22
|
+
expect(params["creationRequestId"]).to eq("#{partner_id}#{request_id}")
|
23
|
+
expect(params["value"]).to eq(
|
24
|
+
"currencyCode" => currency,
|
25
|
+
"amount" => amount
|
26
|
+
)
|
27
|
+
end.and_return(response)
|
28
|
+
|
29
|
+
AGCOD::CreateGiftCard.new(request_id, amount, currency)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when currency not available" do
|
34
|
+
let(:currency) { "NOTEXIST" }
|
35
|
+
|
36
|
+
it "raises error" do
|
37
|
+
expect {
|
38
|
+
AGCOD::CreateGiftCard.new(request_id, amount, currency)
|
39
|
+
}.to raise_error(
|
40
|
+
AGCOD::CreateGiftCardError,
|
41
|
+
"Currency #{currency} not supported, available types are #{AGCOD::CreateGiftCard::CURRENCIES.join(", ")}"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
shared_context "request with response" do
|
48
|
+
let(:claim_code) { "FOO" }
|
49
|
+
let(:gc_id) { "BAR" }
|
50
|
+
let(:creation_request_id) { "BAZ" }
|
51
|
+
let(:payload) { {"gcClaimCode" => claim_code, "gcId" => gc_id, "creationRequestId" => creation_request_id} }
|
52
|
+
let(:request) { AGCOD::CreateGiftCard.new(request_id, amount, currency) }
|
53
|
+
|
54
|
+
before do
|
55
|
+
allow(AGCOD::Request).to receive(:new) { double(response: response) }
|
56
|
+
allow(response).to receive(:payload) { payload }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#claim_code" do
|
61
|
+
include_context "request with response"
|
62
|
+
|
63
|
+
it "returns claim_code" do
|
64
|
+
expect(request.claim_code).to eq(claim_code)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#gc_id" do
|
69
|
+
include_context "request with response"
|
70
|
+
|
71
|
+
it "returns gc_id" do
|
72
|
+
expect(request.gc_id).to eq(gc_id)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "#request_id" do
|
77
|
+
include_context "request with response"
|
78
|
+
|
79
|
+
it "returns creation request_id" do
|
80
|
+
expect(request.request_id).to eq(creation_request_id)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/gift_card_activity_list"
|
3
|
+
|
4
|
+
describe AGCOD::GiftCardActivityList do
|
5
|
+
let(:partner_id) { "Testa" }
|
6
|
+
let(:request_id) { "test1" }
|
7
|
+
let(:start_time) { double("start_time") }
|
8
|
+
let(:end_time) { double("end_time") }
|
9
|
+
let(:page) { 1 }
|
10
|
+
let(:per_page) { AGCOD::GiftCardActivityList::LIMIT }
|
11
|
+
let(:show_no_ops) { true }
|
12
|
+
let(:response) { spy }
|
13
|
+
|
14
|
+
before do
|
15
|
+
AGCOD.configure do |config|
|
16
|
+
config.partner_id = partner_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context ".new" do
|
21
|
+
it "makes request" do
|
22
|
+
expect(start_time).to receive(:strftime).with(
|
23
|
+
AGCOD::GiftCardActivityList::TIME_FORMAT
|
24
|
+
).and_return(start_time)
|
25
|
+
|
26
|
+
expect(end_time).to receive(:strftime).with(
|
27
|
+
AGCOD::GiftCardActivityList::TIME_FORMAT
|
28
|
+
).and_return(end_time)
|
29
|
+
|
30
|
+
expect(AGCOD::Request).to receive(:new) do |action, params|
|
31
|
+
expect(action).to eq("GetGiftCardActivityPage")
|
32
|
+
expect(params["requestId"]).to eq(request_id)
|
33
|
+
expect(params["utcStartDate"]).to eq(start_time)
|
34
|
+
expect(params["utcEndDate"]).to eq(end_time)
|
35
|
+
expect(params["pageIndex"]).to eq((page - 1) * per_page)
|
36
|
+
expect(params["pageSize"]).to eq(per_page)
|
37
|
+
expect(params["showNoOps"]).to eq(show_no_ops)
|
38
|
+
end.and_return(response)
|
39
|
+
|
40
|
+
AGCOD::GiftCardActivityList.new(request_id, start_time, end_time, page, per_page, show_no_ops)
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when request per_page reaches limit" do
|
44
|
+
let(:per_page) { AGCOD::GiftCardActivityList::LIMIT + 1 }
|
45
|
+
|
46
|
+
it "raises error" do
|
47
|
+
expect {
|
48
|
+
AGCOD::GiftCardActivityList.new(request_id, start_time, end_time, page, per_page, show_no_ops)
|
49
|
+
}.to raise_error(
|
50
|
+
AGCOD::GiftCardActivityListError,
|
51
|
+
"Only #{AGCOD::GiftCardActivityList::LIMIT} records allowed per request."
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "#results" do
|
58
|
+
let(:payload) { { "cardActivityList" => [double * 3] } }
|
59
|
+
let(:request) { AGCOD::GiftCardActivityList.new(request_id, start_time, end_time, page, per_page, show_no_ops) }
|
60
|
+
|
61
|
+
before do
|
62
|
+
allow(start_time).to receive(:strftime)
|
63
|
+
allow(end_time).to receive(:strftime)
|
64
|
+
allow(AGCOD::Request).to receive(:new) { double(response: response) }
|
65
|
+
allow(response).to receive(:payload) { payload }
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns GiftCardActivity instances" do
|
69
|
+
request.results.each do |item|
|
70
|
+
expec(item).to be_a(AGCOD::GiftCardActivity)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/request"
|
3
|
+
|
4
|
+
describe AGCOD::Request do
|
5
|
+
let(:action) { "Foo" }
|
6
|
+
let(:params) { {} }
|
7
|
+
let(:signature) { double("Signature") }
|
8
|
+
let(:signed_headers) { double("signed_headers") }
|
9
|
+
let(:base_uri) { "https://example.com" }
|
10
|
+
let(:partner_id) { "BAR" }
|
11
|
+
let(:timeout) { 10 }
|
12
|
+
let(:config) { double(uri: base_uri, partner_id: partner_id, timeout: timeout) }
|
13
|
+
|
14
|
+
context "#new" do
|
15
|
+
before do
|
16
|
+
allow(AGCOD).to receive(:config) { config }
|
17
|
+
allow(AGCOD::Signature).to receive(:new).with(config) { signature }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "sends post request to endpoint uri" do
|
21
|
+
expect(signature).to receive(:sign) do |uri, headers, body|
|
22
|
+
expect(uri).to eq(URI("#{base_uri}/#{action}"))
|
23
|
+
expect(headers.keys).to match_array(%w(content-type x-amz-date accept host x-amz-target date))
|
24
|
+
expect(headers["content-type"]).to eq("application/json")
|
25
|
+
expect(headers["x-amz-target"]).to eq("com.amazonaws.agcod.AGCODService.#{action}")
|
26
|
+
expect(JSON.parse(body)["partnerId"]).to eq(partner_id)
|
27
|
+
end.and_return(signed_headers)
|
28
|
+
|
29
|
+
expect(HTTParty).to receive(:post) do |uri, options|
|
30
|
+
expect(uri).to eq(URI("#{base_uri}/#{action}"))
|
31
|
+
expect(JSON.parse(options[:body])["partnerId"]).to eq(partner_id)
|
32
|
+
expect(options[:headers]).to eq(signed_headers)
|
33
|
+
expect(options[:timeout]).to eq(timeout)
|
34
|
+
end.and_return(double(body: params.to_json))
|
35
|
+
|
36
|
+
AGCOD::Request.new(action, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "sets response" do
|
40
|
+
expect(signature).to receive(:sign) { signed_headers }
|
41
|
+
expect(HTTParty).to receive(:post) { (double(body: params.to_json)) }
|
42
|
+
|
43
|
+
response = AGCOD::Request.new(action, params).response
|
44
|
+
|
45
|
+
expect(response).to be_a(AGCOD::Response)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "aws_agcod/response"
|
3
|
+
|
4
|
+
describe AGCOD::Response do
|
5
|
+
let(:payload) { { foo: "bar" }.to_json }
|
6
|
+
|
7
|
+
context "#new" do
|
8
|
+
it "sets payload and status" do
|
9
|
+
response = AGCOD::Response.new(payload)
|
10
|
+
|
11
|
+
expect(response.payload).not_to be_nil
|
12
|
+
expect(response.status).not_to be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when no status in payload" do
|
16
|
+
it "sets status to failure" do
|
17
|
+
expect(AGCOD::Response.new(payload).status).to eq("FAILURE")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when has status in payload" do
|
22
|
+
let(:status) { "foo" }
|
23
|
+
let(:payload) { { status: status }.to_json }
|
24
|
+
|
25
|
+
it "sets status as payload's status" do
|
26
|
+
expect(AGCOD::Response.new(payload).status).to eq(status)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when has agcodResponse in payload" do
|
31
|
+
let(:status) { "foo" }
|
32
|
+
let(:payload) { { agcodResponse: { status: status } }.to_json }
|
33
|
+
|
34
|
+
it "sets status as agcodResponse's status" do
|
35
|
+
expect(AGCOD::Response.new(payload).status).to eq(status)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "success?" do
|
41
|
+
context "when status is SUCCESS" do
|
42
|
+
let(:payload) { { status: "SUCCESS" }.to_json }
|
43
|
+
|
44
|
+
it "returns true" do
|
45
|
+
expect(AGCOD::Response.new(payload).success?).to be_truthy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when status is not SUCCESS" do
|
50
|
+
it "returns false" do
|
51
|
+
expect(AGCOD::Response.new(payload).success?).to be_falsey
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "error_message" do
|
57
|
+
let(:error_code) { "foo" }
|
58
|
+
let(:error_type) { "bar" }
|
59
|
+
let(:error_message) { "baz" }
|
60
|
+
let(:payload) { { errorCode: error_code, errorType: error_type, message: error_message }.to_json }
|
61
|
+
|
62
|
+
it "composes error message by error code, type, and message from payload" do
|
63
|
+
expect(AGCOD::Response.new(payload).error_message).to eq("#{error_code} #{error_type} - #{error_message}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
ROOT_PATH = Pathname.new(__FILE__).join("../..").expand_path
|
4
|
+
$LOAD_PATH.unshift(ROOT_PATH.join("lib"))
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Run specs in random order to surface order dependencies. If you find an
|
8
|
+
# order dependency and want to debug it, you can fix the order by providing
|
9
|
+
# the seed, which is printed after each run.
|
10
|
+
# --seed 1234
|
11
|
+
config.order = "random"
|
12
|
+
|
13
|
+
# Disable the should syntax compeletely; we use the expect syntax only.
|
14
|
+
config.expect_with :rspec do |c|
|
15
|
+
c.syntax = :expect
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,79 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_agcod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xenor Chang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.13'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.1'
|
62
|
-
- -
|
62
|
+
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: 3.1.0
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- - ~>
|
69
|
+
- - "~>"
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '3.1'
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 3.1.0
|
75
|
-
description:
|
76
|
-
Amazon
|
75
|
+
description: |-
|
76
|
+
Amazon Gift Code On Demand (AGCOD) API v2 implementation for
|
77
|
+
distribute Amazon gift cards (gift codes) instantly in any denomination
|
77
78
|
email:
|
78
79
|
- xenor@listia.com
|
79
80
|
executables: []
|
@@ -92,6 +93,14 @@ files:
|
|
92
93
|
- lib/aws_agcod/response.rb
|
93
94
|
- lib/aws_agcod/signature.rb
|
94
95
|
- lib/aws_agcod/version.rb
|
96
|
+
- spec/aws_agcod/cancel_gift_card_spec.rb
|
97
|
+
- spec/aws_agcod/config_spec.rb
|
98
|
+
- spec/aws_agcod/create_gift_card_spec.rb
|
99
|
+
- spec/aws_agcod/gift_card_activity_list_spec.rb
|
100
|
+
- spec/aws_agcod/request_spec.rb
|
101
|
+
- spec/aws_agcod/response_spec.rb
|
102
|
+
- spec/aws_agcod_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
95
104
|
homepage: https://github.com/listia/aws-agcod
|
96
105
|
licenses:
|
97
106
|
- MIT
|
@@ -102,18 +111,26 @@ require_paths:
|
|
102
111
|
- lib
|
103
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
113
|
requirements:
|
105
|
-
- -
|
114
|
+
- - ">="
|
106
115
|
- !ruby/object:Gem::Version
|
107
116
|
version: '0'
|
108
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
118
|
requirements:
|
110
|
-
- -
|
119
|
+
- - ">="
|
111
120
|
- !ruby/object:Gem::Version
|
112
121
|
version: '0'
|
113
122
|
requirements: []
|
114
123
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
116
125
|
signing_key:
|
117
126
|
specification_version: 4
|
118
127
|
summary: AWS AGCOD API v2 endpoints implementation
|
119
|
-
test_files:
|
128
|
+
test_files:
|
129
|
+
- spec/aws_agcod/cancel_gift_card_spec.rb
|
130
|
+
- spec/aws_agcod/config_spec.rb
|
131
|
+
- spec/aws_agcod/create_gift_card_spec.rb
|
132
|
+
- spec/aws_agcod/gift_card_activity_list_spec.rb
|
133
|
+
- spec/aws_agcod/request_spec.rb
|
134
|
+
- spec/aws_agcod/response_spec.rb
|
135
|
+
- spec/aws_agcod_spec.rb
|
136
|
+
- spec/spec_helper.rb
|