Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable /catalogue/log endpoint support #73

Open
PradatiusD opened this issue Jun 2, 2015 · 5 comments
Open

Enable /catalogue/log endpoint support #73

PradatiusD opened this issue Jun 2, 2015 · 5 comments

Comments

@PradatiusD
Copy link

We need to have the ~/catalogue/log endpoint to report radio streaming activity as this is a requirement of the labels.

Right now when I look at the latest API Schema I do not see this method as part of the module.

Documentation on this particular logging method can be found here.

If this method just requires OAuth signing then can just take care of implementing it similar to the previews, streaming, and downloading tracks methods?

Here is what I mean as an example, using your README.md:

var api = require('7digital-api').configure({
    consumerkey: 'YOUR_KEY_HERE',
    consumersecret: 'YOUR_SECRET_HERE',
    defaultParams: {
        country: 'es'
    }
});

var oauth = new api.OAuth();
var previewUrl = oauth.sign('http://previews.7digital.com/clip/12345');

// For access to locker / subscription streaming without managed users you
// will need to provide the accesstoken and secret for the user
var signedUrl = oauth.sign('https://stream.svc.7digital.net/stream/locker', {
    trackId: 1234,
    formatId: 26,
    accesstoken: 'ACCESS_TOKEN',
    accesssecret: 'ACCESS_SECRET'
});
// Requesting this URL will now respond with the media data (or redirect to
// an error).

Let me know and thank you!
Daniel

@raoulmillais
Copy link
Contributor

You're right that this is n't currently supported. Your approach may work - give it a go. I'm having a look now to see if I can find a nicer solution for you.

@raoulmillais
Copy link
Contributor

I'm afraid your approrach probably won't work because Oauth.sign currently doesn't let you supply the method which is needed to generate the correct signature. I'll try to get something usable for you.

@raoulmillais
Copy link
Contributor

Ok, i've put a fix in to allow you to specify the HTTP verb when using Oauth.sign. So you can use something like the following for the time-being. Make sure you update the client to version 0.34.0 or newer.

var util= require('util');
var http = require('http');
var url = require('url');
var api = require('7digital-api');
var oauth = new api.OAuth();
var host = 'api.7digital.com';
var port = 80;
var signedUrl = oauth.sign(
        'http://api.7digital.com/1.2/catalogue/log', {},
        'POST');

console.log('URL: ', signedUrl);

var playLog = {
    playLogItem: [ { /* ... */ } } ]
};

var postData = JSON.stringify(playLog);

var options = {
        hostname: host,
        port: port,
        path: url.parse(signedUrl).path,
        method: 'POST',
        keepAlive: true,
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    };

var req = http.request(options, function (res) {
    var responseBody = '';
    // NB - We are not doing the full error handling and parsing here that
        // the client would normally do for you
    console.log('RES STATUS: ', res.statusCode);
    console.log('RES HEADERS: ', JSON.stringify(res.headers));
    res.setEncoding('utf-8');

    res.on('data', function (chunk) {
        responseBody += chunk;
    });
    res.on('end', function (chunk) {
        if (chunk) {
            responseBody += chunk;
        }

        console.log('PARSED RESPONSE');
        console.log(
            util.inspect(
                JSON.parse(responseBody), { depth: null, colors: true }));
    });
});

req.setHeader('Content-Length', postData.length);

req.on('error', function (e) {
    // NB - I am not doing any error handling here
        console.log('ERROR');
    console.log(e);
});


console.log('REQ HEADERS: ');
console.log(req.headers);
console.log('REQ POST: ', postData);
req.write(postData);
req.end();

I need to do some work to specify an endpont's content type in the schema and then use it to support this properly. I'll create a separate issue to track that and let you know so you can clean up your code.

Let me know if you have any issues.

Thanks,

@PradatiusD
Copy link
Author

No issues. Was able to refactor and integrate to what I have. Thank you so much!

Should we close the issue now (since we've solved the lack of an API endpoint) or do we keep it open until it is part of the module and the API Schema?

Have a great day!
Daniel

@raoulmillais raoulmillais changed the title Is ~/catalogue/log endpoint covered by this module? Enable /catalogue/log endpoint support Jun 11, 2015
@raoulmillais
Copy link
Contributor

Great, glad you got it working. Let's keep this one open, I'll update here when we've added support for JSON/XML content-type POSTs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants