parasut-v4 1.0.1 → 1.0.2
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/README.md +34 -0
- data/lib/her/middleware/o_auth_provider_header.rb +44 -34
- data/lib/parasut.rb +1 -0
- data/lib/parasut/contact.rb +2 -0
- data/lib/parasut/http_client.rb +67 -0
- data/lib/parasut/sales_invoice.rb +1 -0
- data/lib/parasut/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4974936eedcb48fd61edf1fa58d3cc5a882be34
|
4
|
+
data.tar.gz: 95bcf0ab3381ed666eed7fc16f1162427bfd385e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea1ac80d5f9bfa9ae2aa570b52f39b963a9d6cee747f7ca5dde259b28d373ba16652620116c7bc70149a085c01d8afa84109189312bd93e1204d0bf585bf968
|
7
|
+
data.tar.gz: 13ea243191a8dabd1e771a6969d65f72e5f05bea6acb7e17a58eabdc340c6bc8aceef4e2ff3dd7533d470f5e853b9bd9beae59c92e9062ec79ccc269e684ccb7
|
data/README.md
CHANGED
@@ -62,6 +62,40 @@ To paginate collections:
|
|
62
62
|
# Pagination uses kaminari. (https://github.com/kaminari/kaminari)
|
63
63
|
|
64
64
|
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
## HttpClient
|
69
|
+
|
70
|
+
|
71
|
+
Parasut-v4 provides an http client integration to execute tasks manually.
|
72
|
+
You can make your calls simply providing endpoint, body and headers. It automatically handles authentication and handles your request.
|
73
|
+
|
74
|
+
This is an http client, hence it does not manipulate the response into objects.
|
75
|
+
|
76
|
+
Making get requests:
|
77
|
+
|
78
|
+
# Parasut::HttpClient.get(endpoint, query_parameters, headers, parse_json=true)
|
79
|
+
# parse_json tries to parse the response body into hash
|
80
|
+
contact=Parasut::HttpClient.get("contacts/123")
|
81
|
+
contact[:data][:attributes][:name]
|
82
|
+
|
83
|
+
Executing post calls:
|
84
|
+
|
85
|
+
# Parasut::HttpClient.post(endpoint, body, headers, parse_json=true)
|
86
|
+
contact=Parasut::HttpClient.post("contacts", {
|
87
|
+
data:{
|
88
|
+
type: :contacts,
|
89
|
+
attributes:{
|
90
|
+
name: "Test From Api",
|
91
|
+
account_type: :customer
|
92
|
+
}
|
93
|
+
}
|
94
|
+
)
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
65
99
|
## ENVs
|
66
100
|
|
67
101
|
- PARASUT_API_BASE_URL
|
@@ -2,50 +2,60 @@ module Her
|
|
2
2
|
module Middleware
|
3
3
|
# OAuthProviderHeader
|
4
4
|
class OAuthProviderHeader < Faraday::Middleware
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def add_header(headers)
|
9
|
+
headers.merge! Authorization: "Bearer #{refresh_token['access_token']}"
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def refresh_token
|
13
|
+
uri = URI("#{token_url}?#{URI.encode_www_form(refresh_token_params)}")
|
14
|
+
res = Net::HTTP.post_form(uri, {})
|
15
|
+
JSON.parse(res.body)
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def refresh_token_params
|
19
|
+
{
|
20
|
+
client_id: Parasut.options.client_id,
|
21
|
+
client_secret: Parasut.options.client_secret,
|
22
|
+
grant_type: 'refresh_token',
|
23
|
+
refresh_token: password['refresh_token']
|
24
|
+
}
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def password_params
|
28
|
+
{
|
29
|
+
client_id: Parasut.options.client_id,
|
30
|
+
client_secret: Parasut.options.client_secret,
|
31
|
+
username: Parasut.options.username,
|
32
|
+
password: Parasut.options.password,
|
33
|
+
grant_type: 'password',
|
34
|
+
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob'
|
35
|
+
}
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
def token_url
|
39
|
+
"#{Parasut.options.api_base_url}/oauth/token"
|
40
|
+
end
|
41
|
+
|
42
|
+
def password
|
43
|
+
uri = URI("#{token_url}?#{URI.encode_www_form(password_params)}")
|
44
|
+
res = Net::HTTP.post_form(uri, {})
|
45
|
+
JSON.parse(res.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
38
49
|
|
39
|
-
def password
|
40
|
-
uri = URI("#{token_url}?#{URI.encode_www_form(password_params)}")
|
41
|
-
res = Net::HTTP.post_form(uri, {})
|
42
|
-
JSON.parse(res.body)
|
43
50
|
end
|
51
|
+
#end static
|
44
52
|
|
45
53
|
def call(env)
|
46
|
-
add_header(env[:request_headers])
|
54
|
+
Her::Middleware::OAuthProviderHeader.add_header(env[:request_headers])
|
47
55
|
@app.call(env)
|
48
56
|
end
|
57
|
+
|
58
|
+
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
data/lib/parasut.rb
CHANGED
@@ -23,6 +23,7 @@ require_relative 'her/model/pagination'
|
|
23
23
|
|
24
24
|
# Models that are including Her::JsonApi::Model has to be required after Her initialization
|
25
25
|
def require_parasut
|
26
|
+
require_relative 'parasut/http_client'
|
26
27
|
require_relative 'parasut/version'
|
27
28
|
require_relative 'parasut/product'
|
28
29
|
require_relative 'parasut/document_status'
|
data/lib/parasut/contact.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
# lib/parasut/http_client.rb
|
2
|
+
module Parasut
|
3
|
+
class HttpClient
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# The url base
|
8
|
+
@@url_base="#{Parasut.options.api_base_url}/v4/#{Parasut.options.company_id}"
|
9
|
+
|
10
|
+
def handle_headers(headers)
|
11
|
+
|
12
|
+
# Append json content type if not exists
|
13
|
+
headers.merge!({'Content-type': 'application/json'}) if headers['Content-type'].nil?
|
14
|
+
|
15
|
+
# Handle access token header
|
16
|
+
Her::Middleware::OAuthProviderHeader.add_header(headers)
|
17
|
+
|
18
|
+
end
|
19
|
+
# end handle_headers
|
20
|
+
|
21
|
+
|
22
|
+
def post(endpoint, body={}, headers={}, parse_json=true)
|
23
|
+
|
24
|
+
# The url
|
25
|
+
url="#{@@url_base}/#{endpoint}"
|
26
|
+
|
27
|
+
handle_headers(headers)
|
28
|
+
|
29
|
+
# Convert body to json if hash provided
|
30
|
+
body=body.to_json if body.is_a?(Hash)
|
31
|
+
|
32
|
+
# Execute the request
|
33
|
+
request=Faraday.post(url, body, headers)
|
34
|
+
|
35
|
+
# Return
|
36
|
+
parse_json ? JSON.parse(request.body).with_indifferent_access : request.body
|
37
|
+
|
38
|
+
end
|
39
|
+
# end post
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
def get(endpoint, query_parameters={}, headers={}, parse_json=true)
|
44
|
+
|
45
|
+
# The url
|
46
|
+
url="#{@@url_base}/#{endpoint}"
|
47
|
+
|
48
|
+
handle_headers(headers)
|
49
|
+
|
50
|
+
# Request
|
51
|
+
request=Faraday.get(url, query_parameters, headers)
|
52
|
+
|
53
|
+
# Return
|
54
|
+
parse_json ? JSON.parse(request.body).with_indifferent_access : request.body
|
55
|
+
|
56
|
+
end
|
57
|
+
# end get
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
# end static
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/parasut/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parasut-v4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dijital Garaj
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-09-
|
14
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/parasut/account.rb
|
183
183
|
- lib/parasut/contact.rb
|
184
184
|
- lib/parasut/document_status.rb
|
185
|
+
- lib/parasut/http_client.rb
|
185
186
|
- lib/parasut/item_category.rb
|
186
187
|
- lib/parasut/options.rb
|
187
188
|
- lib/parasut/payment.rb
|
@@ -210,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
211
|
version: '0'
|
211
212
|
requirements: []
|
212
213
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.6.14
|
214
|
+
rubygems_version: 2.6.14.4
|
214
215
|
signing_key:
|
215
216
|
specification_version: 4
|
216
217
|
summary: Parasut client.
|