B4A Library CloudRail - CloudStorage (Dropbox, GoogleDrive, OneDrive and Box) Payment (PayPal, Stripe), POI

This is a Wrapper for the CloudStorage API from CloudRail.

At this point of development there is no Social-module wrapped. CloudRail does support more than just the CloudStorage-Api. But it was this i was interested in so i wrote the wrap for them...

I leave it up to the community to extend the library; i´ll share the written JAVA-Code

Requirements:
- B4A 6+ as the library is using a aar
- Account at CloudRail. Note that they also provide free subscription.
https://cloudrail.com/cloudrail-pricing/
- The file cloudrail-si.aar which can be downloaded here.
- An ClientID and Secret from the content-provider you want to use.
Dropbox
GoogleDrive
OneDrive
Box

Installation: Copy all three files from the library zip to your additional libs folder.
CloudRail.xml, CloudRail.jar and cloudrail-si.aar



Example-Code (for Dropbox)

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim dropbox As Dropbox
    Dim cr As CloudRail
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    cr.Initialize("CloudRail","cloudrailid")
End Sub
Sub CloudRail_Ready(Success As Boolean)
    Log($"CloudRail_Ready(${Success})"$)
    If Success Then
        'dropbox.Initialize("Dropbox","client id","client secret")
    End If
End Sub

B4X:
Sub Dropbox_Ready(Success As Boolean)
    Log($"Dropbox_Ready(${Success})"$)
    dropbox.getChildren("/")
    dropbox.getChildren("/B4A")
    dropbox.checkAllocation
    dropbox.download("/B4A/MaterialDesign-Webfont-master.zip",rp.GetSafeDirDefaultExternal("Downloads"),"MaterialWebfont.zip")
End Sub
Sub Dropbox_DownloadFinished(success As Boolean, info As String, filePath As String, destPath As String, destFile As String)
    Log($"Dropbox_DownloadFinished(${destFile}->${success},${destFile},${filePath})"$)
End Sub
Sub Dropbox_Allocation(alloc As Object)
    Log($"Dropbox_Allocation()"$)
    If alloc <> Null Then
        Dim sa As SpaceAllocation = alloc
        Log($"${sa.Used} Used"$)
        Log($"${sa.Total} Total"$)
    End If
End Sub
Sub Dropbox_MetaData(path As String, meta As Object)
    Log($"Dropbox_MetaData(${path},${meta})"$)
End Sub
Sub Dropbox_Login(Success As Boolean)
    Log($"Dropbox_Login(${Success})"$)
End Sub
Sub Dropbox_Children(folder As List, files As List)
    Log($"Dropbox_Children()"$)
    If folder <> Null Then
        Log($"folder: ${folder.Size}"$)
    End If
    If files <> Null Then
        Log($"files: ${files.Size}"$)
    End If
    'Log($"Dropbox_Children(${folder})"$)
End Sub

CloudRail
Author:
DonManfred (wrapper)
Version: 1.5
CloudRail
Events:

  • Ready (Success As Boolean)
Methods:
  • validateKey As void
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String, AppKey As java.lang.String) As void
Permissions:
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.INTERNET
  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE
Properties:
  • AppKey As java.lang.String

Business CloudStorage:
AmazonS3
Backblaze
GoogleCloudPlatform
MicrosoftAzure
Rackspace
OneDriveBusiness


Cloud Storage:
Box
Google-Drive
Dropbox
Egnyte
OneDrive









SpaceAllocation
Methods:

  • hashCode As int
  • equals (o As java.lang.Object) As boolean
  • toString As java.lang.String
  • IsInitialized As boolean
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String, space As com.cloudrail.si.types.SpaceAllocation) As void
Properties:
  • Used As java.lang.Long
  • Total As java.lang.Long
 

Attachments

  • CloudRailV1.51.zip
    189.7 KB · Views: 415
  • CloudRailV1.52.zip
    188.7 KB · Views: 402
  • CloudRailV1.54.zip
    188.8 KB · Views: 620
  • cloudrail-si.zip
    453.7 KB · Views: 587
  • cloudrailEx.zip
    8 KB · Views: 572
Last edited:

DonManfred

Expert
Licensed User
Longtime User
CloudRail
Author: DonManfred (wrapper)
Version: 1.2
  • CloudRail
    Events:
    • Ready (Success As Boolean)
    Methods:
    • Initialize (EventName As String, AppKey As String)
    • validateKey
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.INTERNET
    • android.permission.READ_EXTERNAL_STORAGE
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • AppKey As String


  • Address
    Methods:
    • Initialize (EventName As String, cvc As String, expire_month As Long, expire_year As Long, number As String, type As String, firstName As String, lastName As String, address As Address)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • City As String
    • Country As String
    • Line1 As String
    • Line2 As String
    • PostalCode As String
    • State As String
  • Charge
    Methods:
    • Initialize (EventName As String, amount As Long, created As Long, currency As String, id As String, refunded As Number, source As CreditCard, status As String)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • isRefunded As Boolean
    • toString As String
    Properties:
    • Amount As Long [read only]
    • Created As Long [read only]
    • Currency As String [read only]
    • Id As String [read only]
    • Source As CreditCard [read only]
    • Status As String [read only]
  • Refund
    Methods:
    • Initialize (EventName As String, amount As Long, chargeID As String, created As Long, id As String, state As String, currency As String)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • Amount As Long [read only]
    • ChargeID As String [read only]
    • Created As Long [read only]
    • Currency As String [read only]
    • Id As String [read only]
    • State As String [read only]
  • CreditCard
    Methods:
    • Initialize (EventName As String, cvc As String, expire_month As Long, expire_year As Long, number As String, type As String, firstName As String, lastName As String, address As Address)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • Address As Address
    • Cvc As String
    • Expire_month As Long
    • Expire_year As Long
    • FirstName As String
    • LastName As String
    • Number As String
    • Type As String

  • Subscription
    Methods:
    • Initialize (EventName As String, created As Long, description As String, id As String, lastCharge As Long, name As String, nextCharge As Long, creditCard As CreditCard, state As String, subscriptionPlanID As String)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • Created As Long [read only]
    • CreditCard As CreditCard [read only]
    • Description As String [read only]
    • Id As String [read only]
    • LastCharge As Long [read only]
    • Name As String [read only]
    • NextCharge As Long [read only]
    • State As String [read only]
    • SubscriptionPlanID As String [read only]
  • SubscriptionPlan
    Methods:
    • Initialize (EventName As String, amount As Long, created As Long, currency As String, description As String, id As String, interval As String, interval_count As Long, name As String)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • Amount As Long [read only]
    • Created As Long [read only]
    • Currency As String [read only]
    • Description As String [read only]
    • Id As String [read only]
    • Interval As String [read only]
    • Interval_count As Long [read only]
    • Name As String [read only]

  • PayPal
    Events:
    • CancelSubscription (id As String)
    • Charge (id As String, ch As Charge)
    • CreateSubscription (sub As Subscription)
    • Createcharge (ch As Charge)
    • ListCharges (charges As List)
    • PartialRefund (id As String, refund As Refund)
    • Ready (success As Boolean)
    • Refund (is As String, refund As Refund)
    • RefundCharge (refund As Refund)
    • RefundsForCharge (id As String, refunds As List)
    • Subscription (name As String, plan As SupscriptionPlan)
    • SubscriptionList (supscriptions As List)
    Methods:
    • ChargeByID (id As String)
    • GetRefund (id As String)
    • Initialize (EventName As String, ClientID As String, ClientSecret As String, sandbox As Boolean)
    • IsInitialized As Boolean
    • cancelSubscription (id As String)
    • createCharge (amount As Long, currency As String, source As CreditCard)
    • createSubscription (planID As String, name As String, description As String, source As CreditCard)
    • createSubscriptionPlan (name As String, amount As Long, currency As String, description As String, interval As String, intervalCount As Long)
    • getRefundsForCharge (id As String)
    • listCharges (paramLong1 As Long, paramLong2 As Long, paramCreditCard As CreditCard)
    • listSubscriptionPlans
    • partiallyRefundCharge (id As String, amount As Long)
    • refundCharge (id As String)

  • Stripe
    Events:
    • CancelSubscription (id As String)
    • Charge (id As String, ch As Charge)
    • CreateSubscription (sub As Subscription)
    • Createcharge (ch As Charge)
    • ListCharges (charges As List)
    • PartialRefund (id As String, refund As Refund)
    • Ready (success As Boolean)
    • Refund (is As String, refund As Refund)
    • RefundCharge (refund As Refund)
    • RefundsForCharge (id As String, refunds As List)
    • Subscription (name As String, plan As SupscriptionPlan)
    • SubscriptionList (supscriptions As List)
    Methods:
    • ChargeByID (id As String)
    • GetRefund (id As String)
    • Initialize (EventName As String, ClientSecret As String)
    • IsInitialized As Boolean
    • cancelSubscription (id As String)
    • createCharge (amount As Long, currency As String, source As CreditCard)
    • createSubscription (planID As String, name As String, description As String, source As CreditCard)
    • createSubscriptionPlan (name As String, amount As Long, currency As String, description As String, interval As String, intervalCount As Long)
    • getRefundsForCharge (id As String)
    • listCharges (paramLong1 As Long, paramLong2 As Long, paramCreditCard As CreditCard)
    • listSubscriptionPlans
    • partiallyRefundCharge (id As String, amount As Long)
    • refundCharge (id As String)

 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
*reserved*

CloudRail POI (PointsOfInteres) - GooglePlaces, fourSquare, Yelp
Author: DonManfred (wrapper)
Version: 1.2
  • CloudRail
    Events:
    • Ready (Success As Boolean)
    Methods:
    • Initialize (EventName As String, AppKey As String)
    • validateKey
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.INTERNET
    • android.permission.READ_EXTERNAL_STORAGE
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • AppKey As String





  • GooglePlaces
    Events:
    • NearbyPOIs (listofpois As List)
    Methods:
    • Initialize (EventName As String, apiKey As String)
    • IsInitialized As Boolean
    • NearbyPOIs (latitude As Double, longitude As Double, radius As Long, searchTerm As String, categories As List)
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String

  • Yelp
    Events:
    • NearbyPOIs (listofpois As List)
    Methods:
    • Initialize (EventName As String, consumerKey As String, consumerSecret As String, token As String, tokenSecret As String)
    • IsInitialized As Boolean
    • NearbyPOIs (latitude As Double, longitude As Double, radius As Long, searchTerm As String, categories As List)
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String

  • POI
    Methods:
    • Initialize (EventName As String, categories As List, imageURL As String, location As Location, name As String, phone As String)
    • IsInitialized As Boolean
    • equals (o As Object) As Boolean
    • hashCode As Int
    • toString As String
    Properties:
    • Categories As List [read only]
    • ImageURL As String [read only]
    • Location As Location [read only]
    • Name As String [read only]
    • Phone As String [read only]
 
Last edited:

Husam

Member
Licensed User
Hi DonManfred

i got this error , did i miss something ?

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **~i:** Activity (main) Resume **
CloudRail_Ready(true)Dropbox_Ready(true)
android.content.ActivityNotFoundException: Unable to find explicit activity class {b4a.example/com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1911)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1629)
    at android.app.ContextImpl.startActivity(ContextImpl.java:685)
    at android.app.ContextImpl.startActivity(ContextImpl.java:667)
    at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
    at com.cloudrail.si.servicecode.commands.AwaitCodeRedirect$1.run(AwaitCodeRedirect.java:89)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5845)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
 

jpvniekerk

Active Member
Licensed User
Longtime User
Looks great - very versatile to have one library for all the cloud storage options!
Is there any advantages using the DropBox API V2 library over this one?
I don't see the example you refer to in the previous post - is there an example available to show the use of this library?
I specifically want to know how to get authorization for the app to use the user's cloud storage (not mine). How is this done?
 

DonManfred

Expert
Licensed User
Longtime User
Is there any advantages using the DropBox API V2 library over this one?
The Dropbox-Class is more than just a way do list/download/upload files. You can create sharelinks and so on... Much more possibilities than cloudstorage.

If you just need list/up-/download files than Cloudstorage should be good for you
 

Mahares

Expert
Licensed User
Longtime User
add the cloudrail activity in manifest editor like in example
I am getting this error, but, where is the manifest editor example that you refer to:
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
CloudRail_Ready(true)
Dropbox_Ready(true)
android.content.ActivityNotFoundException: Unable to find explicit activity class {b4a.example/com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity}; have you declared this activity in your AndroidManifest.xml?
  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
  at android.app.ContextImpl.startActivity(ContextImpl.java:1283)
  at android.app.ContextImpl.startActivity(ContextImpl.java:1265)
  at android.content.ContextWrapper.startActivity(ContextWrapper.java:291)
  at com.cloudrail.si.servicecode.commands.AwaitCodeRedirect$1.run(AwaitCodeRedirect.java:89)
  at android.os.Handler.handleCallback(Handler.java:725)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:175)
  at android.app.ActivityThread.main(ActivityThread.java:5279)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  at dalvik.system.NativeStart.main(Native Method)
Thank you
 

Husam

Member
Licensed User
I am getting this error, but, where is the manifest editor example that you refer to:
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
CloudRail_Ready(true)
Dropbox_Ready(true)
android.content.ActivityNotFoundException: Unable to find explicit activity class {b4a.example/com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity}; have you declared this activity in your AndroidManifest.xml?
  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
  at android.app.ContextImpl.startActivity(ContextImpl.java:1283)
  at android.app.ContextImpl.startActivity(ContextImpl.java:1265)
  at android.content.ContextWrapper.startActivity(ContextWrapper.java:291)
  at com.cloudrail.si.servicecode.commands.AwaitCodeRedirect$1.run(AwaitCodeRedirect.java:89)
  at android.os.Handler.handleCallback(Handler.java:725)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:175)
  at android.app.ActivityThread.main(ActivityThread.java:5279)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  at dalvik.system.NativeStart.main(Native Method)
Thank you


i just added this line in manifest editor

B4X:
AddApplicationText(<activity android:name="com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity" />)
 

