Skip to content

Commit bfb6d7a

Browse files
committed
Fix json compatibility issues.
1 parent 06f2357 commit bfb6d7a

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

lib/github_api/error/service_error.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# encoding: utf-8
2-
require 'multi_json'
2+
# require 'multi_json'
3+
require 'github_api/jsonable'
34

45
module Github
56
# Raised when GitHub returns any of the HTTP status codes
67
module Error
78
class ServiceError < GithubError
9+
include ::Github::Jsonable
10+
811
attr_reader :http_headers
912

1013
def initialize(response)
@@ -20,7 +23,7 @@ def parse_response(response)
2023

2124
def decode_body(body)
2225
if body.respond_to?(:to_str) && body.length >= 2
23-
MultiJson.load(body, :symbolize_keys => true)
26+
decode body, :symbolize_keys => true
2427
else
2528
body
2629
end

lib/github_api/jsonable.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# encoding: utf-8
2+
3+
require 'multi_json'
4+
5+
module Github
6+
module Jsonable
7+
extend self
8+
9+
def decode(*args)
10+
if MultiJson.respond_to?(:load)
11+
MultiJson.load *args
12+
else
13+
MultiJson.decode *args
14+
end
15+
end
16+
end
17+
end

lib/github_api/response/jsonize.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# encoding: utf-8
22

33
require 'faraday'
4+
require 'github_api/jsonable'
45

56
module Github
67
class Response::Jsonize < Response
8+
include Github::Jsonable
9+
710
dependency 'multi_json'
811

912
define_parser do |body|
10-
if MultiJson.respond_to?(:load)
11-
MultiJson.load body
12-
else
13-
MultiJson.decode body
14-
end
13+
Github::Jsonable.decode body
1514
end
1615

1716
def parse(body)

0 commit comments

Comments
 (0)