numbers 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/numbers.rb +44 -44
- data/lib/numbers/connect.rb +2 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8c1de9daaba97a10f279eaeea2222297be5f75
|
4
|
+
data.tar.gz: 20431d1f5535d63573a5e4d39de39802ba03a5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5cb65606de982af21f72a5f7280be043b9bcf4817044168ca088771f7d4d2fa2bd5b97aca5e4b1a6a3623fe5b17d4632cb0c38118aa4a5dddeb2c01593771f
|
7
|
+
data.tar.gz: b77715fe000778eef4c410926e9279502574b7224f8c0baae2cf30e2580a937e644790a9fd0c5daf9872cb6ca280cdfafb680f8576d76fa29bdb924183183a3e
|
data/lib/numbers.rb
CHANGED
@@ -8,80 +8,80 @@ module Numbers
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
def get_date_fact(day, month)
|
11
|
+
def date(day, month)
|
14
12
|
if day.is_a?(Integer) && month.is_a?(Integer)
|
15
|
-
response =
|
16
|
-
req.url "/#{day}/#{month}/date?json=true"
|
17
|
-
req.headers['X-Mashape-Key'] = @api_key
|
18
|
-
req.headers['Accept'] = "text/plain"
|
19
|
-
end
|
13
|
+
response = get_response(day, month)
|
20
14
|
JSON.parse(response.body)
|
21
15
|
else
|
22
16
|
puts "day and month must be integers"
|
23
|
-
JSON.parse(response.body)
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
27
|
-
def
|
20
|
+
def math(int)
|
28
21
|
if int.is_a?(Integer)
|
29
|
-
response =
|
30
|
-
req.url "/#{int}/math?json=true"
|
31
|
-
req.headers['X-Mashape-Key'] = @api_key
|
32
|
-
req.headers['Accept'] = "text/plain"
|
33
|
-
end
|
22
|
+
response = get_response(int)
|
34
23
|
JSON.parse(response.body)
|
35
24
|
else
|
36
25
|
puts "must submit an integer"
|
37
|
-
JSON.parse(response.body)
|
38
26
|
end
|
39
27
|
end
|
40
28
|
|
41
|
-
def
|
29
|
+
def random
|
42
30
|
types = %w{trivia math date year}
|
43
|
-
response =
|
44
|
-
req.url "/random/#{types.sample}?json=true"
|
45
|
-
req.headers['X-Mashape-Key'] = @api_key
|
46
|
-
req.headers['Accept'] = "text/plain"
|
47
|
-
end
|
31
|
+
response = get_response(types.sample)
|
48
32
|
JSON.parse(response.body)
|
49
33
|
end
|
50
34
|
|
51
|
-
def
|
35
|
+
def trivia(int)
|
52
36
|
if int.is_a?(Integer)
|
53
|
-
response =
|
54
|
-
req.url "/#{int}/trivia?json=true"
|
55
|
-
req.headers['X-Mashape-Key'] = @api_key
|
56
|
-
req.headers['Accept'] = "text/plain"
|
57
|
-
end
|
37
|
+
response = get_response(int)
|
58
38
|
JSON.parse(response.body)
|
59
39
|
else
|
60
40
|
puts "must submit an integer"
|
61
|
-
JSON.parse(response.body)
|
62
41
|
end
|
63
42
|
end
|
64
43
|
|
65
|
-
def
|
44
|
+
def year(int)
|
66
45
|
if int.is_a?(Integer)
|
67
|
-
response =
|
68
|
-
req.url "/#{int}/year?json=true"
|
69
|
-
req.headers['X-Mashape-Key'] = @api_key
|
70
|
-
req.headers['Accept'] = "text/plain"
|
71
|
-
end
|
46
|
+
response = get_response(int)
|
72
47
|
JSON.parse(response.body)
|
73
48
|
else
|
74
49
|
puts "must submit an integer"
|
75
|
-
JSON.parse(response.body)
|
76
50
|
end
|
77
51
|
end
|
78
|
-
end
|
79
|
-
end
|
80
52
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
53
|
+
private
|
54
|
+
def get_response(*args)
|
55
|
+
type = caller[0][/`.*'/][1..-2]
|
56
|
+
|
57
|
+
if type == "date"
|
58
|
+
Connection.connection.get do |req|
|
59
|
+
req.url "/#{args[0]}/#{args[1]}/#{type}?json=true"
|
60
|
+
end
|
61
|
+
|
62
|
+
elsif type == "math"
|
63
|
+
Connection.connection.get do |req|
|
64
|
+
req.url "/#{args[0]}/#{type}?json=true"
|
65
|
+
end
|
66
|
+
|
67
|
+
elsif type == "random"
|
68
|
+
Connection.connection.get do |req|
|
69
|
+
req.url "/#{type}/#{args[0]}/?json=true"
|
70
|
+
end
|
87
71
|
|
72
|
+
elsif type == "trivia"
|
73
|
+
Connection.connection.get do |req|
|
74
|
+
req.url "/#{args[0]}/#{type}?json=true"
|
75
|
+
end
|
76
|
+
|
77
|
+
elsif type == "year"
|
78
|
+
Connection.connection.get do |req|
|
79
|
+
req.url "/#{args[0]}/#{type}?json=true"
|
80
|
+
end
|
81
|
+
|
82
|
+
else
|
83
|
+
puts "what the hell did you do"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/numbers/connect.rb
CHANGED
@@ -3,9 +3,8 @@ module Numbers
|
|
3
3
|
class << self
|
4
4
|
attr_reader :connection
|
5
5
|
end
|
6
|
-
@connection = Faraday.new(:url => "
|
7
|
-
faraday.
|
8
|
-
faraday.adapter Faraday.default_adapter
|
6
|
+
@connection = Faraday.new(:url => "http://numbersapi.com") do |faraday|
|
7
|
+
faraday.adapter(Faraday.default_adapter)
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numbers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aaron Cowan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.4.
|
69
|
+
rubygems_version: 2.4.8
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
|
-
summary: 'Ruby gem for the use of the numbers API found here: https://www.
|
72
|
+
summary: 'Ruby gem for the use of the numbers API found here: https://www.numbersapi.com'
|
73
73
|
test_files: []
|