helu 0.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.
- data/README.md +34 -0
- data/lib/helu.rb +8 -0
- data/lib/project/helu.rb +70 -0
- metadata +65 -0
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# helu
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'helu'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install helu
|
16
|
+
|
17
|
+
## USAGE
|
18
|
+
|
19
|
+
Start a helu with the In App Purchase ID:
|
20
|
+
|
21
|
+
@helu = Helu.new("loosing_weight_10")
|
22
|
+
|
23
|
+
|
24
|
+
#### create blocks for failing and buying:
|
25
|
+
|
26
|
+
fail_block = lambda { # node here for failed in app purchase }
|
27
|
+
buy_block = lambda { # code here for successful in app purchase }
|
28
|
+
|
29
|
+
@helu.fail = fail_block
|
30
|
+
@helu.winning = winning_block
|
31
|
+
|
32
|
+
#### buy the product:
|
33
|
+
|
34
|
+
@helu.buy
|
data/lib/helu.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
8
|
+
end
|
data/lib/project/helu.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
class Helu
|
2
|
+
|
3
|
+
attr_reader :product_id
|
4
|
+
|
5
|
+
def initialize(product_id)
|
6
|
+
@product_id = product_id
|
7
|
+
SKPaymentQueue.defaultQueue.addTransactionObserver(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def fail=(fail_block)
|
11
|
+
@fail = fail_block
|
12
|
+
end
|
13
|
+
|
14
|
+
def winning=(winning_block)
|
15
|
+
@winning = winning_block
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def buy
|
20
|
+
SKPaymentQueue.defaultQueue.addPayment(SKPayment.paymentWithProductIdentifier(product_id))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def finishTransaction(transaction, wasSuccessful:wasSuccessful)
|
26
|
+
SKPaymentQueue.defaultQueue.finishTransaction(transaction)
|
27
|
+
produt_id = transaction.payment.productIdentifier
|
28
|
+
if (wasSuccessful)
|
29
|
+
@winning.call ; puts "Was suscessfull"
|
30
|
+
else
|
31
|
+
@fail.call ; puts "was unsuscessfull"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def completeTransaction(transaction)
|
36
|
+
finishTransaction(transaction,wasSuccessful:true)
|
37
|
+
end
|
38
|
+
|
39
|
+
def restoreTransaction(transaction)
|
40
|
+
recordTransaction(transaction.originalTransaction)
|
41
|
+
finishTransaction(transaction,wasSuccessful:true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def failedTransaction(transaction)
|
45
|
+
produt_id = transaction.payment.productIdentifier
|
46
|
+
|
47
|
+
if (transaction.error.code != SKErrorPaymentCancelled)
|
48
|
+
finishTransaction(transaction, wasSuccessful:false)
|
49
|
+
elsif transaction.error.code == SKErrorPaymentCancelled
|
50
|
+
@fail.call
|
51
|
+
else
|
52
|
+
SKPaymentQueue.defaultQueue.finishTransaction(transaction)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def paymentQueue(queue,updatedTransactions:transactions)
|
57
|
+
transactions.each do |transaction|
|
58
|
+
case transaction.transactionState
|
59
|
+
when SKPaymentTransactionStatePurchased
|
60
|
+
completeTransaction(transaction)
|
61
|
+
when SKPaymentTransactionStateFailed
|
62
|
+
failedTransaction(transaction)
|
63
|
+
when SKPaymentTransactionStateRestored
|
64
|
+
restoreTransaction(transaction)
|
65
|
+
else
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: helu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Acosta-Rubio
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ! 'Ruby Motion :: StoreKit Wrapper :: Allows In App Purchases '
|
31
|
+
email:
|
32
|
+
- ivan@bakedweb.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- lib/helu.rb
|
39
|
+
- lib/project/helu.rb
|
40
|
+
homepage: http://www.ivanacostarubio.com
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.24
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby Motion StoreKit Wrapper
|
65
|
+
test_files: []
|