Best way to read rapidshare API response?

I started working with the rapidshare.com API. I'm just wondering what is the best way to read the response and call the API.

Honestly, I believe the API is everywhere. Some answers are comma separated, which is good. I am having problems responding to account information. This is not separated by a comma, and the fields may not always be in the same order.

Here is an example response: accountid = 123456 type = prem servertime = 1260968445 addtime = 1230841165 validuntil = 1262377165 username = DOWNLOADER directstart = 1 protectfiles = 0 rsantihack = 0 plustrafficmode = 0 mirror = jsconfig = 1 email=take@hike.com lots = 0 fpoints = 12071 ppoints = 10 curfiles = 150 curspace = 800426795 bodkb = 5,000,000 premkbleft = 23394289 ppointrate = 93

I think regex is the way here. Here is my expression that seems to contain all the answers containing the values: (AccountID | type | ServerTime | AddTime | validuntil | Username | directstart | protectfiles | rsantihack | plustrafficmode | Mirrors | jsconfig | mail | earth | fpoints | ppoints | curfiles | curspace | bodkb | premkbleft | ppointrate | refstring | cookies) \ = [\ sh__]]

If the data order should be considered random, then how to determine what value is?

I'm just wondering how everyone works with this.

Thanks,

Conor

+3
source share
3 answers

I assume C #.

string[] s = @"accountid=123456 type=prem servertime=1260968445 addtime=1230841165 validuntil=1262377165 username=DOWNLOADER directstart=1 protectfiles=0 rsantihack=0 plustrafficmode=0 mirrors= jsconfig=1 email=take@hike.com lots=0 fpoints=12071 ppoints=10 curfiles=150 curspace=800426795 bodkb=5000000 premkbleft=23394289 ppointrate=93".Split(" ");
var params = new Dictionary<string, string>();
foreach(var l in s)
{
 var tmp = l.Split("=");
 params[tmp[0]] = params[tmp[1]];
}

(it may contain errors .. but the idea is obvious?)

+2
source

, , .

#, .NET 3.5:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace SO
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = @"accountid=123456 type=prem servertime=1260968445";

            string pattern = @"(?<Key>[^ =]+)(?:\=)(?<Value>[^ ]+)(?=\ ?)";

            Dictionary<string, string> fields = 
                (from Match m in Regex.Matches(input, pattern)
                   select new
                   {
                       key = m.Groups["Key"].Value,
                       value = m.Groups["Value"].Value
                   }
                ).ToDictionary(p => p.key, p => p.value);

            //iterate over all fields
            foreach (KeyValuePair<string, string> field in fields)
            {
                Console.WriteLine(
                    string.Format("{0} : {1}", field.Key, field.Value)
                );
            }

            //get value from a key
            Console.WriteLine(
                string.Format("{0} : {1}", "type", fields["type"])
            );

        }
    }
}

PHP:

API- rapidshare ? PHP

0

Here is what I did.

This is basically just a working version of the code from Yossarian.

            // Command to send to API
        String command = "sub=getaccountdetails_v1&type=prem&login="+Globals.username+"&password="+Globals.password;

        // This will return the response from rapidshare API request.
        // It just performs @ webrequest and returs the raw text/html. It only a few lines. Sorry I haven't included it here.
        String input  = executeRequest(command);

        input = input.Trim();
        string[] s = input.Split('\n');

        Dictionary<string,string> terms = new Dictionary<string, string>();
        foreach(var l in s)
        {
             String[] tmp = l.Split('=');
             terms.Add(tmp[0], tmp[1]);
        }
        foreach (KeyValuePair<String, String> term in terms)
        {
            txtOutput.Text += term.Key + " :: " + term.Value+"\n";
        }

Thanks for helping the guys.

0
source

Source: https://habr.com/ru/post/1725846/


All Articles