Mahares

Expert
Licensed User
Longtime User
Thank you @Husam for your response. Adding your line to the manifest eliminated my above error. But, I am having the below error come up now:

B4X:
CloudRail_Ready(true)
Dropbox_Ready(true)
** Activity (main) Pause, UserClosed = false **
com.cloudrail.si.exceptions.HttpException: {"error_description": "code has already been used", "error": "invalid_grant"}
  at com.cloudrail.si.services.Dropbox.getChildren(Dropbox.java:855)
  at de.donmanfred.DropboxWrapper$5.run(DropboxWrapper.java:140)
  at java.lang.Thread.run(Thread.java:856)

EDIT: The above error disappeared for some reason, but I cannot upload a file using this code:
B4X:
dropbox.upload(File.DirRootExternal & "/HHE/DG1100116100716.txt","/Import",141,True)
B4X:
CloudRail_Ready(true)
Dropbox_Ready(true)
uploadfalse
getChildren()=[CloudMetaData{path='/Import/DG1100216100816.txt', name='DG1100216100816.txt', size=141, folder=false, modifiedAt=1475940886000}, CloudMetaData{path='/Import/Dumped', name='Dumped', size=0, folder=true, modifiedAt=null}]
Dropbox_Children()
folder: 1
files: 1
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
I am trying the below code. The createfolder works, the upload and download do not work.
B4X:
Sub Dropbox_Ready(Success As Boolean)
    Log($"Dropbox_Ready(${Success})"$)
    dropbox.getChildren("/")
    dropbox.download("/Export/Base_Comments.tab",File.DirRootExternal,"myfile.tab")  'this does not work
    dropbox.upload(File.DirRootExternal & "/HHE/DG1100216100816.txt","/Import",141,True)   'this does not work
    dropbox.createFolder("/myfolder")  'this works
End Sub
Here is the log:
B4X:
CloudRail_Ready(true)
Dropbox_Ready(true)
** Activity (main) Pause, UserClosed = false **
com.cloudrail.si.exceptions.HttpException: {"error_description": "code has already been used", "error": "invalid_grant"}
  at com.cloudrail.si.services.Dropbox.getChildren(Dropbox.java:855)
  at de.donmanfred.DropboxWrapper$5.run(DropboxWrapper.java:140)
  at java.lang.Thread.run(Thread.java:856)
com.cloudrail.si.exceptions.HttpException: {"error_description": "code has already been used", "error": "invalid_grant"}
  at com.cloudrail.si.services.Dropbox.upload(Dropbox.java:651)
  at de.donmanfred.DropboxWrapper$11.run(DropboxWrapper.java:239)
  at java.lang.Thread.run(Thread.java:856)
Thank you again
 

Mahares

Expert
Licensed User
Longtime User
Has anybody succeeded in uploading to and downloading from Dropbox using this library. I can create and copy folders in Dropbox root, but cannot upload or download.. I do not know if is correct or something is wrong. I hope one of you can steer me to the correct syntax as the below does not work:
B4X:
dropbox.download("/Export/Base_Comments.tab",File.DirRootExternal,"myfile.tab") 
dropbox.upload(File.DirRootExternal & "/HHE/DG1100216100816.txt","/Import",141,True)
The lib seems to be very promising, but it does not have enough sample code to tap into its depth.
Thank you
 

Husam

Member
Licensed User
it's work very well with me

B4X:
dropbox.upload(File.DirRootExternal & "/txt.txt","/Active/p/txt.txt",0,True)
dropbox.Download("/Active/p/txt.txt",File.DirInternalCache ,"txt.txt")
 

Mahares

Expert
Licensed User
Longtime User
it's work very well with me
Here is what I came up with:
1. The download works only if you download to File.DirDefaultExternal or File.DirInternalCache, but not to File.DirRootExternal. but the downloaded file name has extra unnecessary text. If the file to download is MyFile.tab, the downloaded file name is: filesMyFile.tab, For the file to be stored with the correct name and in the Files folder of DefaulExternal, you need to preceed the file name with a slash '/'. Here is the correct code:
B4X:
dropbox.download("/Export/Base_Comments.tab",File.DirDefaultExternal,"/Base_Comments.tab")

2. So far, I have not been able to upload from File.DirRootExternal or from any other folder. The parameters for upload require the file size. What do you put there if you do not know the size?
Thanks
 

Mahares

Expert
Licensed User
Longtime User
@DonManfred
I tried 0 and also the correct size of the file. Nothing seems to work when it comes to uploading files from RootExrternal or DefaultExternal.
B4X:
dropbox.upload(File.DirRootExternal & "/HHE/DG1100216100816.txt","/Import",0,True)  'no go

Could you also address why I can download from DefaultExternal but not from RootExternal. You might want to test it for yourself.
 
Top