How to get the recurly subscriber uuid to local db - ruby-on-rails-4.1

I am using recurly gem. Now i am trying to do update the subscriber plan recurly. Here every subscriber have unique id. How to get that id to locally. I referred the following code.
subscription = Recurly::Subscription.find('44f83d7cba354d5b84812419f923ea96')
subscription.update_attributes(
:plan_code => 'silver',
:quantity => 2,
:timeframe => 'now'
)
How to get the subscriber uuid in xml response i.e 44f83d7cba354d5b84812419f923ea96 from recurly to local db. Help me.

The ruby gem doesn't actually provide any ActiveRecord integration so you'd need to handle any storage yourself.

Related

Ionic capacitor get list of all SQLite databases for the purpose of versioning

I have a Ionic angular application which creates an SQLite DB on first install like so
this.platform.ready().then(() => {
this.sqlite.create({
name: this.dbName,
location: 'default'
}).then((sqLite: SQLiteObject) => {
lets say this.dbName is call database-v1 and then I release a updated and a user updates the app and now I have set a new name eg database-v2
How can I check if database-v1 exists first? So that I know to run the sync scripts before switching to v2?
Is it possible to get a list of all current DB names for example?
Thanks for any help

Going offline with app and database syncing

I have a NativeScript (Angular) app that makes API-calls to a server to get data. I want to implement a bi-directional synchronization once a device gets online but using current API, no BaaS.
I could do a sort of caching. Once in a while app invalidates info in database and fetches it again. I don't like this approach because there are big lists that may change. They are fetched in batches, i.e. by page. One of them is a list of files downloaded to and stored on a device. So I have to keep those that are still in the list, and delete those that are not. It sounds like a nightmare.
How would you solve such a problem?
I use nativescript-couchebase plugin to store the data. We have following services
Connectivity
Data
API Service
Based on connectivity is Online/Offline, we either fetch data from remote API or via couchebase db. Please note that API service always returns the data from Couchebase only.
So in online mode
API Call -> Write to DB -> Return latest data from Couchebase
Offline mode
Read DB -> Return latest data from Couchebase
Also along with this, we maintain all API calls in a queue. So whenever connectivity returns, API calls are processed in sequence. Another challenge that you may face while coming in online mode from offline mode is the token expiry. This problem can be solved by showing a small popup to user after you come online.
I do this by saving my data as a json string and saving it to the devices file system.
When the app loads/reloads I read it from the file.
ie.
const fileSystemModule = require("tns-core-modules/file-system");
var siteid = appSettings.getNumber("siteid");
var fileName = viewName + ".json";
const documents = fileSystemModule.knownFolders.documents();
const site_folder = documents.getFolder("site");
const siteid_folder = site_folder.getFolder(siteid.toString());
const directoryPath = fileSystemModule.path.join(siteid_folder.path, fileName);
const directoryFile = fileSystemModule.File.fromPath(directoryPath);
directoryFile.writeText(json_string)
.then((result) => {
directoryFile.readText().then((res) => {
retFun(res);
});
}).catch((err) => {
console.log(err.stack);
});

Creating database triggers via Fluent API

I am using ef-core 2.2 in connection with sqlite. In order to prevent/catch concurrency exceptions, I am creating a concurrency token in the according table. The token is a timestamp which I am configuring in my DbContext class via Fluent API:
modelBuilder.Entity<User>().Property( u => u.Timestamp ).IsRowVersion();
After that I need the timestamp to be updated on every update to my table-entry, therefor I am appending a sql statement to my automatically created migration file:
In Up( MigrationBuilder migrationBuilder ):
migrationBuilder.Sql( "CREATE TRIGGER SetUserTimestamp AFTER UPDATE ON Users BEGIN UPDATE Users SET Timestamp = randomblob( 8 ) WHERE Id = NEW.Id; END" );
In Down( MigrationBuilder migrationBuilder ) I append:
migrationBuilder.Sql( "DROP TRIGGER SetUserTimestamp" );
This solution does work well. One problem for me is that I have to be extremely careful not to forget including the trigger creation after I created a new migration via command line. Is there any way to configure this trigger in the DbContext class, maybe via Fluent API? Or is there another way to automate the creation of the trigger?

Is there a way to get a webhook called on every Firebase Realtime DB transaction?

Basically, I'm using Firebase as my realtime database from my iOS application. However, I'd love to get a "Transaction log" to my server, even if it is not realtime. Is there a way to set this up? Maybe with a webhook?
You can use Cloud Functions for Firebase to write a database trigger that runs some JavaScript (running in a node.js environment) whenever data in your database changes. You can effectively use this to send changes from your Realtime Database to whatever other server you control. You would probably have to implement a webhook or some other endpoint on your server to receive the data.
In order to make outbound network requests in a function like this, you will need to upgrade your project to the Blaze plan if you haven't already.
I can't understand very well your question, what are you trying to achieve?
You can "save" an action done on your app with firebase in , at least, three ways:
1)Creating a node to log the transactions and use childupdates to save a transaction in its node and at the same time in another node like "transactionsLog" (https://firebase.google.com/docs/database/ios/read-and-write#update_specific_fields)
2)If you only need to track events done in your app by users, you can use firebase Analytics and save an event every time there is a transaction: https://firebase.google.com/docs/analytics/ios/start (get started) and https://firebase.google.com/docs/analytics/ios/start#log_events (to log events)
3)To do more complex actions when a transaction has been done you can use a Firebase Function (https://firebase.google.com/docs/functions/) where you can do, in javascript (it is a nodeJs environment ), everything you want.
Example first method (Swift):
let key = ref.child("transactions").childByAutoId().key
let post = ["uid": userID,
"author": username,
"amount": amount,
"date": date]
let childUpdates = ["/transactions/\(key)": post,
"/transactionsLog/\(userID)/\(key)/": true]
ref.updateChildValues(childUpdates)

How to upload existing mongodb users into Meteor app?

We have an existing mongodb which I imported into my Meteor app using:
mongorestore -h 127.0.0.1 --port 3001 -d meteor dump/mymongodb
Now it seems I can access any collection just find by using the collection name for example:
Meteor.publish 'works', ->
Works.find({}, {limit: 10, sort: {createdAt: -1}})
Seems to work, as we had a collection named works. I didn't even have to define it:
#Works = new Meteor.collection('works')
although it probably wouldn't hurt to define it.
But I am lost when it comes to the Meteor.users collection. We had a collection in our database called users, but I cannot access that one. How can I get our users collection from other mongodb into Meteor.users for the app?
PS. I can access the users collection directly from terminal using 'meteor mongo' and search db.users.findOne() but I cannot seem to access it from the code files.
You need collections to be defined in order to use them. Meteor.users is defined by the accounts packages (e.g. accounts-password). If you are not using any of those packages, you will need to define the collection like so:
#Users = new Mongo.Collection 'users'
or
#Meteor.users = new Mongo.Collection 'users'
I regularly do this in apps which talk to our database but which don't require any user interaction (db migrations, stats reporting, etc.).
Of course, without the accounts packages installed, you get none of the other user functionality, but that may not matter in your case.

Resources