json_api_toolbox 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/json_api_toolbox.gemspec +11 -9
- data/lib/json_api_toolbox.rb +1 -0
- data/lib/json_api_toolbox/version.rb +1 -1
- data/lib/service.rb +53 -0
- metadata +64 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fdd03f3e9cd96343e0ce30ab65515adf6da81ce
|
4
|
+
data.tar.gz: 85900da4c2c0adf3952ccd48d7595a6858df398c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bbb11dbb5560cb3847ad7fad60a956e4941dfcfabcf8f5362126dcf8b2d1b923fdde1b735d7a56a8c96b69f0d6602cb11fe56e2aee7d53b06165006645e3a51
|
7
|
+
data.tar.gz: d66fea553b53f8cd9e5bfd08a5cf68a477949463dd57f83bdbbaeb54ac1fabb4062ea0ac1d5e57c9d90b36bd4f2089c2301208e54def30e343b33482125d7311
|
data/CHANGELOG.md
CHANGED
@@ -38,3 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
38
38
|
- Added Serializable Version
|
39
39
|
- Added jsonapi_class method at Renderizable, to render versions on controllers
|
40
40
|
|
41
|
+
## [0.11.0] - 2018-03-08
|
42
|
+
### Added
|
43
|
+
- Added default Service class to call services that responds with jsonapi
|
44
|
+
pattern
|
data/json_api_toolbox.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
5
|
require 'json_api_toolbox/version'
|
7
6
|
|
@@ -19,16 +18,19 @@ Gem::Specification.new do |spec|
|
|
19
18
|
end
|
20
19
|
spec.require_paths = ['lib']
|
21
20
|
|
22
|
-
spec.add_dependency 'actionpack',
|
23
|
-
spec.add_dependency 'activerecord',
|
24
|
-
spec.add_dependency 'activesupport',
|
21
|
+
spec.add_dependency 'actionpack', '>= 4.0.0'
|
22
|
+
spec.add_dependency 'activerecord', '>= 4.0.0'
|
23
|
+
spec.add_dependency 'activesupport', '>= 4.0.0'
|
24
|
+
spec.add_dependency 'json-api-vanilla', '~> 1.0.1'
|
25
25
|
spec.add_dependency 'jsonapi-serializable', '>= 0.3.0'
|
26
|
-
spec.add_dependency '
|
27
|
-
spec.add_dependency '
|
26
|
+
spec.add_dependency 'request_store', '~> 1.3.2'
|
27
|
+
spec.add_dependency 'rest-client', '>= 2.0.1'
|
28
|
+
spec.add_dependency 'will_paginate', '>= 3.1.0'
|
28
29
|
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'bundler'
|
30
31
|
spec.add_development_dependency 'json'
|
31
32
|
spec.add_development_dependency 'pry'
|
32
33
|
spec.add_development_dependency 'pry-byebug'
|
33
|
-
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec'
|
34
36
|
end
|
data/lib/json_api_toolbox.rb
CHANGED
data/lib/service.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'request_store'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'json-api-vanilla'
|
6
|
+
|
7
|
+
module JsonApiToolbox
|
8
|
+
class Service
|
9
|
+
class << self
|
10
|
+
def get(url: nil, includes: nil, query_string: nil)
|
11
|
+
body = build_body(includes, query_string)
|
12
|
+
response = request(url, body, :get)
|
13
|
+
return if response.code == 404
|
14
|
+
parse_response(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(url: nil, body: nil)
|
18
|
+
response = request(url, body, :post)
|
19
|
+
parse_response(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def parse_response(response)
|
25
|
+
response_parsed = JSON::Api::Vanilla.parse(response.body)
|
26
|
+
response_parsed.data || response_parsed.errors
|
27
|
+
end
|
28
|
+
|
29
|
+
def request(url, payload, method)
|
30
|
+
RestClient.proxy = nil
|
31
|
+
RestClient::Request.execute(
|
32
|
+
method: method,
|
33
|
+
url: url,
|
34
|
+
payload: payload,
|
35
|
+
headers: build_header,
|
36
|
+
verify_ssl: false
|
37
|
+
)
|
38
|
+
rescue RestClient::ExceptionWithResponse => e
|
39
|
+
e.response
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_body(includes, query_string)
|
43
|
+
params = { includes: includes }
|
44
|
+
params.merge!(query_string) if query_string
|
45
|
+
params
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_header
|
49
|
+
{ Authorization: RequestStore.store[:token] }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adriano Bacha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,42 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json-api-vanilla
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: jsonapi-serializable
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,47 +81,61 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.3.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: request_store
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 1.3.2
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 1.3.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rest-client
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.0.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.0.1
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: will_paginate
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
117
|
+
version: 3.1.0
|
90
118
|
type: :runtime
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
124
|
+
version: 3.1.0
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: bundler
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
|
-
- - "
|
129
|
+
- - ">="
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
131
|
+
version: '0'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
|
-
- - "
|
136
|
+
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: json
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +182,30 @@ dependencies:
|
|
154
182
|
name: rake
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
156
184
|
requirements:
|
157
|
-
- - "
|
185
|
+
- - ">="
|
158
186
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
187
|
+
version: '0'
|
160
188
|
type: :development
|
161
189
|
prerelease: false
|
162
190
|
version_requirements: !ruby/object:Gem::Requirement
|
163
191
|
requirements:
|
164
|
-
- - "
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rspec
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
165
207
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
208
|
+
version: '0'
|
167
209
|
description:
|
168
210
|
email:
|
169
211
|
- abacha@gmail.com
|
@@ -191,6 +233,7 @@ files:
|
|
191
233
|
- lib/json_api_toolbox/version.rb
|
192
234
|
- lib/postable.rb
|
193
235
|
- lib/renderizable.rb
|
236
|
+
- lib/service.rb
|
194
237
|
homepage: http://bitbucket.org/guideinvestimentos/json_api_toolbox
|
195
238
|
licenses: []
|
196
239
|
metadata: {}
|