Skip to content

Commit 01b3595

Browse files
committed
Merge pull request #1 from eonrubia/master
Accessing via proxy
2 parents a99784e + 1cdfe30 commit 01b3595

File tree

4 files changed

+70
-45
lines changed

4 files changed

+70
-45
lines changed

README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# TrueRandom
1+
# TrueRandom
22
Get true random numbers from [RANDOM.ORG](http://random.org).
33

4-
# Description
4+
# Description
55
Use the true random number service of [RANDOM.ORG](http://random.org). The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.
66

77

8-
#Installation
8+
#Installation
99
##From the command line.
1010

1111
```shell
@@ -26,23 +26,23 @@ gem 'true-random'
2626
bundle install
2727
```
2828

29-
##Important note!
29+
##Important note!
3030
To access [RANDOM.ORG](http://random.org) via an automated client, please make sure you observe the [Guidelines for Automated Clients](http://www.random.org/clients/) or your computer may be banned.
3131

32-
#Usage
33-
##Integer Generator
32+
#Usage
33+
##Integer Generator
3434
The Integer Generator will generate truly random integers in configurable intervals.
3535

3636
```ruby
3737
rnd = TrueRandom::Random.new
3838
puts rnd.integer
3939
```
4040

41-
**Parameters**
42-
*n* The number of integers requested. 1 by default.
43-
*min* The smallest value allowed for each integer. 1 by default.
44-
*max* The largest value allowed for each integer. 100 by default.
45-
*base* The base that will be used to print the numbers, i.e., binary, octal, decimal or hexadecimal. Possible values are 2, 8, 10 or 16. 10 by default.
41+
**Parameters**
42+
*n* The number of integers requested. 1 by default.
43+
*min* The smallest value allowed for each integer. 1 by default.
44+
*max* The largest value allowed for each integer. 100 by default.
45+
*base* The base that will be used to print the numbers, i.e., binary, octal, decimal or hexadecimal. Possible values are 2, 8, 10 or 16. 10 by default.
4646

4747
The same example with full parameters
4848

@@ -59,9 +59,9 @@ The Sequence Generator will randomize a given interval of integers, i.e., arrang
5959
puts rnd.sequence
6060
```
6161

62-
**Parameters**
63-
*min* The lower bound of the interval (inclusive). 1 by default.
64-
*max* The upper bound of the interval (inclusive). 100 by default.
62+
**Parameters**
63+
*min* The lower bound of the interval (inclusive). 1 by default.
64+
*max* The upper bound of the interval (inclusive). 100 by default.
6565

6666
The sequence requested must 10,000 numbers or shorter in length, i.e., max-min+1=1e4.
6767

@@ -73,13 +73,13 @@ The String Generator will generate truly random strings of various length and ch
7373
puts rnd.string
7474
```
7575

76-
**Parameters**
77-
*n* The number of strings requested. 1 by default.
78-
*len* The length of the strings. All the strings produced will have the same length. Max length 20. 20 by default.
79-
*digits* Determines whether digits (0-9) are allowed to occur in the strings. Possible values are true or false. True by default.
80-
*upperalpha* Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings. Possible values are true or false. True by default.
81-
*loweralpha* Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings. Possible values are true or false. True by default.
82-
*unique* Determines whether the strings picked should be unique (as a series of raffle tickets drawn from a hat) or not (as a series of die rolls). If unique is set to on, then there is the additional constraint that the number of strings requested (num) must be less than or equal to the number of strings that exist with the selected length and characters. Possible values are true or false. True by default.
76+
**Parameters**
77+
*n* The number of strings requested. 1 by default.
78+
*len* The length of the strings. All the strings produced will have the same length. Max length 20. 20 by default.
79+
*digits* Determines whether digits (0-9) are allowed to occur in the strings. Possible values are true or false. True by default.
80+
*upperalpha* Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings. Possible values are true or false. True by default.
81+
*loweralpha* Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings. Possible values are true or false. True by default.
82+
*unique* Determines whether the strings picked should be unique (as a series of raffle tickets drawn from a hat) or not (as a series of die rolls). If unique is set to on, then there is the additional constraint that the number of strings requested (num) must be less than or equal to the number of strings that exist with the selected length and characters. Possible values are true or false. True by default.
8383

8484
##Quota Checker
8585
The Quota Checker allows you to examine your quota at any point in time. The quota system works on the basis of IP addresses. Each IP address has a base quota of 1,000,000 bits. When your client makes a request for random numbers (or strings, etc.), the server deducts the number of bits it took to satisfy your request from the quota associated with your client's IP address.
@@ -98,3 +98,15 @@ You can request for certain IP.
9898

9999
n.n.n.n is the IP address for which you wish to examine the quota. Each value for n should be an integer in the [0,255] interval. This parameter is optional. If you leave it out, it defaults to the IP address of the machine from which you are issuing the request.
100100

101+
##Using proxy server
102+
To enable proxy feature, set a proxy host.
103+
104+
```ruby
105+
rnd = TrueRandom::Random.new
106+
rnd.proxy host, port
107+
puts rnd.integer
108+
```
109+
110+
Set host to false to disable proxy.
111+
112+
Default port is 8080.

lib/true-random.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
module TrueRandom
44
class Random
5+
def initialize
6+
@proxy_url = false
7+
end
8+
59
def integer n=1, min=1, max=100, base = 10
610
return integers "integers/?num=#{n}&min=#{min}&max=#{max}&col=1&base=#{base}"
711
end
@@ -20,9 +24,13 @@ def quota ip = false
2024
else
2125
return integers "quota/?ip=#{ip}"
2226
end
23-
2427
end
2528

29+
def proxy url = false, port = 8080
30+
@proxy_url = url
31+
@proxy_port = port
32+
end
33+
2634
private
2735
def on_off value = false
2836
return value == true ? 'on' : 'off'
@@ -45,7 +53,12 @@ def strings uri
4553
end
4654

4755
def request uri
48-
http_response = Net::HTTP.get_response(URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new'))
56+
url = URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new')
57+
http_response = Net::HTTP::Proxy(@proxy_url, @proxy_port).get_response(url)
58+
if @proxy_url
59+
else
60+
http_response = Net::HTTP.get_response(url)
61+
end
4962
return false unless http_response.code.to_i == 200
5063
results = []
5164
http_response.body.split("\n").each do |item|

lib/true-random/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module TrueRandom
2-
VERSION = "1.1.0"
2+
VERSION = "1.1.2"
33
end

true_random.gemspec

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
$:.push File.expand_path("../lib", __FILE__)
2-
3-
# Maintain your gem's version:
4-
require "true-random/version"
5-
6-
# Describe your gem and declare its dependencies:
7-
Gem::Specification.new do |s|
8-
s.name = "true-random"
9-
s.version = TrueRandom::VERSION
10-
s.authors = ["Miguel Adolfo Barroso"]
11-
s.email = ["mabarroso@mabarroso.com"]
12-
s.homepage = "http://github.com/mabarroso/true-random"
13-
s.platform = Gem::Platform::RUBY
14-
s.summary = "Get true random numbers from RANDOM.ORG."
15-
s.description = "Use the true random number service of RANDOM.ORG. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs."
16-
17-
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
18-
s.test_files = Dir["test/**/*"]
19-
20-
s.add_development_dependency "rspec", "~> 2.7.0"
21-
end
1+
$:.push File.expand_path("../lib", __FILE__)
2+
3+
# Maintain your gem's version:
4+
require "true-random/version"
5+
6+
# Describe your gem and declare its dependencies:
7+
Gem::Specification.new do |s|
8+
s.name = "true-random"
9+
s.version = TrueRandom::VERSION
10+
s.authors = ["Miguel Adolfo Barroso", "eonrubia"]
11+
s.email = ["mabarroso@mabarroso.com"]
12+
s.homepage = "http://github.com/mabarroso/true-random"
13+
s.platform = Gem::Platform::RUBY
14+
s.summary = "Get true random numbers from RANDOM.ORG."
15+
s.description = "Use the true random number service of RANDOM.ORG. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs."
16+
17+
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
18+
s.test_files = Dir["test/**/*"]
19+
20+
s.add_development_dependency "rspec", "~> 2.7.0"
21+
end

0 commit comments

Comments
 (0)