gds-api-adapters 0.0.40 → 0.0.41
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gds_api/base.rb +4 -4
- data/lib/gds_api/helpers.rb +1 -1
- data/lib/gds_api/imminence.rb +4 -0
- data/lib/gds_api/json_client.rb +32 -16
- data/lib/gds_api/response.rb +8 -8
- data/lib/gds_api/version.rb +1 -1
- metadata +43 -43
data/lib/gds_api/base.rb
CHANGED
@@ -4,11 +4,11 @@ require 'null_logger'
|
|
4
4
|
|
5
5
|
class GdsApi::Base
|
6
6
|
extend Forwardable
|
7
|
-
|
7
|
+
|
8
8
|
def client
|
9
9
|
@client ||= create_client
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def create_client
|
13
13
|
if options[:access_key]
|
14
14
|
GdsApi::OAuth2Client.new(options)
|
@@ -16,8 +16,8 @@ class GdsApi::Base
|
|
16
16
|
GdsApi::JsonClient.new(options)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
def_delegators :client, :get_json, :post_json, :put_json
|
19
|
+
|
20
|
+
def_delegators :client, :get_json, :post_json, :put_json, :get_raw
|
21
21
|
|
22
22
|
attr_reader :options
|
23
23
|
|
data/lib/gds_api/helpers.rb
CHANGED
@@ -15,7 +15,7 @@ module GdsApi
|
|
15
15
|
def panopticon_api
|
16
16
|
@panopticon_api ||= GdsApi::Panopticon.new(Plek.current.environment, panopticon_api_credentials)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def panopticon_api_credentials
|
20
20
|
Object::const_defined?(:PANOPTICON_API_CREDENTIALS) ? PANOPTICON_API_CREDENTIALS : {}
|
21
21
|
end
|
data/lib/gds_api/imminence.rb
CHANGED
data/lib/gds_api/json_client.rb
CHANGED
@@ -28,19 +28,46 @@ module GdsApi
|
|
28
28
|
}
|
29
29
|
DEFAULT_TIMEOUT_IN_SECONDS = 2
|
30
30
|
|
31
|
+
def get_raw(url)
|
32
|
+
do_raw_request(Net::HTTP::Get, url)
|
33
|
+
end
|
34
|
+
|
31
35
|
def get_json(url)
|
32
|
-
@cache[url] ||=
|
36
|
+
@cache[url] ||= do_json_request(Net::HTTP::Get, url)
|
33
37
|
end
|
34
38
|
|
35
39
|
def post_json(url, params)
|
36
|
-
|
40
|
+
do_json_request(Net::HTTP::Post, url, params)
|
37
41
|
end
|
38
42
|
|
39
43
|
def put_json(url, params)
|
40
|
-
|
44
|
+
do_json_request(Net::HTTP::Put, url, params)
|
41
45
|
end
|
42
46
|
|
43
47
|
private
|
48
|
+
def do_raw_request(method_class, url, params = nil)
|
49
|
+
response, loggable = do_request(method_class, url, params)
|
50
|
+
response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_json_request(method_class, url, params = nil)
|
54
|
+
response, loggable = do_request(method_class, url, params)
|
55
|
+
|
56
|
+
if response.is_a?(Net::HTTPSuccess)
|
57
|
+
logger.info loggable.merge(status: 'success', end_time: Time.now.to_f).to_json
|
58
|
+
Response.new(response)
|
59
|
+
else
|
60
|
+
body = begin
|
61
|
+
JSON.parse(response.body)
|
62
|
+
rescue
|
63
|
+
response.body
|
64
|
+
end
|
65
|
+
loggable.merge!(status: response.code, end_time: Time.now.to_f, body: body)
|
66
|
+
logger.warn loggable.to_json
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
44
71
|
def do_request(method_class, url, params = nil)
|
45
72
|
loggable = {request_uri: url, start_time: Time.now.to_f}
|
46
73
|
start_logging = loggable.merge(action: 'start')
|
@@ -60,19 +87,8 @@ module GdsApi
|
|
60
87
|
http.request(request)
|
61
88
|
end
|
62
89
|
|
63
|
-
|
64
|
-
|
65
|
-
Response.new(response)
|
66
|
-
else
|
67
|
-
body = begin
|
68
|
-
JSON.parse(response.body)
|
69
|
-
rescue
|
70
|
-
response.body
|
71
|
-
end
|
72
|
-
loggable.merge!(status: response.code, end_time: Time.now.to_f, body: body)
|
73
|
-
logger.warn loggable.to_json
|
74
|
-
nil
|
75
|
-
end
|
90
|
+
return response, loggable
|
91
|
+
|
76
92
|
rescue Errno::ECONNREFUSED => e
|
77
93
|
logger.error loggable.merge(status: 'refused', error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
|
78
94
|
raise GdsApi::EndpointNotFound.new("Could not connect to #{url}")
|
data/lib/gds_api/response.rb
CHANGED
@@ -6,13 +6,13 @@ module GdsApi
|
|
6
6
|
class Response
|
7
7
|
extend Forwardable
|
8
8
|
include Enumerable
|
9
|
-
|
9
|
+
|
10
10
|
def_delegators :to_hash, :[], :"<=>", :each
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(net_http_response)
|
13
13
|
@net_http_response = net_http_response
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def to_hash
|
17
17
|
@parsed ||= JSON.parse(@net_http_response.body)
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module GdsApi
|
|
20
20
|
def to_ostruct
|
21
21
|
self.class.build_ostruct_recursively(to_hash)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def method_missing(method)
|
25
25
|
if to_hash.has_key?(method.to_s)
|
26
26
|
to_ostruct.send(method)
|
@@ -28,16 +28,16 @@ module GdsApi
|
|
28
28
|
nil
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def respond_to_missing?(method, include_private)
|
33
33
|
to_hash.has_key?(method.to_s)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def present?; ! blank?; end
|
37
37
|
def blank?; false; end
|
38
|
-
|
38
|
+
|
39
39
|
private
|
40
|
-
|
40
|
+
|
41
41
|
def self.build_ostruct_recursively(value)
|
42
42
|
case value
|
43
43
|
when Hash
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.41
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
16
|
-
requirement: &
|
16
|
+
requirement: &70148847744340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70148847744340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: null_logger
|
27
|
-
requirement: &
|
27
|
+
requirement: &70148847743920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70148847743920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: lrucache
|
38
|
-
requirement: &
|
38
|
+
requirement: &70148847743420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.1.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70148847743420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70148847742920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.2.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70148847742920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: webmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &70148847742460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.7'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70148847742460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &70148847742000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.10.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70148847742000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: minitest
|
82
|
-
requirement: &
|
82
|
+
requirement: &70148847772240 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 2.10.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70148847772240
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rack
|
93
|
-
requirement: &
|
93
|
+
requirement: &70148847771860 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70148847771860
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: simplecov
|
104
|
-
requirement: &
|
104
|
+
requirement: &70148847771320 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 0.5.4
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70148847771320
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: simplecov-rcov
|
115
|
-
requirement: &
|
115
|
+
requirement: &70148847770900 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70148847770900
|
124
124
|
description: A set of adapters providing easy access to the GDS gov.uk APIs
|
125
125
|
email:
|
126
126
|
- jystewart@gmail.com
|
@@ -128,34 +128,34 @@ executables: []
|
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
|
-
- lib/gds_api/
|
132
|
-
- lib/gds_api/
|
131
|
+
- lib/gds_api/base.rb
|
132
|
+
- lib/gds_api/contactotron.rb
|
133
133
|
- lib/gds_api/core-ext/openstruct.rb
|
134
|
-
- lib/gds_api/
|
135
|
-
- lib/gds_api/
|
136
|
-
- lib/gds_api/test_helpers/imminence.rb
|
137
|
-
- lib/gds_api/test_helpers/contactotron.rb
|
138
|
-
- lib/gds_api/test_helpers/panopticon.rb
|
139
|
-
- lib/gds_api/test_helpers/json_client_helper.rb
|
140
|
-
- lib/gds_api/test_helpers/publisher.rb
|
134
|
+
- lib/gds_api/exceptions.rb
|
135
|
+
- lib/gds_api/helpers.rb
|
141
136
|
- lib/gds_api/imminence.rb
|
137
|
+
- lib/gds_api/json_client.rb
|
142
138
|
- lib/gds_api/needotron.rb
|
143
|
-
- lib/gds_api/
|
139
|
+
- lib/gds_api/oauth2_client.rb
|
140
|
+
- lib/gds_api/panopticon/registerer.rb
|
144
141
|
- lib/gds_api/panopticon.rb
|
145
|
-
- lib/gds_api/
|
146
|
-
- lib/gds_api/json_client.rb
|
142
|
+
- lib/gds_api/part_methods.rb
|
147
143
|
- lib/gds_api/publisher.rb
|
148
|
-
- lib/gds_api/
|
144
|
+
- lib/gds_api/response.rb
|
145
|
+
- lib/gds_api/test_helpers/contactotron.rb
|
146
|
+
- lib/gds_api/test_helpers/imminence.rb
|
147
|
+
- lib/gds_api/test_helpers/json_client_helper.rb
|
148
|
+
- lib/gds_api/test_helpers/panopticon.rb
|
149
|
+
- lib/gds_api/test_helpers/publisher.rb
|
149
150
|
- lib/gds_api/version.rb
|
150
|
-
- lib/gds_api/base.rb
|
151
151
|
- README.md
|
152
152
|
- Rakefile
|
153
|
+
- test/contactotron_api_test.rb
|
153
154
|
- test/gds_api_base_test.rb
|
155
|
+
- test/json_client_test.rb
|
156
|
+
- test/panopticon_api_test.rb
|
154
157
|
- test/publisher_api_test.rb
|
155
158
|
- test/test_helper.rb
|
156
|
-
- test/panopticon_api_test.rb
|
157
|
-
- test/json_client_test.rb
|
158
|
-
- test/contactotron_api_test.rb
|
159
159
|
homepage: http://github.com/alphagov/gds-api-adapters
|
160
160
|
licenses: []
|
161
161
|
post_install_message:
|
@@ -176,14 +176,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 1.8.
|
179
|
+
rubygems_version: 1.8.10
|
180
180
|
signing_key:
|
181
181
|
specification_version: 3
|
182
182
|
summary: Adapters to work with GDS APIs
|
183
183
|
test_files:
|
184
|
+
- test/contactotron_api_test.rb
|
184
185
|
- test/gds_api_base_test.rb
|
186
|
+
- test/json_client_test.rb
|
187
|
+
- test/panopticon_api_test.rb
|
185
188
|
- test/publisher_api_test.rb
|
186
189
|
- test/test_helper.rb
|
187
|
-
- test/panopticon_api_test.rb
|
188
|
-
- test/json_client_test.rb
|
189
|
-
- test/contactotron_api_test.rb
|