help_scout-sdk 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +1 -2
- data/help_scout-sdk.gemspec +1 -1
- data/lib/help_scout/api/access_token.rb +23 -12
- data/lib/help_scout/api/client.rb +18 -10
- data/lib/help_scout/api.rb +15 -14
- data/lib/help_scout/configuration.rb +2 -0
- data/lib/help_scout/conversation.rb +1 -1
- data/lib/help_scout/mailbox.rb +2 -2
- data/lib/help_scout/response.rb +1 -1
- data/lib/help_scout/version.rb +1 -1
- data/lib/help_scout-sdk.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde4d41133056de55106a9908c925633544fe8a0f888794ed88dd3eff5502985
|
4
|
+
data.tar.gz: 25e7ad5dcdb45e4d24744bcb72a06a46588cc0712d4eed9e2990246ad3bb625a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f25c0927c1bdde7e99f7b9be29734978a99d39dba10cc3143a2ef6968fe4456713670709805888c69cb44a2b961deb8e3f8c5d5218f0afbb27d4357cacee80a8
|
7
|
+
data.tar.gz: b94698d0faf4d31672d5434b26ed4e2a3025a55b846db3512d458ab1176bcf45b0f5adbfcc68030e6428472bc5ef9cbf864a5923350d160d81b42c1c9d28d0be
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Help Scout API Wrapper
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/taxjar/help_scout-sdk.svg?branch=master)](https://travis-ci.org/taxjar/help_scout-sdk)
|
4
|
-
|
5
|
-
🚨 WORK IN PROGRESS 🚨
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/help_scout-sdk.svg)](https://badge.fury.io/rb/help_scout-sdk)
|
6
5
|
|
7
6
|
This gem is a wrapper around the Help Scout API. The current version is targeting the [Mailbox 2.0 API](https://developer.helpscout.com/mailbox-api/).
|
8
7
|
|
data/help_scout-sdk.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ['support@taxjar.com']
|
12
12
|
|
13
13
|
spec.summary = 'Ruby Help Scout SDK'
|
14
|
-
spec.description = 'Ruby Help Scout SDK.'
|
14
|
+
spec.description = 'Ruby Help Scout (aka HelpScout) SDK.'
|
15
15
|
spec.homepage = 'https://github.com/taxjar/help_scout-sdk'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
@@ -5,15 +5,14 @@ module HelpScout
|
|
5
5
|
class AccessToken
|
6
6
|
class << self
|
7
7
|
def create
|
8
|
-
connection = HelpScout::API::Client.new.
|
8
|
+
connection = HelpScout::API::Client.new(authorize: false).connection
|
9
9
|
response = connection.post('oauth2/token', token_request_params)
|
10
10
|
|
11
11
|
case response.status
|
12
|
-
when
|
13
|
-
when
|
12
|
+
when 200 then new HelpScout::Response.new(response).body
|
13
|
+
when 429 then raise HelpScout::API::ThrottleLimitReached, response.body&.dig('error')
|
14
|
+
else raise HelpScout::API::InternalError, "unexpected response (status #{response.status})"
|
14
15
|
end
|
15
|
-
|
16
|
-
new HelpScout::Response.new(response).body
|
17
16
|
end
|
18
17
|
|
19
18
|
def refresh!
|
@@ -23,7 +22,7 @@ module HelpScout
|
|
23
22
|
private
|
24
23
|
|
25
24
|
def token_request_params
|
26
|
-
@
|
25
|
+
@_token_request_params ||= {
|
27
26
|
grant_type: 'client_credentials',
|
28
27
|
client_id: HelpScout.app_id,
|
29
28
|
client_secret: HelpScout.app_secret
|
@@ -31,21 +30,33 @@ module HelpScout
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
|
33
|
+
attr_accessor :invalid
|
34
|
+
attr_reader :expires_in, :value
|
35
35
|
|
36
36
|
def initialize(params)
|
37
37
|
@value = params[:access_token]
|
38
|
-
expires_in = params[:expires_in]
|
39
|
-
|
40
|
-
return unless expires_in
|
38
|
+
@expires_in = params[:expires_in]
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
@
|
41
|
+
def expires_at
|
42
|
+
@_expires_at ||= Time.now.utc + expires_in
|
44
43
|
end
|
45
44
|
|
46
45
|
def expired?
|
47
46
|
Time.now.utc > expires_at
|
48
47
|
end
|
48
|
+
|
49
|
+
def invalid?
|
50
|
+
invalid
|
51
|
+
end
|
52
|
+
|
53
|
+
def invalidate!
|
54
|
+
self.invalid = true
|
55
|
+
end
|
56
|
+
|
57
|
+
def stale?
|
58
|
+
invalid? || expired?
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
@@ -3,29 +3,37 @@
|
|
3
3
|
module HelpScout
|
4
4
|
class API
|
5
5
|
class Client
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
6
|
+
attr_reader :authorize
|
7
|
+
|
8
|
+
def initialize(authorize: true)
|
9
|
+
@authorize = authorize
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
@
|
15
|
-
|
12
|
+
def connection
|
13
|
+
@_connection ||= begin
|
14
|
+
HelpScout::API::AccessToken.refresh! if authorize? && token_needs_refresh?
|
15
|
+
build_connection
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def
|
21
|
+
def authorize?
|
22
|
+
authorize
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_connection
|
22
26
|
Faraday.new(url: BASE_URL) do |conn|
|
23
27
|
conn.request :json
|
24
|
-
conn.authorization(:Bearer, HelpScout.access_token.value) if authorize && HelpScout.access_token&.value
|
28
|
+
conn.authorization(:Bearer, HelpScout.access_token.value) if authorize? && HelpScout.access_token&.value
|
25
29
|
conn.response(:json, content_type: /\bjson$/)
|
26
30
|
conn.adapter(Faraday.default_adapter)
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
def token_needs_refresh?
|
35
|
+
HelpScout.access_token.nil? || HelpScout.access_token.stale?
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
data/lib/help_scout/api.rb
CHANGED
@@ -30,29 +30,30 @@ module HelpScout
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
def handle_response(result) # rubocop:disable AbcSize
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def handle_response(result) # rubocop:disable AbcSize, Metrics/MethodLength
|
34
|
+
if (200...300).include? result.status
|
35
|
+
HelpScout::Response.new(result)
|
36
|
+
else
|
37
|
+
case result.status
|
38
|
+
when 400 then raise BadRequest, result.body&.dig('validationErrors')
|
39
|
+
when 401 then raise NotAuthorized, result.body&.dig('error_description')
|
40
|
+
when 404 then raise NotFound, 'Resource Not Found'
|
41
|
+
when 429 then raise ThrottleLimitReached, result.body&.dig('error')
|
42
|
+
else raise InternalError, result.body
|
43
|
+
end
|
40
44
|
end
|
41
|
-
|
42
|
-
HelpScout::Response.new(result)
|
43
45
|
end
|
44
46
|
|
45
47
|
def new_connection
|
46
|
-
HelpScout::API::Client.new.
|
48
|
+
HelpScout::API::Client.new.connection
|
47
49
|
end
|
48
50
|
|
49
51
|
def send_request(action, path, params)
|
50
|
-
|
51
|
-
response = connection.send(action, path, params.compact)
|
52
|
+
response = new_connection.send(action, path, params.compact)
|
52
53
|
|
53
54
|
if response.status == 401
|
54
|
-
|
55
|
-
response =
|
55
|
+
access_token.invalidate!
|
56
|
+
response = new_connection.send(action, path, params.compact)
|
56
57
|
end
|
57
58
|
|
58
59
|
handle_response(response)
|
data/lib/help_scout/mailbox.rb
CHANGED
@@ -27,11 +27,11 @@ module HelpScout
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def fields
|
30
|
-
@
|
30
|
+
@_fields ||= HelpScout.api.get(fields_path).embedded[:fields]
|
31
31
|
end
|
32
32
|
|
33
33
|
def folders
|
34
|
-
@
|
34
|
+
@_folders ||= HelpScout::Folder.list(id: id)
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
data/lib/help_scout/response.rb
CHANGED
data/lib/help_scout/version.rb
CHANGED
data/lib/help_scout-sdk.rb
CHANGED
@@ -35,7 +35,7 @@ module HelpScout
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def api
|
38
|
-
@
|
38
|
+
@_api ||= HelpScout::API.new
|
39
39
|
end
|
40
40
|
|
41
41
|
def app_id
|
@@ -47,7 +47,7 @@ module HelpScout
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def configuration
|
50
|
-
@
|
50
|
+
@_configuration ||= Configuration.new
|
51
51
|
end
|
52
52
|
|
53
53
|
def configure
|
@@ -59,8 +59,8 @@ module HelpScout
|
|
59
59
|
configuration.default_mailbox
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
63
|
-
@
|
62
|
+
def reset!
|
63
|
+
@_api = HelpScout::API.new
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: help_scout-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TaxJar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -212,7 +212,7 @@ dependencies:
|
|
212
212
|
- - "~>"
|
213
213
|
- !ruby/object:Gem::Version
|
214
214
|
version: '3.3'
|
215
|
-
description: Ruby Help Scout SDK.
|
215
|
+
description: Ruby Help Scout (aka HelpScout) SDK.
|
216
216
|
email:
|
217
217
|
- support@taxjar.com
|
218
218
|
executables: []
|