This repository was archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
implemented product class, updated docs, other minor changes #2
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,4 @@ gemfile: | |
| - Gemfile | ||
| script: | ||
| - bundle install | ||
| - bundle exec rake clean | ||
| - bundle exec rake spec | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| # ProMotion-iap | ||
|
|
||
| [](http://badge.fury.io/rb/ProMotion-iap) | ||
| [](https://travis-ci.org/clearsightstudio/ProMotion-iap) | ||
|
|
||
| ProMotion-iap is in-app purchase notification support for the | ||
| popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion). | ||
| popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion). | ||
|
|
||
| ## Installation | ||
|
|
||
|
|
@@ -11,7 +14,79 @@ gem 'ProMotion-iap' | |
|
|
||
| ## Usage | ||
|
|
||
| ### AppDelegate | ||
| ### PM::IAP::Product Class | ||
|
|
||
| The `Product` class is an abstraction layer that provides a simpler interface when working with a single IAP product. | ||
| If you are dealing with multiple products you will want to use the IAP Module directly (documented below). | ||
|
|
||
| ```ruby | ||
| class PurchaseScreen < PM::Screen | ||
|
|
||
| def on_load | ||
|
|
||
| product = PM::IAP::Product.new("productid") | ||
|
|
||
| product.retrieve do |product, error| | ||
| # product looks something like the following | ||
| { | ||
| product_id: "productid1", | ||
| title: "title", | ||
| description: "description", | ||
| price: <BigDecimal 0.99>, | ||
| formatted_price: "$0.99", | ||
| price_locale: <NSLocale>, | ||
| downloadable: false, | ||
| download_content_lengths: <?>, # TODO: ? | ||
| download_content_version: <?>, # TODO: ? | ||
| product: <SKProduct> | ||
| } | ||
| end | ||
|
|
||
| product.purchase do |status, transaction| | ||
| case status | ||
| when :in_progress | ||
| # Usually do nothing, maybe a spinner | ||
| when :deferred | ||
| # Waiting on a prompt to the user | ||
| when :purchased | ||
| # Notify the user, update any affected UI elements | ||
| when :canceled | ||
| # They just canceled, no big deal. | ||
| when :error | ||
| # Failed to purchase | ||
| transaction.error.localizedDescription # => error message | ||
| end | ||
| end | ||
|
|
||
| product.restore do |status, product| | ||
| if status == :restored | ||
| # Update your UI, notify the user | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
| ``` | ||
|
|
||
| #### Product.new(product_id) | ||
|
|
||
| Stores the product_id for use in the instance methods. | ||
|
|
||
| #### retrieve(&callback) | ||
|
|
||
| Retrieves the product. | ||
|
|
||
| #### purchase(&callback) | ||
|
|
||
| Begins a purchase of the product. | ||
|
|
||
| #### restore(&callback) | ||
|
|
||
| Begins a restoration of the previously purchased product. | ||
|
|
||
|
|
||
| ### IAP Module | ||
|
|
||
| Include `PM::IAP` to add some in-app purchase methods to a screen, app delegate, or other class. | ||
|
|
||
|
|
@@ -22,7 +97,7 @@ class PurchaseScreen < PM::Screen | |
|
|
||
| def on_load | ||
|
|
||
| retrieve_iaps([ "productid1", "productid2" ]) do |products, error| | ||
| retrieve_iaps [ "productid1", "productid2" ] do |products, error| | ||
| # products looks something like the following | ||
| [{ | ||
| product_id: "productid1", | ||
|
|
@@ -54,7 +129,7 @@ class PurchaseScreen < PM::Screen | |
| end | ||
| end | ||
|
|
||
| restore_iaps do |status, products| | ||
| restore_iaps "productid" do |status, products| | ||
| if status == :restored | ||
| # Update your UI, notify the user | ||
| end | ||
|
|
@@ -65,19 +140,42 @@ class PurchaseScreen < PM::Screen | |
| end | ||
| ``` | ||
|
|
||
| #### purchase_iap(*product_ids, &callback) | ||
| #### retrieve_iaps(`*`product_ids, &callback) | ||
|
|
||
| Retrieves in-app purchase products in an array of mapped hashes. The callback method should accept `products` and `error`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or at least around the * |
||
|
|
||
|
|
||
| #### purchase_iaps(`*`product_ids, &callback) | ||
|
|
||
| Prompts the user to login to their Apple ID and complete the purchase. The callback method should accept `status` and `transaction`. | ||
| The callback method will be called several times with the various statuses in the process. If more than one `product_id` is provided | ||
| the callback method will be called several times per product with the applicable transaction. | ||
|
|
||
|
|
||
| #### restore_iaps(`*`product_ids, &callback) | ||
|
|
||
| Restores a previously purchased IAP to the user (for example if they have upgraded their device). This relies on the Apple ID the user | ||
| enters at the prompt. Unfortunately, if there is no purchase to restore for the signed-in account, no error message is generated and | ||
| will fail silently. | ||
|
|
||
|
|
||
| TODO | ||
|
|
||
| ```ruby | ||
|
|
||
| ``` | ||
|
|
||
| Find the Product ID here: | ||
|
|
||
|  | ||
|
|
||
|
|
||
| ## Authors | ||
| | Contributor | Twitter | | ||
| | Jamon Holmgren | [@jamonholmgren](http://twitter.com/jamonholmgren) | | ||
| | Kevin VanGelder | [@kevinvangelder](http://twitter.com/kevin_vangelder) | | ||
|
|
||
| ## Inspired By | ||
| - [Helu](https://github.com/ivanacostarubio/helu) | ||
| - [Mark Rickert's Code Example](https://github.com/OTGApps/TheShowCloser/blob/master/app/helpers/iap_helper.rb) | ||
|
|
||
|
|
||
| ## Contributing | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module ProMotion | ||
| class IAP::Product | ||
| include PM::IAP | ||
|
|
||
| attr_reader :product_id | ||
|
|
||
| def initialize(product_id) | ||
| @product_id = product_id | ||
| end | ||
|
|
||
| def retrieve(&callback) | ||
| retrieve_iaps(product_id) do |products, error| | ||
| callback.call products.first, error | ||
| end | ||
| end | ||
|
|
||
| def purchase(&callback) | ||
| purchase_iaps(product_id, &callback) | ||
| end | ||
|
|
||
| def restore(&callback) | ||
| restore_iaps(product_id) do |status, products| | ||
| callback.call status, products.find{|p| p[:product_id] == product_id } | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| describe PM::IAP::Product do | ||
|
|
||
|
|
||
| it "#retrieve" do | ||
| subject = PM::IAP::Product.new("retrieveid") | ||
| subject.mock!(:retrieve_iaps) do |product_ids, &callback| | ||
| product_ids.should.include "retrieveid" | ||
| end | ||
| subject.retrieve do |products, error| | ||
| end | ||
|
|
||
| end | ||
|
|
||
| it "#purchase" do | ||
| subject = PM::IAP::Product.new("purchaseid") | ||
| subject.mock!(:purchase_iaps) do |product_ids, &callback| | ||
| product_ids.should.include "purchaseid" | ||
| end | ||
| subject.purchase do |status, transaction| | ||
| end | ||
| end | ||
|
|
||
| it "#restore" do | ||
| subject = PM::IAP::Product.new("restoreid") | ||
| subject.mock!(:restore_iaps) do |product_ids, &callback| | ||
| product_ids.should.include "restoreid" | ||
| callback.call(:restored, [{product_id: "restoreid2"}, {product_id: "restoreid"}, {product_id: "restoreid4"}]) | ||
| end | ||
| subject.restore do |status, product| | ||
| status.should == :restored | ||
| product.should == { product_id: "restoreid" } | ||
| end | ||
| end | ||
|
|
||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the product id required here? I don't remember. I think not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably shouldn't be. You often want to get all products.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.