frontapp 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frontapp/client.rb +14 -8
- data/lib/frontapp/error.rb +22 -0
- data/lib/frontapp/version.rb +3 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e74de615d1ace8618f995ce0726d5bfd7c04db4a
|
4
|
+
data.tar.gz: 75e276ab77531bfa9b62f06133d6c9a4f5d1aa57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cff32f334a4226301d08f8e35f84e22c43e490bfbd50dae690726130a84d4db21626a63369fa9edb4352d9e5688480d165dbdb4092ec2c7c2b604e710e7373e5
|
7
|
+
data.tar.gz: 5bda12ca94202746d869934855e0fb979aea48eef57c0c95f502963b0f07f7e4ffe2a74b1fbf3f387fc8f94b7477d984dcbe9374d36bc7bfe48c0040ac1c7296
|
data/lib/frontapp/client.rb
CHANGED
@@ -15,6 +15,8 @@ require_relative 'client/teammates.rb'
|
|
15
15
|
require_relative 'client/teams.rb'
|
16
16
|
require_relative 'client/topics.rb'
|
17
17
|
require_relative 'client/exports.rb'
|
18
|
+
require_relative 'error'
|
19
|
+
require_relative 'version'
|
18
20
|
|
19
21
|
module Frontapp
|
20
22
|
class Client
|
@@ -36,10 +38,11 @@ module Frontapp
|
|
36
38
|
|
37
39
|
def initialize(options={})
|
38
40
|
auth_token = options[:auth_token]
|
41
|
+
user_agent = options[:user_agent] || "Frontapp Ruby Gem #{VERSION}"
|
39
42
|
@headers = HTTP.headers({
|
40
|
-
|
41
|
-
|
42
|
-
"
|
43
|
+
Accept: "application/json",
|
44
|
+
Authorization: "Bearer #{auth_token}",
|
45
|
+
"User-Agent": user_agent
|
43
46
|
})
|
44
47
|
end
|
45
48
|
|
@@ -64,6 +67,9 @@ module Frontapp
|
|
64
67
|
|
65
68
|
def get(path)
|
66
69
|
res = @headers.get("#{base_url}#{path}")
|
70
|
+
if !res.status.success?
|
71
|
+
raise Error.from_response(res)
|
72
|
+
end
|
67
73
|
JSON.parse(res.to_s)
|
68
74
|
end
|
69
75
|
|
@@ -71,7 +77,7 @@ module Frontapp
|
|
71
77
|
res = @headers.post("#{base_url}#{path}", json: body)
|
72
78
|
response = JSON.parse(res.to_s)
|
73
79
|
if !res.status.success?
|
74
|
-
raise
|
80
|
+
raise Error.from_response(res)
|
75
81
|
end
|
76
82
|
response
|
77
83
|
end
|
@@ -79,21 +85,21 @@ module Frontapp
|
|
79
85
|
def create_without_response(path, body)
|
80
86
|
res = @headers.post("#{base_url}#{path}", json: body)
|
81
87
|
if !res.status.success?
|
82
|
-
raise
|
88
|
+
raise Error.from_response(res)
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
86
92
|
def update(path, body)
|
87
93
|
res = @headers.patch("#{base_url}#{path}", json: body)
|
88
94
|
if !res.status.success?
|
89
|
-
raise
|
95
|
+
raise Error.from_response(res)
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
93
99
|
def delete(path, body = {})
|
94
100
|
res = @headers.delete("#{base_url}#{path}", json: body)
|
95
101
|
if !res.status.success?
|
96
|
-
raise
|
102
|
+
raise Error.from_response(res)
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
@@ -120,4 +126,4 @@ module Frontapp
|
|
120
126
|
end
|
121
127
|
|
122
128
|
end
|
123
|
-
end
|
129
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Frontapp
|
2
|
+
class Error < StandardError
|
3
|
+
def self.from_response(response)
|
4
|
+
error_class = case response.status
|
5
|
+
when 400 then BadRequestError
|
6
|
+
when 404 then NotFoundError
|
7
|
+
when 409 then ConflictError
|
8
|
+
else self.class
|
9
|
+
end
|
10
|
+
error_class.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
@response = response
|
15
|
+
super("Response: #{response.inspect}\nBody: #{response.body}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BadRequestError < Error; end
|
20
|
+
class NotFoundError < Error; end
|
21
|
+
class ConflictError < Error; end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frontapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niels van der Zanden
|
@@ -88,7 +88,9 @@ files:
|
|
88
88
|
- lib/frontapp/client/teammates.rb
|
89
89
|
- lib/frontapp/client/teams.rb
|
90
90
|
- lib/frontapp/client/topics.rb
|
91
|
+
- lib/frontapp/error.rb
|
91
92
|
- lib/frontapp/utils/hash.rb
|
93
|
+
- lib/frontapp/version.rb
|
92
94
|
homepage: https://github.com/phusion/frontapp
|
93
95
|
licenses:
|
94
96
|
- MIT
|