aws_agcod_2 1.1.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57228cfced3a4ce27d86778e5458cb28c6dd00490880ae22db9ef8c2b1ca456e
4
- data.tar.gz: f06da4395c979dba879ef0aaced9bbdd6ad79958b3514340d6ccbed0bfec74f0
3
+ metadata.gz: 1d03083227c8e83a78a5bd5080293fd21682bfd9d94d979ab6465f9848f18b3a
4
+ data.tar.gz: 41d35ecbde14d73906af7ab4e08c5c00c1c2768f49bd82ed4cb56e3d13aaeea2
5
5
  SHA512:
6
- metadata.gz: 7384eddccb0d643c91eb8e6c00ea515333b7a9a602b46200f2bda20d1d5464e49c02dbc36b3d650de43ffc27aa9a5fc6bc35349a6ae6b1007f92400545e3b12a
7
- data.tar.gz: 7971db886d28511ba4818d283b8c3245ac0cf14f850d14ea58539e8b574293ae4d7b75454d0661574556bd6b7348a83dfe8d11bec623071e7efa0c187aef5a79
6
+ metadata.gz: 19b706ad529e1578c7116051b54a90d1432de36ea1ffcf442e67eaa2dc5c549e5de05248925d9e046888f7d3884deccbdfcecae995b9e976af5b2255dbd39870
7
+ data.tar.gz: 0d0c070d32a953dd436ffc50e60f96a159415e961cd68ff4650c528265416df84d9c0c1d6052ab2f14a23f5c9937c7b1afde4621084b2bd4727068306512c6f4
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # AGCOD
2
2
 
