numbers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/numbers.rb +87 -0
  3. data/lib/numbers/connect.rb +11 -0
  4. metadata +73 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b8b7bed5200ac39ae4e1d5647e90a57c608d314
4
+ data.tar.gz: 98fec333fcf4d9296b4a299e6fa91ef52d206857
5
+ SHA512:
6
+ metadata.gz: a5ce0e01cbeeac63f59128f937292dda9c02d113571a975b59af74974e6162ae2f75412c6f5235bd6783e78d3e0c4f242c1e3a505f1bd1077329c780a2bb13fc
7
+ data.tar.gz: abeaafa8d0b1a0461df9288b388a0ffa233387914e355dbdf7132dd73cde33fb5b7f719ac55716b04c7281cb87a933908e3991efe177b531948ea00675ead6c4
@@ -0,0 +1,87 @@
1
+ require 'faraday'
2
+ require 'numbers/connect'
3
+ require 'json'
4
+
5
+ module Numbers
6
+
7
+ extend Connection
8
+
9
+ class << self
10
+
11
+ attr_accessor :api_key
12
+
13
+ def get_date_fact(day, month)
14
+ 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
20
+ JSON.parse(response.body)
21
+ else
22
+ puts "day and month must be integers"
23
+ JSON.parse(response.body)
24
+ end
25
+ end
26
+
27
+ def get_math_fact(int)
28
+ 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
34
+ JSON.parse(response.body)
35
+ else
36
+ puts "must submit an integer"
37
+ JSON.parse(response.body)
38
+ end
39
+ end
40
+
41
+ def get_random_fact
42
+ 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
48
+ JSON.parse(response.body)
49
+ end
50
+
51
+ def get_trivia_fact(int)
52
+ 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
58
+ JSON.parse(response.body)
59
+ else
60
+ puts "must submit an integer"
61
+ JSON.parse(response.body)
62
+ end
63
+ end
64
+
65
+ def get_year_fact(int)
66
+ 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
72
+ JSON.parse(response.body)
73
+ else
74
+ puts "must submit an integer"
75
+ JSON.parse(response.body)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
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)
87
+
@@ -0,0 +1,11 @@
1
+ module Numbers
2
+ module Connection
3
+ class << self
4
+ attr_reader :connection
5
+ end
6
+ @connection = Faraday.new(:url => "https://numbersapi.p.mashape.com") do |faraday|
7
+ faraday.response :logger
8
+ faraday.adapter Faraday.default_adapter
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numbers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aaron cowan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ description: API wrapper for number facts api
42
+ email: ac.aaroncowan@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/numbers.rb
48
+ - lib/numbers/connect.rb
49
+ homepage: https://github.com/AaronCowan/numbers
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.6
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: 'Ruby gem for the use of the numbers API found here: https://www.mashape.com/divad12/numbers-1'
73
+ test_files: []