Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Use environment instead of test attribute on commerce initialization. #3
Browse files Browse the repository at this point in the history
  • Loading branch information
sagmor committed Jan 25, 2013
1 parent 4cbb075 commit d531dc9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/tbk/commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ module TBK
class Commerce

# The registered commerce id
attr_accessor :id
attr_reader :id

# The commerce secret RSA key
attr_accessor :key
attr_reader :key

# The commerce environment
attr_reader :environment

# Initialyzes a new commerce
# @param [Hash] attributes The commerce attributes
# @option attributes [Integer] :id The commerce ID
# @option attributes [String|OpenSSL::PKey::RSA] :key The commerce RSA private key
# @option attributes [Boolean] :test flag to set commerce in test mode
def initialize(attributes)
@test = attributes[:test]
@environment = (attributes[:environment] || :production).to_sym
raise TBK::CommerceError, "Invalid commerce environment" unless [:production,:test].include? @environment

self.id = attributes[:id]
raise TBK::CommerceError, "Missing commerce id" if self.id.nil?
Expand All @@ -35,12 +39,12 @@ def initialize(attributes)

# @return [Boolean] wether or not the commerce is in test mode
def test?
@test || false
self.environment == :test
end

# @return [Boolean] wether or not the commerce is in production mode
def production?
!self.test?
self.environment == :production
end

# @return [Integer] RSA key bytes
Expand Down

0 comments on commit d531dc9

Please sign in to comment.