Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
1,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. // Sample code to create a listing for Rocket League.
  2. // Your Gameflip account needs to be verified and Steam connected.
  3. //
  4. // Generate the API Key and OTP secret in [Settings page](https://gameflip.com/settings)
  5. //
  6. // Type in bash shell:
  7. // ```
  8. // export GFAPI_KEY=my_api_key
  9. // export GFAPI_SECRET=my_api_secret
  10. // node src/samples/bulk_listing.js
  11. // ```
  12. //
  13. // If you are using an IDE, set the `GFAPI_KEY` and `GFAPI_SECRET` in the Run Configuration Environment.
  14. // Be careful not to commit/push anything with the API key/secret to a public repository.
  15.  
  16. 'use strict';
  17.  
  18. const GFAPI_KEY = process.env.GFAPI_KEY;
  19. const GFAPI_SECRET = process.env.GFAPI_SECRET;
  20.  
  21. // For your own code, use the 'gfapi' library (`npm install 'iJJi/gfapi').
  22. const GfApi = require('../../index'); // require('gfapi')
  23. const fs = require('fs');
  24.  
  25. // Create a Rocket League listing
  26. async function main() {
  27. // Create GF API client. Options: logLevel
  28. // * `trace` (logs HTTP requests/responses)
  29. // * `debug` (outputs HTTP requests)
  30. const gfapi = new GfApi(GFAPI_KEY, {
  31. secret: GFAPI_SECRET,
  32. algorithm: "SHA1",
  33. digits: 6,
  34. period: 90
  35. }, {
  36. logLevel: 'debug'
  37. });
  38.  
  39. // For an inventory of Rocket League items and photo URLs, view https://gameflip.com/api/gameitem/inventory/812872018935
  40. // and for Fortnite, view https://gameflip.com/api/gameitem/inventory/GFFORTNITE
  41.  
  42. //JSON ADDING
  43. let owo = "src/New folder/pokemon";
  44. fs.readdir(owo, function (err, files) {
  45. if (err) {
  46. console.error("Could not list the directory.", err);
  47. process.exit(1);
  48. }
  49.  
  50. files.forEach(async function (file, index) {
  51. let bar = fs.readFileSync(file);
  52. let uwu = JSON.parse(bar);
  53.  
  54.  
  55. // DO EDIT: Choose an image for your listing
  56. let photo_url = uwu.photo_url;
  57. // Create an initial listing
  58. let query = {
  59.  
  60. // DO EDIT: Put just 'Key' for example if you are selling one, otherwise write the quantity as so: Item Name | 10x
  61. name: uwu.name,
  62. description: uwu.description,
  63. price: uwu.price, // price in cents
  64. tags: uwu.tags,
  65. // Example with color
  66. // tags: [ "id: chakram", "type: Wheel", "color: Black" ]
  67.  
  68. // MAYBE EDIT: Platform variation, change if you want to sell for example Fortnite (upc) on the PlayStation (platform) section instead
  69. upc: GfApi.UPC.PKM_SWITCH,
  70. platform: GfApi.PLATFORM.NSWITCH,
  71. shipping_within_days: GfApi.SHIPPING_WITHIN_DAYS.ONE,
  72. expire_in_days: GfApi.EXPIRE_IN_DAYS.NINETY,
  73. //accept_currency: GfApi.ACCEPT_CURRENCY.FLP // Uncomment this if you want to accept FLP instead of USD
  74.  
  75. // DON'T EDIT: Standard settings for coordinated transfer in game item
  76. category: GfApi.CATEGORY.INGAME,
  77. kind: GfApi.KIND.ITEM,
  78. digital: true,
  79. digital_region: 'none',
  80. digital_deliverable: 'transfer',
  81. shipping_predefined_package: 'None',
  82. shipping_fee: 0,
  83. shipping_paid_by: 'seller',
  84.  
  85. };
  86. let listing = await gfapi.listing_post(query);
  87.  
  88. // Upload an image to show in the listing page
  89. gfapi.upload_photo(listing.id, photo_url, 0).then(() => {
  90. // Upload another image to show in the search results
  91. return gfapi.upload_photo(listing.id, photo_url);
  92. // If you want to add a second image in the listing page then uncomment the two lines below:
  93. }).then(() => {
  94. return gfapi.upload_photo(listing.id, 'https://production-gameflipusercontent.fingershock.com/us-east-1:d7e333bf-68b9-4057-a7ab-2a3e24eee1e9/529a0cfb-6571-4727-9e18-70a130ff9073/896c589b-39a1-4224-8e2a-fde27fb678a1', 1);
  95. }).then(() => {
  96. // List the listing for sale
  97. return gfapi.listing_status(listing.id, GfApi.LISTING_STATUS.ONSALE);
  98. }).catch(err => {
  99. console.log(err);
  100. });
  101.  
  102.  
  103. });
  104. });
  105. }
  106.  
  107. // Run main() and catch any unhandle Promise errors
  108. main().catch(err => {
  109. console.log('==== ERROR', err);
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement