Skip to content

Commit

Permalink
Merge a9f1596 into 4a67609
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbt committed Feb 24, 2023
2 parents 4a67609 + a9f1596 commit a3d6e62
Show file tree
Hide file tree
Showing 51 changed files with 463 additions and 479 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "jruby-9.3.10.0"
- "jruby-9.4.1.0"
steps:
Expand Down
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
TargetRubyVersion: 2.6
Exclude:
- 'spec/support/*'
- 'bin/**/*'
Expand All @@ -7,6 +8,8 @@ Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/NumericPredicate:
Enabled: false
Lint/UnifiedInteger:
Expand All @@ -19,6 +22,7 @@ Style/PercentLiteralDelimiters:
Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- '*.gemspec'
Security/MarshalLoad:
Exclude:
- 'lib/candy_check/play_store/discovery_repository.rb'
Expand All @@ -28,3 +32,9 @@ Style/Encoding:
Enabled: false
Style/ExpandPathArguments:
Enabled: false
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.3
3.2.1
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in candy_check.gemspec
gemspec
8 changes: 5 additions & 3 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
directories %w(lib spec) \
.select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
directories(
%w(lib spec) \
.select { |d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist") },
)

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
Expand All @@ -24,7 +26,7 @@ guard :minitest do
# with Minitest::Spec
watch(%r{^spec/(.*)_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
watch(%r{^spec/spec_helper\.rb$}) { "spec" }

# Rails 4
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
Expand Down
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env rake

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rake/testtask"
require "rubocop/rake_task"

Rake::TestTask.new(:spec) do |test|
test.test_files = FileList['spec/**/*_spec.rb']
test.libs << 'spec'
test.test_files = FileList["spec/**/*_spec.rb"]
test.libs << "spec"
test.verbose = true
end

Expand Down
16 changes: 8 additions & 8 deletions candy_check.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ Gem::Specification.new do |spec|
spec.add_dependency "multi_json", "~> 1.15"
spec.add_dependency "thor", "< 2.0"

spec.add_development_dependency "awesome_print"
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "guard"
spec.add_development_dependency "guard-minitest"
spec.add_development_dependency "inch", "~> 0.7"
spec.add_development_dependency "minitest", "~> 5.10"
spec.add_development_dependency "minitest-around", "~> 0.4"
spec.add_development_dependency "minitest-focus"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rubocop", "~> 0.48"
spec.add_development_dependency "timecop", "~> 0.8"
spec.add_development_dependency "webmock", "~> 3.0"
spec.add_development_dependency "vcr"
spec.add_development_dependency "pry"
spec.add_development_dependency "awesome_print"
spec.add_development_dependency "guard"
spec.add_development_dependency "guard-minitest"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rubocop", "~> 1.46"
spec.add_development_dependency "simplecov", "~> 0.18.0"
spec.add_development_dependency "simplecov-lcov", "~> 0.8.0"
spec.add_development_dependency "timecop", "~> 0.9"
spec.add_development_dependency "vcr", "~> 6.1"
spec.add_development_dependency "webmock", "~> 3.0"
end
8 changes: 4 additions & 4 deletions lib/candy_check.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'candy_check/version'
require 'candy_check/utils'
require 'candy_check/app_store'
require 'candy_check/play_store'
require "candy_check/version"
require "candy_check/utils"
require "candy_check/app_store"
require "candy_check/play_store"

# Module to check and verify in-app receipts
module CandyCheck
Expand Down
16 changes: 8 additions & 8 deletions lib/candy_check/app_store.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'candy_check/app_store/client'
require 'candy_check/app_store/config'
require 'candy_check/app_store/receipt'
require 'candy_check/app_store/receipt_collection'
require 'candy_check/app_store/verification'
require 'candy_check/app_store/subscription_verification'
require 'candy_check/app_store/verification_failure'
require 'candy_check/app_store/verifier'
require "candy_check/app_store/client"
require "candy_check/app_store/config"
require "candy_check/app_store/receipt"
require "candy_check/app_store/receipt_collection"
require "candy_check/app_store/verification"
require "candy_check/app_store/subscription_verification"
require "candy_check/app_store/verification_failure"
require "candy_check/app_store/verifier"

module CandyCheck
# Module to request and verify a AppStore receipt
Expand Down
14 changes: 7 additions & 7 deletions lib/candy_check/app_store/client.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'multi_json'
require 'net/http'
require "multi_json"
require "net/http"

module CandyCheck
module AppStore
# Simple HTTP client to load the receipt's data from Apple's verification
# servers (either sandbox or production).
class Client
# Mimetype for JSON objects
JSON_MIME_TYPE = 'application/json'.freeze
JSON_MIME_TYPE = "application/json".freeze

# Initialize a new client bound to an endpoint
# @param endpoint_url [String]
Expand Down Expand Up @@ -40,17 +40,17 @@ def build_http_connector

def build_request(parameters)
Net::HTTP::Post.new(@uri.request_uri).tap do |post|
post['Accept'] = JSON_MIME_TYPE
post['Content-Type'] = JSON_MIME_TYPE
post["Accept"] = JSON_MIME_TYPE
post["Content-Type"] = JSON_MIME_TYPE
post.body = MultiJson.dump(parameters)
end
end

def build_request_parameters(receipt_data, secret)
{
'receipt-data' => receipt_data
"receipt-data" => receipt_data,
}.tap do |h|
h['password'] = secret if secret
h["password"] = secret if secret
end
end
end
Expand Down
16 changes: 7 additions & 9 deletions lib/candy_check/app_store/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ class Config < Utils::Config
# @return [Symbol] the used environment
attr_reader :environment

# Initializes a new configuration from a hash
# @param attributes [Hash]
# @example
# Config.new(
# environment: :production # or :sandbox
# )
def initialize(attributes)
super
end
# @!method initialize(attributes)
# Initializes a new configuration from a hash
# @param attributes [Hash]
# @example
# Config.new(
# environment: :production # or :sandbox
# )

# @return [Boolean] if it is production environment
def production?
Expand Down
30 changes: 15 additions & 15 deletions lib/candy_check/app_store/receipt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,83 @@ def initialize(attributes)
# transaction was canceled.
# @return [Boolean]
def valid?
!has?('cancellation_date')
!has?("cancellation_date")
end

# The receipt's transaction id
# @return [String]
def transaction_id
read('transaction_id')
read("transaction_id")
end

# The receipt's original transaction id which might differ from
# the transaction id for restored products
# @return [String]
def original_transaction_id
read('original_transaction_id')
read("original_transaction_id")
end

# The version number for the app
# @return [String]
def app_version
read('bvrs')
read("bvrs")
end

# The app's bundle identifier
# @return [String]
def bundle_identifier
read('bid')
read("bid")
end

# The app's identifier of the product (SKU)
# @return [String]
def product_id
read('product_id')
read("product_id")
end

# The app's item id of the product
# @return [String]
def item_id
read('item_id')
read("item_id")
end

# The quantity of the product
# @return [Integer]
def quantity
read_integer('quantity')
read_integer("quantity")
end

# The purchase date
# @return [DateTime]
def purchase_date
read_datetime_from_string('purchase_date')
read_datetime_from_string("purchase_date")
end

# The original purchase date which might differ from the
# actual purchase date for restored products
# @return [DateTime]
def original_purchase_date
read_datetime_from_string('original_purchase_date')
read_datetime_from_string("original_purchase_date")
end

# The date of when Apple has canceled this transaction.
# From Apple's documentation: "Treat a canceled receipt
# the same as if no purchase had ever been made."
# @return [DateTime]
def cancellation_date
read_datetime_from_string('cancellation_date')
read_datetime_from_string("cancellation_date")
end

# The date of a subscription's expiration
# @return [DateTime]
def expires_date
read_datetime_from_string('expires_date')
read_datetime_from_string("expires_date")
end

# rubocop:disable PredicateName
# rubocop:disable Naming/PredicateName
def is_trial_period
# rubocop:enable PredicateName
read_bool('is_trial_period')
# rubocop:enable Naming/PredicateName
read_bool("is_trial_period")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/candy_check/app_store/receipt_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ReceiptCollection
# from Apple's verification server
# @param attributes [Array<Hash>] raw data from Apple's server
def initialize(attributes)
@receipts = attributes.map {|r| Receipt.new(r) }.sort{ |a, b|
@receipts = attributes.map { |r| Receipt.new(r) }.sort do |a, b|
a.purchase_date - b.purchase_date
}
end
end

# Check if the latest expiration date is passed
Expand Down
10 changes: 5 additions & 5 deletions lib/candy_check/app_store/subscription_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def initialize(
def call!
verify!
if valid?
build_collection(@response['latest_receipt_info'])
build_collection(@response["latest_receipt_info"])
else
VerificationFailure.fetch(@response['status'])
VerificationFailure.fetch(@response["status"])
end
end

Expand All @@ -35,15 +35,15 @@ def call!
def build_collection(latest_receipt_info)
unless @product_ids.nil?
latest_receipt_info = latest_receipt_info.select do |info|
@product_ids.include?(info['product_id'])
@product_ids.include?(info["product_id"])
end
end
ReceiptCollection.new(latest_receipt_info)
end

def valid?
status_is_ok = @response['status'] == STATUS_OK
@response && status_is_ok && @response['latest_receipt_info']
status_is_ok = @response["status"] == STATUS_OK
@response && status_is_ok && @response["latest_receipt_info"]
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/candy_check/app_store/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def initialize(endpoint_url, receipt_data, secret = nil)
def call!
verify!
if valid?
Receipt.new(@response['receipt'])
Receipt.new(@response["receipt"])
else
VerificationFailure.fetch(@response['status'])
VerificationFailure.fetch(@response["status"])
end
end

private

def valid?
@response && @response['status'] == STATUS_OK && @response['receipt']
@response && @response["status"] == STATUS_OK && @response["receipt"]
end

def verify!
Expand Down
Loading

0 comments on commit a3d6e62

Please sign in to comment.