3
3
  [![Build Status](https://travis-ci.org/compwron/aws_agcod.svg?branch=master)](https://travis-ci.org/compwron/aws_agcod)
4
- [![Gem Version](https://badge.fury.io/rb/aws_agcod.svg)](http://badge.fury.io/rb/aws_agcod)
4
+ [![Gem Version](https://badge.fury.io/rb/aws_agcod_2.svg)](http://badge.fury.io/rb/aws_agcod_2)
5
5
 
6
6
  Amazon Gift Code On Demand (AGCOD) API v2 implementation for distributing Amazon gift cards (gift codes) instantly in any denomination.
7
7
 
@@ -10,7 +10,7 @@ Amazon Gift Code On Demand (AGCOD) API v2 implementation for distributing Amazon
10
10
  Add this line to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'aws_agcod'
13
+ gem 'aws_agcod_2' # https://rubygems.org/gems/aws_agcod_2
14
14
  ```
15
15
 
16
16
  And then execute:
@@ -1,8 +1,8 @@
1
- require "aws_agcod/version"
2
- require "aws_agcod/config"
3
- require "aws_agcod/create_gift_card"
4
- require "aws_agcod/cancel_gift_card"
5
- require "aws_agcod/gift_card_activity_list"
1
+ require 'aws_agcod/version'
2
+ require 'aws_agcod/config'
3
+ require 'aws_agcod/create_gift_card'
4
+ require 'aws_agcod/cancel_gift_card'
5
+ require 'aws_agcod/gift_card_activity_list'
6
6
 
7
7
  module AGCOD
8
8
  def self.configure(&block)
@@ -1,4 +1,4 @@
1
- require "aws_agcod/request"
1
+ require 'aws_agcod/request'
2
2
 
3
3
  module AGCOD
4
4
  class CancelGiftCard
@@ -7,9 +7,9 @@ module AGCOD
7
7
  def_delegators :@response, :status, :success?, :error_message
8
8
 
9
9
  def initialize(httpable, request_id, gc_id)
10
- @response = Request.new(httpable,"CancelGiftCard",
11
- "creationRequestId" => request_id,
12
- "gcId" => gc_id
10
+ @response = Request.new(httpable,'CancelGiftCard',
11
+ 'creationRequestId' => request_id,
12
+ 'gcId' => gc_id
13
13
  ).response
14
14
  end
15
15
  end
@@ -8,14 +8,14 @@ module AGCOD
8
8
  :production
9
9
 
10
10
  URI = {
11
- sandbox: "https://agcod-v2-gamma.amazon.com",
12
- production: "https://agcod-v2.amazon.com"
11
+ sandbox: 'https://agcod-v2-gamma.amazon.com',
12
+ production: 'https://agcod-v2.amazon.com'
13
13
  }
14
14
 
15
15
  def initialize
16
16
  # API defaults
17
17
  @production = false
18
- @region = "us-east-1"
18
+ @region = 'us-east-1'
19
19
  end
20
20
 
21
21
  def uri
@@ -1,4 +1,4 @@
1
- require "aws_agcod/request"
1
+ require 'aws_agcod/request'
2
2
 
3
3
  module AGCOD
4
4
  class CreateGiftCardError < StandardError; end
@@ -10,34 +10,34 @@ module AGCOD
10
10
 
11
11
  def_delegators :@response, :status, :success?, :error_message
12
12
 
13
- def initialize(httpable, request_id, amount, currency = "USD")
13
+ def initialize(httpable, request_id, amount, currency = 'USD')
14
14
  unless CURRENCIES.include?(currency.to_s)
15
15
  raise CreateGiftCardError, "Currency #{currency} not supported, available types are #{CURRENCIES.join(", ")}"
16
16
  end
17
17
 
18
- @response = Request.new(httpable, "CreateGiftCard",
19
- "creationRequestId" => request_id,
20
- "value" => {
21
- "currencyCode" => currency,
22
- "amount" => amount
18
+ @response = Request.new(httpable, 'CreateGiftCard',
19
+ 'creationRequestId' => request_id,
20
+ 'value' => {
21
+ 'currencyCode' => currency,
22
+ 'amount' => amount
23
23
  }
24
24
  ).response
25
25
  end
26
26
 
27
27
  def claim_code
28
- @response.payload["gcClaimCode"]
28
+ @response.payload['gcClaimCode']
29
29
  end
30
30
 
31
31
  def expiration_date
32
- @expiration_date ||= Time.parse @response.payload["gcExpirationDate"]
32
+ @expiration_date ||= Time.parse @response.payload['gcExpirationDate']
33
33
  end
34
34
 
35
35
  def gc_id
36
- @response.payload["gcId"]
36
+ @response.payload['gcId']
37
37
  end
38
38
 
39
39
  def request_id
40
- @response.payload["creationRequestId"]
40
+ @response.payload['creationRequestId']
41
41
  end
42
42
  end
43
43
  end
@@ -1,4 +1,4 @@
1
- require "aws_agcod/request"
1
+ require 'aws_agcod/request'
2
2
 
3
3
  module AGCOD
4
4
  class GiftCardActivityListError < StandardError; end
@@ -9,19 +9,19 @@ module AGCOD
9
9
 
10
10
  def initialize(payload)
11
11
  @payload = payload
12
- @status = payload["activityStatus"]
13
- @created_at = payload["activityTime"]
14
- @type = payload["activityType"]
15
- @card_number = payload["cardNumber"]
16
- @amount = payload["cardValue"]["amount"] if payload["cardValue"]
17
- @error_code = payload["failureCode"]
18
- @gc_id = payload["gcId"]
19
- @partner_id = payload["partnerId"]
20
- @request_id = payload["requestId"]
12
+ @status = payload['activityStatus']
13
+ @created_at = payload['activityTime']
14
+ @type = payload['activityType']
15
+ @card_number = payload['cardNumber']
16
+ @amount = payload['cardValue']['amount'] if payload['cardValue']
17
+ @error_code = payload['failureCode']
18
+ @gc_id = payload['gcId']
19
+ @partner_id = payload['partnerId']
20
+ @request_id = payload['requestId']
21
21
  end
22
22
 
23
23
  def is_real?
24
- @payload["isRealOp"] == "true"
24
+ @payload['isRealOp'] == 'true'
25
25
  end
26
26
  end
27
27
 
@@ -29,25 +29,25 @@ module AGCOD
29
29
  extend Forwardable
30
30
 
31
31
  LIMIT = 1000 # limit per request
32
- TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
32
+ TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
33
33
 
34
34
  def_delegators :@response, :success?, :error_message
35
35
 
36
36
  def initialize(httpable, request_id, start_time, end_time, page = 1, per_page = 100, show_no_ops = false)
37
37
  raise GiftCardActivityListError, "Only #{LIMIT} records allowed per request." if per_page > LIMIT
38
38
 
39
- @response = Request.new(httpable,"GetGiftCardActivityPage",
40
- "requestId" => request_id,
41
- "utcStartDate" => start_time.strftime(TIME_FORMAT),
42
- "utcEndDate" => end_time.strftime(TIME_FORMAT),
43
- "pageIndex" => (page - 1) * per_page,
44
- "pageSize" => per_page,
45
- "showNoOps" => show_no_ops
39
+ @response = Request.new(httpable,'GetGiftCardActivityPage',
40
+ 'requestId' => request_id,
41
+ 'utcStartDate' => start_time.strftime(TIME_FORMAT),
42
+ 'utcEndDate' => end_time.strftime(TIME_FORMAT),
43
+ 'pageIndex' => (page - 1) * per_page,
44
+ 'pageSize' => per_page,
45
+ 'showNoOps' => show_no_ops
46
46
  ).response
47
47
  end
48
48
 
49
49
  def results
50
- @response.payload["cardActivityList"].map { |payload| GiftCardActivity.new(payload) }
50
+ @response.payload['cardActivityList'].map { |payload| GiftCardActivity.new(payload) }
51
51
  end
52
52
  end
53
53
  end
@@ -1,11 +1,11 @@
1
- require "aws_agcod/signature"
2
- require "aws_agcod/response"
3
- require "http"
4
- require "yaml"
1
+ require 'aws_agcod/signature'
2
+ require 'aws_agcod/response'
3
+ require 'http'
4
+ require 'yaml'
5
5
 
6
6
  module AGCOD
7
7
  class Request
8
- TIME_FORMAT = "%Y%m%dT%H%M%SZ"
8
+ TIME_FORMAT = '%Y%m%dT%H%M%SZ'
9
9
  MOCK_REQUEST_IDS = %w(F0000 F2005)
10
10
 
11
11
  attr_reader :response
@@ -23,12 +23,12 @@ module AGCOD
23
23
  time = Time.now.utc
24
24
 
25
25
  headers = {
26
- "content-type" => "application/json",
27
- "x-amz-date" => time.strftime(TIME_FORMAT),
28
- "accept" => "application/json",
29
- "host" => uri.host,
26
+ 'content-type' => 'application/json',
27
+ 'x-amz-date' => time.strftime(TIME_FORMAT),
28
+ 'accept' => 'application/json',
29
+ 'host' => uri.host,
30
30
  "x-amz-target" => "com.amazonaws.agcod.AGCODService.#{@action}",
31
- "date" => time.to_s
31
+ 'date' => time.to_s
32
32
  }
33
33
 
34
34
  Signature.new(AGCOD.config).sign(uri, headers, body)
@@ -40,19 +40,19 @@ module AGCOD
40
40
 
41
41
  def body
42
42
  @body ||= @params.merge(
43
- "partnerId" => AGCOD.config.partner_id
43
+ 'partnerId' => AGCOD.config.partner_id
44
44
  ).to_json
45
45
  end
46
46
 
47
47
  def sanitized_params(params)
48
48
  # Prefix partner_id when it's not given as part of request_id for creationRequestId and it's not a mock request_id
49
- if params["creationRequestId"] && !(params["creationRequestId"] =~ /#{AGCOD.config.partner_id}/) && !(MOCK_REQUEST_IDS.member?(params["creationRequestId"]))
50
- params["creationRequestId"] = "#{AGCOD.config.partner_id}#{params["creationRequestId"]}"
49
+ if params['creationRequestId'] && !(params['creationRequestId'] =~ /#{AGCOD.config.partner_id}/) && !(MOCK_REQUEST_IDS.member?(params["creationRequestId"]))
50
+ params['creationRequestId'] = "#{AGCOD.config.partner_id}#{params['creationRequestId']}"
51
51
  end
52
52
 
53
53
  # Remove partner_id when it's prefixed in requestId
54
- if params["requestId"] && !!(params["requestId"] =~ /^#{AGCOD.config.partner_id}/)
55
- params["requestId"].sub!(/^#{AGCOD.config.partner_id}/, "")
54
+ if params['requestId'] && !!(params['requestId'] =~ /^#{AGCOD.config.partner_id}/)
55
+ params['requestId'].sub!(/^#{AGCOD.config.partner_id}/, '')
56
56
  end
57
57
 
58
58
  params
@@ -11,21 +11,21 @@ module AGCOD
11
11
  # SUCCESS -- Operation succeeded
12
12
  # FAILURE -- Operation failed
13
13
  # RESEND -- A temporary/recoverable system failure that can be resolved by the partner retrying the request
14
- @status = if payload["status"]
15
- payload["status"]
16
- elsif payload["agcodResponse"]
17
- payload["agcodResponse"]["status"]
14
+ @status = if payload['status']
15
+ payload['status']
16
+ elsif payload['agcodResponse']
17
+ payload['agcodResponse']['status']
18
18
  else
19
- "FAILURE"
19
+ 'FAILURE'
20
20
  end
21
21
  end
22
22
 
23
23
  def success?
24
- status == "SUCCESS"
24
+ status == 'SUCCESS'
25
25
  end
26
26
 
27
27
  def error_message
28
- "#{payload["errorCode"]} #{payload["errorType"]} - #{payload["message"]}"
28
+ "#{payload['errorCode']} #{payload['errorType']} - #{payload['message']}"
29
29
  end
30
30
  end
31
31
  end
@@ -2,13 +2,13 @@
2
2
  # this class generates signed headers for making proper request to AGCOD service.
3
3
  #
4
4
  # Based on https://github.com/ifeelgoods/aws4/blob/master/lib/aws4/signer.rb
5
- require "openssl"
6
- require "uri"
7
- require "pathname"
5
+ require 'openssl'
6
+ require 'uri'
7
+ require 'pathname'
8
8
 
9
9
  module AGCOD
10
10
  class Signature
11
- SERVICE = "AGCODService"
11
+ SERVICE = 'AGCODService'
12
12
 
13
13
  def initialize(credentials)
14
14
  @access_key = credentials.access_key
@@ -16,14 +16,14 @@ module AGCOD
16
16
  @region = credentials.region || DEFAULT_REGION
17
17
  end
18
18
 
19
- def sign(uri, headers, body = "")
19
+ def sign(uri, headers, body = '')
20
20
  @uri = uri
21
21
  @headers = headers
22
22
  @body = body
23
- @date = headers["x-amz-date"]
23
+ @date = headers['x-amz-date']
24
24
 
25
25
  signed_headers = headers.dup
26
- signed_headers["Authorization"] = authorization
26
+ signed_headers['Authorization'] = authorization
27
27
 
28
28
  signed_headers
29
29
  end
@@ -35,22 +35,22 @@ module AGCOD
35
35
  "AWS4-HMAC-SHA256 Credential=#{@access_key}/#{credential_string}",
36
36
  "SignedHeaders=#{@headers.keys.map(&:downcase).sort.join(";")}",
37
37
  "Signature=#{signature}"
38
- ].join(", ")
38
+ ].join(', ')
39
39
  end
40
40
 
41
41
  # Reference http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
42
42
  def signature
43
- k_date = hmac("AWS4" + @secret_key, @date[0, 8])
43
+ k_date = hmac('AWS4' + @secret_key, @date[0, 8])
44
44
  k_region = hmac(k_date, @region)
45
45
  k_service = hmac(k_region, SERVICE)
46
- k_credentials = hmac(k_service, "aws4_request")
46
+ k_credentials = hmac(k_service, 'aws4_request')
47
47
  hexhmac(k_credentials, string_to_sign)
48
48
  end
49
49
 
50
50
  # Reference http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html
51
51
  def string_to_sign
52
52
  @string_to_sign ||= [
53
- "AWS4-HMAC-SHA256", # Algorithm
53
+ 'AWS4-HMAC-SHA256', # Algorithm
54
54
  @date, # RequestDate
55
55
  credential_string, # CredentialScope
56
56
  hexdigest(canonical_request) # HashedCanonicalRequest
@@ -58,17 +58,17 @@ module AGCOD
58
58
  end
59
59
 
60
60
  def credential_string
61
- @credential_string ||= [@date[0, 8], @region, SERVICE, "aws4_request"].join("/")
61
+ @credential_string ||= [@date[0, 8], @region, SERVICE, 'aws4_request'].join('/')
62
62
  end
63
63
 
64
64
  # Reference http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
65
65
  def canonical_request
66
66
  @canonical_request ||= [
67
- "POST", # HTTPRequestMethod
67
+ 'POST', # HTTPRequestMethod
68
68
  Pathname.new(@uri.path).cleanpath.to_s, # CanonicalURI
69
69
  @uri.query, # CanonicalQueryString
70
70
  @headers.sort.map { |k, v| [k.downcase, v.strip].join(":") }.join("\n") + "\n", # CanonicalHeaders
71
- @headers.sort.map { |k, v| k.downcase }.join(";"), # SignedHeaders
71
+ @headers.sort.map { |k, v| k.downcase }.join(';'), # SignedHeaders
72
72
  hexdigest(@body) # HexEncode(Hash(RequestPayload))
73
73
  ].join("\n")
74
74
  end
@@ -85,11 +85,11 @@ module AGCOD
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.new("sha256"), key, value)
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.new("sha256"), key, value)
92
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
93
93
  end
94
94
  end
95
95
  end
@@ -1,3 +1,3 @@
1
1
  module AGCOD
2
- VERSION = "1.1.0"
2
+ VERSION = '1.1.1'
3
3
  end
@@ -1,8 +1,8 @@
1
- require "spec_helper"
2
- require "aws_agcod/cancel_gift_card"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/cancel_gift_card'
3
3
 
4
4
  describe AGCOD::CancelGiftCard do
5
- let(:partner_id) { "Testa" }
5
+ let(:partner_id) { 'Testa' }
6
6
  let(:response) { spy }
7
7
  let(:httpable) { HTTP }
8
8
 
@@ -12,25 +12,25 @@ describe AGCOD::CancelGiftCard do
12
12
  end
13
13
  end
14
14
 
15
- context ".new" do
16
- let(:request_id) { "test1" }
17
- let(:gc_id) { "FOO" }
15
+ context '.new' do
16
+ let(:request_id) { 'test1' }
17
+ let(:gc_id) { 'FOO' }
18
18
 
19
- it "makes cancel request" do
19
+ it 'makes cancel request' do
20
20
  expect(AGCOD::Request).to receive(:new) do |_, action, params|
21
- expect(action).to eq("CancelGiftCard")
22
- expect(params["creationRequestId"]).to eq(request_id)
23
- expect(params["gcId"]).to eq(gc_id)
21
+ expect(action).to eq('CancelGiftCard')
22
+ expect(params['creationRequestId']).to eq(request_id)
23
+ expect(params['gcId']).to eq(gc_id)
24
24
  end.and_return(response)
25
25
 
26
26
  AGCOD::CancelGiftCard.new(httpable, request_id, gc_id)
27
27
  end
28
28
  end
29
29
 
30
- shared_context "request with response" do
31
- let(:gc_id) { "BAR" }
32
- let(:creation_request_id) { "BAZ" }
33
- let(:status) { "SUCCESS" }
30
+ shared_context 'request with response' do
31
+ let(:gc_id) { 'BAR' }
32
+ let(:creation_request_id) { 'BAZ' }
33
+ let(:status) { 'SUCCESS' }
34
34
  let(:request) { AGCOD::CancelGiftCard.new(httpable, creation_request_id, gc_id) }
35
35
 
36
36
  before do
@@ -39,10 +39,10 @@ describe AGCOD::CancelGiftCard do
39
39
  end
40
40
  end
41
41
 
42
- context "#status" do
43
- include_context "request with response"
42
+ context '#status' do
43
+ include_context 'request with response'
44
44
 
45
- it "returns the response status" do
45
+ it 'returns the response status' do
46
46
  expect(request.status).to eq(status)
47
47
  end
48
48
  end
@@ -1,41 +1,41 @@
1
- require "spec_helper"
2
- require "aws_agcod/config"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/config'
3
3
 
4
4
  describe AGCOD::Config do
5
5
  let(:config) { AGCOD::Config.new }
6
6
 
7
- context ".new" do
8
- it "sets default uri and region" do
7
+ context '.new' do
8
+ it 'sets default uri and region' do
9
9
  expect(config.uri).not_to be_nil
10
10
  expect(config.region).not_to be_nil
11
11
  expect(config.production).to eq(false)
12
12
  end
13
13
  end
14
14
 
15
- context "#uri" do
16
- context "when uri is set" do
15
+ context '#uri' do
16
+ context 'when uri is set' do
17
17
  before do
18
- config.uri = "https://custom-uri.example.com"
18
+ config.uri = 'https://custom-uri.example.com'
19
19
  end
20
20
 
21
- it "returns the custom uri" do
22
- expect(config.uri).to eq("https://custom-uri.example.com")
21
+ it 'returns the custom uri' do
22
+ expect(config.uri).to eq('https://custom-uri.example.com')
23
23
  end
24
24
  end
25
25
 
26
- context "when uri is not set" do
27
- context "when production is enabled" do
26
+ context 'when uri is not set' do
27
+ context 'when production is enabled' do
28
28
  before do
29
29
  config.production = true
30
30
  end
31
31
 
32
- it "returns the production uri" do
32
+ it 'returns the production uri' do
33
33
  expect(config.uri).to eq(AGCOD::Config::URI[:production])
34
34
  end
35
35
  end
36
36
 
37
- context "when production is disabled" do
38
- it "returns the sandbox uri" do
37
+ context 'when production is disabled' do
38
+ it 'returns the sandbox uri' do
39
39
  expect(config.uri).to eq(AGCOD::Config::URI[:sandbox])
40
40
  end
41
41
  end
@@ -1,9 +1,9 @@
1
- require "spec_helper"
2
- require "aws_agcod/create_gift_card"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/create_gift_card'
3
3
 
4
4
  describe AGCOD::CreateGiftCard do
5
- let(:partner_id) { "Testa" }
6
- let(:request_id) { "test1" }
5
+ let(:partner_id) { 'Testa' }
6
+ let(:request_id) { 'test1' }
7
7
  let(:amount) { 10 }
8
8
  let(:currency) { AGCOD::CreateGiftCard::CURRENCIES.first }
9
9
  let(:response) { spy }
@@ -15,16 +15,16 @@ describe AGCOD::CreateGiftCard do
15
15
  end
16
16
  end
17
17
 
18
- context ".new" do
19
- context "when currency available" do
20
- it "makes create request" do
18
+ context '.new' do
19
+ context 'when currency available' do
20
+ it 'makes create request' do
21
21
  expect(AGCOD::Request).to receive(:new) do |httpable, action, params|
22
22
  expect(httpable).to eq(HTTP)
23
- expect(action).to eq("CreateGiftCard")
24
- expect(params["creationRequestId"]).to eq(request_id)
25
- expect(params["value"]).to eq(
26
- "currencyCode" => currency,
27
- "amount" => amount
23
+ expect(action).to eq('CreateGiftCard')
24
+ expect(params['creationRequestId']).to eq(request_id)
25
+ expect(params['value']).to eq(
26
+ 'currencyCode' => currency,
27
+ 'amount' => amount
28
28
  )
29
29
  end.and_return(response)
30
30
 
@@ -32,10 +32,10 @@ describe AGCOD::CreateGiftCard do
32
32
  end
33
33
  end
34
34
 
35
- context "when currency not available" do
36
- let(:currency) { "NOTEXIST" }
35
+ context 'when currency not available' do
36
+ let(:currency) { 'NOTEXIST' }
37
37
 
38
- it "raises error" do
38
+ it 'raises error' do
39
39
  expect {
40
40
  AGCOD::CreateGiftCard.new(httpable, request_id, amount, currency)
41
41
  }.to raise_error(
@@ -46,13 +46,13 @@ describe AGCOD::CreateGiftCard do
46
46
  end
47
47
  end
48
48
 
49
- shared_context "request with response" do
50
- let(:claim_code) { "FOO" }
51
- let(:expiration_date) { "Wed Mar 12 22:59:59 UTC 2025" }
52
- let(:gc_id) { "BAR" }
53
- let(:creation_request_id) { "BAZ" }
54
- let(:status) { "SUCCESS" }
55
- let(:payload) { {"gcClaimCode" => claim_code, "gcId" => gc_id, "creationRequestId" => creation_request_id, "gcExpirationDate" => expiration_date} }
49
+ shared_context 'request with response' do
50
+ let(:claim_code) { 'FOO' }
51
+ let(:expiration_date) { 'Wed Mar 12 22:59:59 UTC 2025' }
52
+ let(:gc_id) { 'BAR' }
53
+ let(:creation_request_id) { 'BAZ' }
54
+ let(:status) { 'SUCCESS' }
55
+ let(:payload) { {'gcClaimCode' => claim_code, 'gcId' => gc_id, 'creationRequestId' => creation_request_id, 'gcExpirationDate' => expiration_date} }
56
56
  let(:request) { AGCOD::CreateGiftCard.new(httpable, request_id, amount, currency) }
57
57
 
58
58
  before do
@@ -62,42 +62,42 @@ describe AGCOD::CreateGiftCard do
62
62
  end
63
63
  end
64
64
 
65
- context "#claim_code" do
66
- include_context "request with response"
65
+ context '#claim_code' do
66
+ include_context 'request with response'
67
67
 
68
- it "returns claim_code" do
68
+ it 'returns claim_code' do
69
69
  expect(request.claim_code).to eq(claim_code)
70
70
  end
71
71
  end
72
72
 
73
- context "#expiration_date" do
74
- include_context "request with response"
73
+ context '#expiration_date' do
74
+ include_context 'request with response'
75
75
 
76
- it "returns expiration_date" do
76
+ it 'returns expiration_date' do
77
77
  expect(request.expiration_date).to eq(Time.parse expiration_date)
78
78
  end
79
79
  end
80
80
 
81
- context "#gc_id" do
82
- include_context "request with response"
81
+ context '#gc_id' do
82
+ include_context 'request with response'
83
83
 
84
- it "returns gc_id" do
84
+ it 'returns gc_id' do
85
85
  expect(request.gc_id).to eq(gc_id)
86
86
  end
87
87
  end
88
88
 
89
- context "#request_id" do
90
- include_context "request with response"
89
+ context '#request_id' do
90
+ include_context 'request with response'
91
91
 
92
- it "returns creation request_id" do
92
+ it 'returns creation request_id' do
93
93
  expect(request.request_id).to eq(creation_request_id)
94
94
  end
95
95
  end
96
96
 
97
- context "#status" do
98
- include_context "request with response"
97
+ context '#status' do
98
+ include_context 'request with response'
99
99
 
100
- it "returns the response status" do
100
+ it 'returns the response status' do
101
101
  expect(request.status).to eq(status)
102
102
  end
103
103
  end
@@ -17,20 +17,20 @@ describe AGCOD::GetAvailableFunds do
17
17
  }),
18
18
  }),
19
19
  )
20
- let(:payload) { { "availableFunds" => { "amount" => amount, "currencyCode" => currency_code }, "status" => status, "timestamp" => timestamp } }
20
+ let(:payload) { { 'availableFunds' => { 'amount' => amount, 'currencyCode' => currency_code }, 'status' => status, 'timestamp' => timestamp } }
21
21
 
22
22
  let(:request_response) {
23
23
  OpenStruct.new(response:
24
24
  OpenStruct.new(payload:
25
25
  {
26
- "availableFunds" => [
26
+ 'availableFunds' => [
27
27
  {
28
- "amount" => amount,
29
- "currencyCode" => currency_code
28
+ 'amount' => amount,
29
+ 'currencyCode' => currency_code
30
30
  }
31
31
  ],
32
- "status" => status,
33
- "timestamp" => timestamp
32
+ 'status' => status,
33
+ 'timestamp' => timestamp
34
34
  }
35
35
  )
36
36
  )
@@ -1,11 +1,11 @@
1
- require "spec_helper"
2
- require "aws_agcod/gift_card_activity_list"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/gift_card_activity_list'
3
3
 
4
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") }
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
9
  let(:page) { 1 }
10
10
  let(:per_page) { AGCOD::GiftCardActivityList::LIMIT }
11
11
  let(:show_no_ops) { true }
@@ -18,8 +18,8 @@ describe AGCOD::GiftCardActivityList do
18
18
  end
19
19
  end
20
20
 
21
- context ".new" do
22
- it "makes request" do
21
+ context '.new' do
22
+ it 'makes request' do
23
23
  expect(start_time).to receive(:strftime).with(
24
24
  AGCOD::GiftCardActivityList::TIME_FORMAT
25
25
  ).and_return(start_time)
@@ -29,22 +29,22 @@ describe AGCOD::GiftCardActivityList do
29
29
  ).and_return(end_time)
30
30
 
31
31
  expect(AGCOD::Request).to receive(:new) do |_, action, params|
32
- expect(action).to eq("GetGiftCardActivityPage")
33
- expect(params["requestId"]).to eq(request_id)
34
- expect(params["utcStartDate"]).to eq(start_time)
35
- expect(params["utcEndDate"]).to eq(end_time)
36
- expect(params["pageIndex"]).to eq((page - 1) * per_page)
37
- expect(params["pageSize"]).to eq(per_page)
38
- expect(params["showNoOps"]).to eq(show_no_ops)
32
+ expect(action).to eq('GetGiftCardActivityPage')
33
+ expect(params['requestId']).to eq(request_id)
34
+ expect(params['utcStartDate']).to eq(start_time)
35
+ expect(params['utcEndDate']).to eq(end_time)
36
+ expect(params['pageIndex']).to eq((page - 1) * per_page)
37
+ expect(params['pageSize']).to eq(per_page)
38
+ expect(params['showNoOps']).to eq(show_no_ops)
39
39
  end.and_return(response)
40
40
 
41
41
  AGCOD::GiftCardActivityList.new(httpable, request_id, start_time, end_time, page, per_page, show_no_ops)
42
42
  end
43
43
 
44
- context "when request per_page reaches limit" do
44
+ context 'when request per_page reaches limit' do
45
45
  let(:per_page) { AGCOD::GiftCardActivityList::LIMIT + 1 }
46
46
 
47
- it "raises error" do
47
+ it 'raises error' do
48
48
  expect {
49
49
  AGCOD::GiftCardActivityList.new(httpable, request_id, start_time, end_time, page, per_page, show_no_ops)
50
50
  }.to raise_error(
@@ -55,8 +55,8 @@ describe AGCOD::GiftCardActivityList do
55
55
  end
56
56
  end
57
57
 
58
- context "#results" do
59
- let(:payload) { { "cardActivityList" => [spy] } }
58
+ context '#results' do
59
+ let(:payload) { { 'cardActivityList' => [spy] } }
60
60
  let(:request) { AGCOD::GiftCardActivityList.new(httpable, request_id, start_time, end_time, page, per_page, show_no_ops) }
61
61
 
62
62
  before do
@@ -66,7 +66,7 @@ describe AGCOD::GiftCardActivityList do
66
66
  allow(response).to receive(:payload) { payload }
67
67
  end
68
68
 
69
- it "returns GiftCardActivity instances" do
69
+ it 'returns GiftCardActivity instances' do
70
70
  request.results.each do |item|
71
71
  expect(item).to be_a(AGCOD::GiftCardActivity)
72
72
  end
@@ -1,23 +1,23 @@
1
- require "spec_helper"
2
- require "aws_agcod/request"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/request'
3
3
 
4
4
  describe AGCOD::Request do
5
- let(:action) { "Foo" }
5
+ let(:action) { 'Foo' }
6
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" }
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
11
  let(:config) { double(uri: base_uri, partner_id: partner_id) }
12
12
  let(:httpable) { HTTP }
13
13
 
14
- context "#new" do
14
+ context '#new' do
15
15
  before do
16
16
  allow(AGCOD).to receive(:config) { config }
17
17
  allow(AGCOD::Signature).to receive(:new).with(config) { signature }
18
18
  end
19
19
 
20
- context "with creationRequestId as special testing value" do
20
+ context 'with creationRequestId as special testing value' do
21
21
  let(:params) { { creationRequestId: creationRequestId } }
22
22
 
23
23
  subject { AGCOD::Request.new(httpable, action, params) }
@@ -26,48 +26,48 @@ describe AGCOD::Request do
26
26
  allow(signature).to receive(:sign).and_return(signed_headers)
27
27
  end
28
28
 
29
- context "with special creationRequestId F0000" do
30
- let(:creationRequestId) { "F0000" }
29
+ context 'with special creationRequestId F0000' do
30
+ let(:creationRequestId) { 'F0000' }
31
31
 
32
- it "does not add partnerId to creationRequestId" do
32
+ it 'does not add partnerId to creationRequestId' do
33
33
  expect(HTTP).to receive(:post) do |_, options|
34
- expect(JSON.parse(options[:body])["creationRequestId"]).to eq("F0000")
34
+ expect(JSON.parse(options[:body])['creationRequestId']).to eq('F0000')
35
35
  end.and_return(double(body: params.to_json))
36
36
  subject
37
37
  end
38
38
  end
39
39
 
40
- context "with special creationRequestId F2005" do
41
- let(:creationRequestId) { "F2005" }
40
+ context 'with special creationRequestId F2005' do
41
+ let(:creationRequestId) { 'F2005' }
42
42
 
43
- it "does not add partnerId to creationRequestId" do
43
+ it 'does not add partnerId to creationRequestId' do
44
44
  expect(HTTP).to receive(:post) do |_, options|
45
- expect(JSON.parse(options[:body])["creationRequestId"]).to eq("F2005")
45
+ expect(JSON.parse(options[:body])['creationRequestId']).to eq('F2005')
46
46
  end.and_return(double(body: params.to_json))
47
47
  subject
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
- it "sends post request to endpoint uri" do
52
+ it 'sends post request to endpoint uri' do
53
53
  expect(signature).to receive(:sign) do |uri, headers, body|
54
54
  expect(uri).to eq(URI("#{base_uri}/#{action}"))
55
55
  expect(headers.keys).to match_array(%w(content-type x-amz-date accept host x-amz-target date))
56
- expect(headers["content-type"]).to eq("application/json")
57
- expect(headers["x-amz-target"]).to eq("com.amazonaws.agcod.AGCODService.#{action}")
58
- expect(JSON.parse(body)["partnerId"]).to eq(partner_id)
56
+ expect(headers['content-type']).to eq('application/json')
57
+ expect(headers['x-amz-target']).to eq("com.amazonaws.agcod.AGCODService.#{action}")
58
+ expect(JSON.parse(body)['partnerId']).to eq(partner_id)
59
59
  end.and_return(signed_headers)
60
60
 
61
61
  expect(HTTP).to receive(:post) do |uri, options|
62
62
  expect(uri).to eq(URI("#{base_uri}/#{action}"))
63
- expect(JSON.parse(options[:body])["partnerId"]).to eq(partner_id)
63
+ expect(JSON.parse(options[:body])['partnerId']).to eq(partner_id)
64
64
  expect(options[:headers]).to eq(signed_headers)
65
65
  end.and_return(double(body: params.to_json))
66
66
 
67
67
  AGCOD::Request.new(httpable, action, params)
68
68
  end
69
69
 
70
- it "sets response" do
70
+ it 'sets response' do
71
71
  expect(signature).to receive(:sign) { signed_headers }
72
72
  expect(HTTP).to receive(:post) { (double(body: params.to_json)) }
73
73
 
@@ -1,65 +1,65 @@
1
- require "spec_helper"
2
- require "aws_agcod/response"
1
+ require 'spec_helper'
2
+ require 'aws_agcod/response'
3
3
 
4
4
  describe AGCOD::Response do
5
- let(:payload) { { foo: "bar" }.to_json }
5
+ let(:payload) { { foo: 'bar' }.to_json }
6
6
 
7
- context "#new" do
8
- it "sets payload and status" do
7
+ context '#new' do
8
+ it 'sets payload and status' do
9
9
  response = AGCOD::Response.new(payload)
10
10
 
11
11
  expect(response.payload).not_to be_nil
12
12
  expect(response.status).not_to be_nil
13
13
  end
14
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")
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
18
  end
19
19
  end
20
20
 
21
- context "when has status in payload" do
22
- let(:status) { "foo" }
21
+ context 'when has status in payload' do
22
+ let(:status) { 'foo' }
23
23
  let(:payload) { { status: status }.to_json }
24
24
 
25
- it "sets status as payload's status" do
25
+ it 'sets status as payload\'s status' do
26
26
  expect(AGCOD::Response.new(payload).status).to eq(status)
27
27
  end
28
28
  end
29
29
 
30
- context "when has agcodResponse in payload" do
31
- let(:status) { "foo" }
30
+ context 'when has agcodResponse in payload' do
31
+ let(:status) { 'foo' }
32
32
  let(:payload) { { agcodResponse: { status: status } }.to_json }
33
33
 
34
- it "sets status as agcodResponse's status" do
34
+ it 'sets status as agcodResponse\'s status' do
35
35
  expect(AGCOD::Response.new(payload).status).to eq(status)
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
- context "success?" do
41
- context "when status is SUCCESS" do
42
- let(:payload) { { status: "SUCCESS" }.to_json }
40
+ context 'success?' do
41
+ context 'when status is SUCCESS' do
42
+ let(:payload) { { status: 'SUCCESS' }.to_json }
43
43
 
44
- it "returns true" do
44
+ it 'returns true' do
45
45
  expect(AGCOD::Response.new(payload).success?).to be_truthy
46
46
  end
47
47
  end
48
48
 
49
- context "when status is not SUCCESS" do
50
- it "returns false" do
49
+ context 'when status is not SUCCESS' do
50
+ it 'returns false' do
51
51
  expect(AGCOD::Response.new(payload).success?).to be_falsey
52
52
  end
53
53
  end
54
54
  end
55
55
 
56
- context "error_message" do
57
- let(:error_code) { "foo" }
58
- let(:error_type) { "bar" }
59
- let(:error_message) { "baz" }
56
+ context 'error_message' do
57
+ let(:error_code) { 'foo' }
58
+ let(:error_type) { 'bar' }
59
+ let(:error_message) { 'baz' }
60
60
  let(:payload) { { errorCode: error_code, errorType: error_type, message: error_message }.to_json }
61
61
 
62
- it "composes error message by error code, type, and message from payload" do
62
+ it 'composes error message by error code, type, and message from payload' do
63
63
  expect(AGCOD::Response.new(payload).error_message).to eq("#{error_code} #{error_type} - #{error_message}")
64
64
  end
65
65
  end
@@ -1,9 +1,9 @@
1
- require "spec_helper"
2
- require "aws_agcod"
1
+ require 'spec_helper'
2
+ require 'aws_agcod'
3
3
 
4
4
  describe AGCOD do
5
- context ".configure" do
6
- it "yields config" do
5
+ context '.configure' do
6
+ it 'yields config' do
7
7
  AGCOD.configure do |config|
8
8
  expect(config).to be_an_instance_of(AGCOD::Config)
9
9
  end
@@ -1,15 +1,15 @@
1
- require "pathname"
2
- require "http"
1
+ require 'pathname'
2
+ require 'http'
3
3
 
4
- ROOT_PATH = Pathname.new(__FILE__).join("../..").expand_path
5
- $LOAD_PATH.unshift(ROOT_PATH.join("lib"))
4
+ ROOT_PATH = Pathname.new(__FILE__).join('../..').expand_path
5
+ $LOAD_PATH.unshift(ROOT_PATH.join('lib'))
6
6
 
7
7
  RSpec.configure do |config|
8
8
  # Run specs in random order to surface order dependencies. If you find an
9
9
  # order dependency and want to debug it, you can fix the order by providing
10
10
  # the seed, which is printed after each run.
11
11
  # --seed 1234
12
- config.order = "random"
12
+ config.order = 'random'
13
13
 
14
14
  # Disable the should syntax compeletely; we use the expect syntax only.
15
15
  config.expect_with :rspec do |c|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_agcod_2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenor Chang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-24 00:00:00.000000000 Z
12
+ date: 2018-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -67,11 +67,11 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3'
70
- description: |-
71
- Amazon Gift Code On Demand (AGCOD) API v2 implementation for
72
- distribute Amazon gift cards (gift codes) instantly in any denomination
70
+ description: Amazon Gift Code On Demand (AGCOD) API v2 implementation for distributing
71
+ Amazon gift cards (gift codes) instantly in any denomination
73
72
  email:
74
73
  - xenor@listia.com
74
+ - compiledwrong+aws_agcod_2@gmail.com
75
75
  executables: []
76
76
  extensions: []
77
77
  extra_rdoc_files: []