nobel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nobel/api.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'uri'
4
- require 'net/http'
5
4
  require 'json'
6
5
 
7
6
  module Nobel
@@ -25,7 +24,7 @@ module Nobel
25
24
  end
26
25
 
27
26
  def get_json(endpoint, params = {})
28
- load_json get("#{endpoint}.json", params)
27
+ load_json get("#{endpoint}.json", params) || "{}"
29
28
  end
30
29
 
31
30
  def get(path, params = {})
data/lib/nobel/config.rb CHANGED
@@ -9,7 +9,7 @@ module Nobel
9
9
  @api_host = 'api.nobelprize.org'
10
10
  @api_version = 'v1'
11
11
  @json_parser = ->(d) { JSON.parse(d) }
12
- @http_client = Net::HTTP
12
+ @http_client = Nobel::HTTP
13
13
  @debug = false
14
14
 
15
15
  yield self if block_given?
data/lib/nobel/http.rb ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'net/http'
4
+
5
+ module Nobel
6
+ class HTTP
7
+ class << self
8
+ def get(uri)
9
+ Net::HTTP.start(uri.host, uri.port) do |http|
10
+ request = Net::HTTP::Get.new(uri.request_uri)
11
+ response = http.request(request)
12
+ response.body if response.code == '200'
13
+ end
14
+ rescue StandardError
15
+ nil
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/nobel/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Nobel
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/nobel.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "nobel/api"
4
4
  require "nobel/config"
5
5
  require "nobel/country"
6
+ require "nobel/http"
6
7
  require "nobel/laureate"
7
8
  require "nobel/affiliation"
8
9
  require "nobel/prize"
@@ -39,7 +39,7 @@ describe "Config" do
39
39
 
40
40
  describe "http_client" do
41
41
  it "is Net::HTTP by default" do
42
- subject.http_client.must_equal Net::HTTP
42
+ subject.http_client.must_equal Nobel::HTTP
43
43
  end
44
44
 
45
45
  it "can be changed" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nobel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -28,6 +28,7 @@ files:
28
28
  - lib/nobel/api.rb
29
29
  - lib/nobel/config.rb
30
30
  - lib/nobel/country.rb
31
+ - lib/nobel/http.rb
31
32
  - lib/nobel/laureate.rb
32
33
  - lib/nobel/prize.rb
33
34
  - lib/nobel/version.rb