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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd600ecb379a51219160d4df9c365339321ce1c2
4
- data.tar.gz: 0f1371e0aa8e7cbe8e1d20fba2ff10395ad57ae6
3
+ metadata.gz: 9fdd03f3e9cd96343e0ce30ab65515adf6da81ce
4
+ data.tar.gz: 85900da4c2c0adf3952ccd48d7595a6858df398c
5
5
  SHA512:
6
- metadata.gz: c03490dc512a639160a0e1ce82f0ab30b7a609ad423d5031edf3dfd5e8542148f7e7043fe0e3908ce1abfb9c0fa15e4d3c00982834cb218c0af87e054e29e7f9
7
- data.tar.gz: f90fa1161b5b5d8c73dc75d53b119b2ca2cb32ac4f716f3cf311f134eaa0b942ed776d8680f48d5b21aa44e294e52b110a5f12cabcb86b02792e7fe8a663efb6
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
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # coding: utf-8
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
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', '>= 4.0'
23
- spec.add_dependency 'activerecord', '>= 4.0'
24
- spec.add_dependency 'activesupport', '>= 4.0'
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 'rspec', '~> 3.0'
27
- spec.add_dependency 'will_paginate', '>= 3.1'
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', '~> 1.15'
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', '~> 10.0'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
34
36
  end
@@ -4,6 +4,7 @@ require 'active_support/inflector'
4
4
  require 'renderizable'
5
5
  require 'enums'
6
6
  require 'postable'
7
+ require 'service'
7
8
  require 'jsonapi/serializable'
8
9
  require 'json_api_toolbox/paginable'
9
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiToolbox
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
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.10.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-01-12 00:00:00.000000000 Z
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: '4.0'
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: '4.0'
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: '4.0'
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: '4.0'
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: '4.0'
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: '4.0'
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: rspec
84
+ name: request_store
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '3.0'
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: '3.0'
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: '3.1'
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: '3.1'
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: '1.15'
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: '1.15'
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: '10.0'
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: '10.0'
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: {}