grom_native 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +2 -2
- data/{GromNative.gemspec → gromnative.gemspec} +2 -2
- data/lib/grom_native/request.rb +144 -0
- data/lib/grom_native/version.rb +1 -1
- metadata +16 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 856f8f1624b22099e215a07e69dcd9c1ecba8c39e5641ae2e39b956eb6455e99
|
4
|
+
data.tar.gz: 2080714e05709281f6a1c90bb88d5b52cdaa2d1085de56cbb8e57fd96aa03382
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b9ee1c0bca7ed33166e1caf31b75e45a02e74881cc79149869262d95faca10c16363b81b39e6292b329e119d8f9996a2ce4052e08f6024666900c1274bd191f
|
7
|
+
data.tar.gz: b04c55804680f20ddf33a780f266d60894c574fc8055d077a8daaa2b15cd1daf42eb3f37ad4cadb62a43faba6af5bbaede1b572e84025e26d3b8d19cb6d54190
|
data/.DS_Store
ADDED
Binary file
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grom_native (0.1.
|
4
|
+
grom_native (0.1.1)
|
5
5
|
ffi (~> 1.9)
|
6
6
|
grom
|
7
|
-
parliament-grom-decorators
|
8
7
|
rdf (~> 3.0)
|
9
8
|
|
10
9
|
GEM
|
@@ -70,6 +69,7 @@ PLATFORMS
|
|
70
69
|
DEPENDENCIES
|
71
70
|
bundler (~> 1.16)
|
72
71
|
grom_native!
|
72
|
+
parliament-grom-decorators
|
73
73
|
rack (~> 2.0)
|
74
74
|
rake (~> 10.0)
|
75
75
|
rspec (~> 3.0)
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['m@rayner.io']
|
11
11
|
|
12
12
|
spec.summary = %q{A GROM implementation using a GO native extension for heavy lifting.}
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/ukparliament/gromnative'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'ffi', '~> 1.9'
|
26
26
|
spec.add_dependency 'grom'
|
27
27
|
spec.add_dependency 'rdf', '~> 3.0'
|
28
|
-
spec.add_dependency 'parliament-grom-decorators'
|
29
28
|
|
30
29
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
30
|
+
spec.add_development_dependency 'parliament-grom-decorators'
|
31
31
|
spec.add_development_dependency 'rack', '~> 2.0'
|
32
32
|
spec.add_development_dependency 'rake', '~> 10.0'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module GromNative
|
2
|
+
# URL request object, allowing the user to build a URL to make a request to an API.
|
3
|
+
#
|
4
|
+
# @since 0.7.5
|
5
|
+
#
|
6
|
+
# @attr_reader [String] base_url the endpoint for our API which we will build our requests on. (expected: http://example.com - without the trailing slash).
|
7
|
+
# @attr_reader [Hash] headers the headers being sent in the request.
|
8
|
+
class UrlRequest < Parliament::Request::BaseRequest
|
9
|
+
# Creates a new instance of Parliament::Request::UrlRequest.
|
10
|
+
#
|
11
|
+
# @see Parliament::Request::BaseRequest#initialize.
|
12
|
+
#
|
13
|
+
# @param [String] base_url the base url of our api. (expected: http://example.com - without the trailing slash).
|
14
|
+
# @param [Hash] headers the headers being sent in the request.
|
15
|
+
# @param [Parliament::Builder] builder the builder to use in order to build a response.
|
16
|
+
# @param [Module] decorators the decorator module to use in order to provide possible alias methods for any objects created by the builder.
|
17
|
+
# @example Passing headers
|
18
|
+
#
|
19
|
+
# request = Parliament::Request::UrlRequest.new(base_url: 'http://example.com', headers: { 'Access-Token' => '12345678' })
|
20
|
+
# This will create a request with the Access-Token set to 12345678.
|
21
|
+
def initialize(base_url: nil, headers: nil, builder: nil, decorators: nil)
|
22
|
+
@endpoint_parts = []
|
23
|
+
@base_url ||= ENV['PARLIAMENT_BASE_URL']
|
24
|
+
@headers = headers || self.class.headers || {}
|
25
|
+
@builder = builder || Parliament::Builder::BaseResponseBuilder
|
26
|
+
@decorators = decorators
|
27
|
+
@query_params = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Makes an HTTP GET request and process results into a response.
|
31
|
+
#
|
32
|
+
# @example HTTP GET request
|
33
|
+
# request = Parliament::Request::BaseRequest.new(base_url: 'http://example.com/people/123'
|
34
|
+
#
|
35
|
+
# # url: http://example.com/people/123
|
36
|
+
#
|
37
|
+
# response = request.get #=> #<Parliament::Response::BaseResponse ...>
|
38
|
+
#
|
39
|
+
# @example HTTP GET request with URI encoded form values
|
40
|
+
# request = Parliament::Request.new(base_url: 'http://example.com/people/current')
|
41
|
+
#
|
42
|
+
# # url: http://example.com/people/current?limit=10&page=4&lang=en-gb
|
43
|
+
#
|
44
|
+
# response = request.get({ limit: 10, page: 4, lang: 'en-gb' }) #=> #<Parliament::Response::BaseResponse ...>
|
45
|
+
#
|
46
|
+
# @raise [Parliament::ServerError] when the server responds with a 5xx status code.
|
47
|
+
# @raise [Parliament::ClientError] when the server responds with a 4xx status code.
|
48
|
+
# @raise [Parliament::NoContentResponseError] when the response body is empty.
|
49
|
+
#
|
50
|
+
# @param [Hash] params (optional) additional URI encoded form values to be added to the URI.
|
51
|
+
#
|
52
|
+
# @return [Parliament::Response::BaseResponse] a Parliament::Response::BaseResponse object containing all of the data returned from the URL.
|
53
|
+
def get(params: {}, filter: [])
|
54
|
+
uri = URI.parse(query_url)
|
55
|
+
|
56
|
+
temp_params = {}
|
57
|
+
|
58
|
+
if uri.query
|
59
|
+
# Returns [ ["key", "value"], ["key", "value"] ]
|
60
|
+
key_value_array = URI.decode_www_form(endpoint.query)
|
61
|
+
key_value_array.map! { |key_value_pair| [ key_value_pair[0].to_sym, key_value_pair[1] ] }
|
62
|
+
temp_params = key_value_array.to_h
|
63
|
+
end
|
64
|
+
|
65
|
+
temp_params = temp_params.merge(params)
|
66
|
+
|
67
|
+
uri.query = temp_params
|
68
|
+
|
69
|
+
GromNative.fetch( uri: uri.to_s, headers: headers, filter: filter, decorators: @decorators )
|
70
|
+
end
|
71
|
+
|
72
|
+
# Overrides ruby's method_missing to allow creation of URLs through method calls.
|
73
|
+
#
|
74
|
+
# @example Adding a simple URL part
|
75
|
+
# request = Parliament::Request::UrlRequest.new(base_url: 'http://example.com')
|
76
|
+
#
|
77
|
+
# # url: http://example.com/people
|
78
|
+
# request.people
|
79
|
+
#
|
80
|
+
# @example Adding a simple URL part with parameters
|
81
|
+
# request = Parliament::Request::UrlRequest.new(base_url: 'http://example.com')
|
82
|
+
#
|
83
|
+
# # url: http://example.com/people/123456
|
84
|
+
# request.people('123456')
|
85
|
+
#
|
86
|
+
# @example Chaining URL parts and using hyphens
|
87
|
+
# request = Parliament::Request::UrlRequest.new(base_url: 'http://example.com')
|
88
|
+
#
|
89
|
+
# # url: http://example.com/people/123456/foo/bar/hello-world/7890
|
90
|
+
# request.people('123456').foo.bar('hello-world', '7890')
|
91
|
+
#
|
92
|
+
# @param [Symbol] method the 'method' (url part) we are processing.
|
93
|
+
# @param [Array<Object>] params parameters passed to the specified method (url part).
|
94
|
+
# @param [Block] block additional block (kept for compatibility with method_missing API).
|
95
|
+
#
|
96
|
+
# @return [Parliament::Request::UrlRequest] self (this is to allow method chaining).
|
97
|
+
def method_missing(method, *params, &block)
|
98
|
+
@endpoint_parts << method.to_s
|
99
|
+
|
100
|
+
@endpoint_parts << params
|
101
|
+
@endpoint_parts = @endpoint_parts.flatten!
|
102
|
+
|
103
|
+
block&.call
|
104
|
+
|
105
|
+
self || super
|
106
|
+
end
|
107
|
+
|
108
|
+
# This class always responds to method calls, even those missing. Therefore, respond_to_missing? always returns true.
|
109
|
+
#
|
110
|
+
# @return [Boolean] always returns true.
|
111
|
+
def respond_to_missing?(_, _ = false)
|
112
|
+
true # responds to everything, always
|
113
|
+
end
|
114
|
+
|
115
|
+
def query_url
|
116
|
+
uri_string = [@base_url, @endpoint_parts].join('/').gsub(' ', '%20')
|
117
|
+
|
118
|
+
uri = URI.parse(uri_string)
|
119
|
+
uri.query = URI.encode_www_form(@query_params) unless @query_params.empty?
|
120
|
+
|
121
|
+
uri.to_s
|
122
|
+
end
|
123
|
+
|
124
|
+
# @return [Parliament::Request::UrlRequest] self (this is to allow method chaining).
|
125
|
+
def set_url_params(params)
|
126
|
+
@query_params = @query_params.merge(params)
|
127
|
+
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
def default_headers
|
132
|
+
{ 'Accept' => ['*/*', 'application/n-triples'] }
|
133
|
+
end
|
134
|
+
|
135
|
+
def headers
|
136
|
+
default_headers.merge(@headers)
|
137
|
+
end
|
138
|
+
|
139
|
+
class << self
|
140
|
+
attr_accessor :base_url, :headers
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/lib/grom_native/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grom_native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Rayner
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.16'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: parliament-grom-decorators
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rack
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,6 +143,7 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
+
- ".DS_Store"
|
146
147
|
- ".gitignore"
|
147
148
|
- ".rspec"
|
148
149
|
- ".ruby-version"
|
@@ -152,7 +153,6 @@ files:
|
|
152
153
|
- Gemfile.lock
|
153
154
|
- Gopkg.lock
|
154
155
|
- Gopkg.toml
|
155
|
-
- GromNative.gemspec
|
156
156
|
- LICENSE.txt
|
157
157
|
- Makefile
|
158
158
|
- README.md
|
@@ -169,10 +169,12 @@ files:
|
|
169
169
|
- ext/processor/spec/processor_suite_test.go
|
170
170
|
- ext/types/net.proto
|
171
171
|
- ext/types/net/net.pb.go
|
172
|
+
- gromnative.gemspec
|
172
173
|
- lib/grom_native.rb
|
173
174
|
- lib/grom_native/node.rb
|
175
|
+
- lib/grom_native/request.rb
|
174
176
|
- lib/grom_native/version.rb
|
175
|
-
homepage: https://github.com/
|
177
|
+
homepage: https://github.com/ukparliament/gromnative
|
176
178
|
licenses:
|
177
179
|
- MIT
|
178
180
|
metadata: {}
|