Class: Bio::BaseSpace::BillingAPI
- Defined in:
- lib/basespace/api/billing_api.rb
Overview
The API class used for all communication with the BaseSpace Billng server.
Instance Method Summary collapse
-
#create_purchase(products, app_session_id = nil) ⇒ Object
Creates a purchase with the specified products.
-
#get_purchase_by_id(id) ⇒ Object
Request a purchase object by ID.
-
#get_user_products(id = 'current', qps = {}) ⇒ Object
Returns the Products for the current user.
-
#initialize(api_server, version, app_session_id = nil, access_token = nil) ⇒ BillingAPI
constructor
Create a new BillingAPI object.
-
#refund_purchase(purchase_id, refund_secret, comment = nil) ⇒ Object
Creates a purchase with the specified products.
Methods inherited from BaseAPI
#get_access_token, #get_server_uri, #hash2urlencode, #list_request, #make_curl_request, #set_access_token, #set_timeout, #single_request, #to_s, #to_str, #update_access_token
Constructor Details
#initialize(api_server, version, app_session_id = nil, access_token = nil) ⇒ BillingAPI
Create a new BillingAPI object.
api_server
-
URI of the BaseSpace API server.
version
-
Version of the API to use.
app_session_id
-
AppSession ID.
access_token
-
Access token that is provided by App triggering.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/basespace/api/billing_api.rb', line 29 def initialize(api_server, version, app_session_id = nil, access_token = nil) end_with_slash = %r(/$) unless api_server[end_with_slash] api_server += '/' end @app_session_id = app_session_id @api_server = api_server + version @version = version super(access_token) end |
Instance Method Details
#create_purchase(products, app_session_id = nil) ⇒ Object
Creates a purchase with the specified products.
products
-
List of dicts to purchase, each of which has a product ‘id’ and ‘quantity’ to purchase.
app_session_id
-
AppSession ID.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/basespace/api/billing_api.rb', line 46 def create_purchase(products, app_session_id = nil) my_model = 'PurchaseResponse' resource_path = '/purchases/' resource_path = resource_path.sub('{format}', 'json') method = 'POST' query_params = {} header_params = {} post_data = {} # 'Products' is list of dicts with 'id', 'quantity', and optnl 'tags[]' post_data['Products'] = products if app_session_id post_data['AppSessionId'] = app_session_id end verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#get_purchase_by_id(id) ⇒ Object
Request a purchase object by ID.
id
-
The ID of the purchase.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/basespace/api/billing_api.rb', line 66 def get_purchase_by_id(id) my_model = 'PurchaseResponse' resource_path = '/purchases/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} return single_request(my_model, resource_path, method, query_params, header_params) end |
#get_user_products(id = 'current', qps = {}) ⇒ Object
Returns the Products for the current user.
id
-
The ID of the user.
qps
-
Query parameters, a dictionary for filtering by ‘Tags’ and/or ‘ProductIds’.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/basespace/api/billing_api.rb', line 81 def get_user_products(id = 'current', qps = {}) query_pars = QueryParametersPurchasedProduct.new(qps) my_model = 'PurchasedProduct' resource_path = '/users/{Id}/products' resource_path = resource_path.sub('{Id}', id.to_s) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} return self.__listRequest__(my_model, resource_path, method, query_params, header_params) end |
#refund_purchase(purchase_id, refund_secret, comment = nil) ⇒ Object
Creates a purchase with the specified products.
purchase_id
-
The ID of the purchase.
refund_secret
-
The RefundSecret that was provided in the Response from createPurchase.
comment
-
An optional comment about the refund.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/basespace/api/billing_api.rb', line 97 def refund_purchase(purchase_id, refund_secret, comment = nil) my_model = 'RefundPurchaseResponse' resource_path = '/purchases/{id}/refund' resource_path = resource_path.sub('{id}', purchase_id) method = 'POST' query_params = {} header_params = {} post_data = {} post_data['RefundSecret'] = refund_secret if comment post_data['Comment'] = comment end verbose = 0 return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |