paradox460 / snoo

A ruby api wrapper for reddit.com
MIT License
79 stars 21 forks source link

require unique user-agents? #6

Open yubrew opened 11 years ago

yubrew commented 11 years ago

In the Reddit API wiki, Many default User-Agents (like "Python/urllib" or "Java") are drastically limited to encourage unique and descriptive user-agent strings. - https://github.com/reddit/reddit/wiki/API

I was having some request problems with logging into my reddit account through snoo, doing something like 1 request every 3-5 minutes, and I am wondering if it's because of the generic snoo user agent.

https://github.com/paradox460/snoo/blob/development/lib/snoo.rb#L36

It might make sense to require a user defined user-agent, and update the docs; e.g. Snoo::Client.new(user-agent: 'my_cool_application')

I'll make a pull request later tonight, if this idea seems ok.

paradox460 commented 11 years ago

Custom user agents can be easily set at init. But making this required isn't that hard.

One thing I've thought of is adding some machine identifier to the default ua. Say an encoded version of the machine's Mac address. That way, the reddit administration could easily pinpoint abuse from one singular machine, while not limiting others.

(Aside: I'll change my various bots to use custom user agents to help lighten the load.)

Finally, I suspect the throttling is a symptom of people not respecting the api rate limits. A possible fix is sticking a sleep 2 in the get helper, with an option to disable globally or per request.

yubrew commented 11 years ago

No doubt there are a bunch of ways to implement this. Figured we could discuss this a bit before firing up the console.

I like your idea of taking something unique from each user (such as encoding Mac address). Setting a sleep default, which could be disabled is another great suggestion. I'll make a pull request with both suggestions probably in a couple days or so.

paradox460 commented 11 years ago

For doing mac address, feel free to use the macaddr gem and add a dependency.

I'm working on a complete recode of the gem, to support 2.0's niceties, while retaining support for 1.9