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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/numbers.rb +44 -44
  3. data/lib/numbers/connect.rb +2 -3
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b8b7bed5200ac39ae4e1d5647e90a57c608d314
4
- data.tar.gz: 98fec333fcf4d9296b4a299e6fa91ef52d206857
3
+ metadata.gz: db8c1de9daaba97a10f279eaeea2222297be5f75
4
+ data.tar.gz: 20431d1f5535d63573a5e4d39de39802ba03a5e3
5
5
  SHA512:
6
- metadata.gz: a5ce0e01cbeeac63f59128f937292dda9c02d113571a975b59af74974e6162ae2f75412c6f5235bd6783e78d3e0c4f242c1e3a505f1bd1077329c780a2bb13fc
7
- data.tar.gz: abeaafa8d0b1a0461df9288b388a0ffa233387914e355dbdf7132dd73cde33fb5b7f719ac55716b04c7281cb87a933908e3991efe177b531948ea00675ead6c4
6
+ metadata.gz: 6c5cb65606de982af21f72a5f7280be043b9bcf4817044168ca088771f7d4d2fa2bd5b97aca5e4b1a6a3623fe5b17d4632cb0c38118aa4a5dddeb2c01593771f
7
+ data.tar.gz: b77715fe000778eef4c410926e9279502574b7224f8c0baae2cf30e2580a937e644790a9fd0c5daf9872cb6ca280cdfafb680f8576d76fa29bdb924183183a3e
@@ -8,80 +8,80 @@ module Numbers
8
8
 
9
9
  class << self
10
10
 
11
- attr_accessor :api_key
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 = Connection.connection.get do |req|
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 get_math_fact(int)
20
+ def math(int)
28
21
  if int.is_a?(Integer)
29
- response = Connection.connection.get do |req|
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 get_random_fact
29
+ def random
42
30
  types = %w{trivia math date year}
43
- response = Connection.connection.get do |req|
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 get_trivia_fact(int)
35
+ def trivia(int)
52
36
  if int.is_a?(Integer)
53
- response = Connection.connection.get do |req|
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 get_year_fact(int)
44
+ def year(int)
66
45
  if int.is_a?(Integer)
67
- response = Connection.connection.get do |req|
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
- #Numbers.api_key = ""
82
- #puts Numbers.get_date_fact(21,6)
83
- #puts Numbers.get_math_fact(100)
84
- #puts Numbers.get_random_fact
85
- #puts Numbers.get_trivia_fact(20)
86
- #puts Numbers.get_year_fact(-1)
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
@@ -3,9 +3,8 @@ module Numbers
3
3
  class << self
4
4
  attr_reader :connection
5
5
  end
6
- @connection = Faraday.new(:url => "https://numbersapi.p.mashape.com") do |faraday|
7
- faraday.response :logger
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: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - aaron cowan
7
+ - Aaron Cowan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
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.6
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.mashape.com/divad12/numbers-1'
72
+ summary: 'Ruby gem for the use of the numbers API found here: https://www.numbersapi.com'
73
73
  test_files: []