breathe 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/breathe.rb +2 -0
- data/lib/breathe/absences.rb +2 -8
- data/lib/breathe/response.rb +53 -0
- data/lib/breathe/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b556ec113d7d5c5f9666a7107c86707b4aa28bec7932eb7607c090631c07250c
|
4
|
+
data.tar.gz: c5b26bce036fd4324e154b0df6e68e10c94e441691e015bb2bb9cd5ac702dc52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0af79e4598c36081ae9705f8b90bec086a54530a008644e4dbce0f7158094e32744d90f7f6677b232caa90cebd55851afaf31d4fe8bd9813b7d4471aa452ef6
|
7
|
+
data.tar.gz: 0fefc175a63493210d9c5c81e31b11539e5b08b77ac2e6d626285fdd7552846668cf2a4d670b2f59e742d71e48ffb0c65c6c7b799aaacc085a5887cca01e97f7
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ client = Breathe::Client.new(api_key: YOUR_API_KEY)
|
|
39
39
|
And use like so
|
40
40
|
|
41
41
|
```ruby
|
42
|
-
client.absences
|
42
|
+
client.absences.list
|
43
43
|
#=> [
|
44
44
|
# {
|
45
45
|
# "employee"=>{"id"=>123, "email"=>"someone@somewhere.com", "first_name"=>"Jo", "last_name"=>"Bloggs"},
|
@@ -62,6 +62,10 @@ client.absences
|
|
62
62
|
# },
|
63
63
|
# ...
|
64
64
|
#]
|
65
|
+
client.absences.list.next_page
|
66
|
+
# 2
|
67
|
+
client.absences.list.per_page
|
68
|
+
# 100
|
65
69
|
```
|
66
70
|
|
67
71
|
You can also pass in arguments like so:
|
data/lib/breathe.rb
CHANGED
data/lib/breathe/absences.rb
CHANGED
@@ -7,14 +7,8 @@ module Breathe
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def list(args = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def parse_response(request)
|
16
|
-
json = JSON.parse(request.body)
|
17
|
-
json["absences"]
|
10
|
+
response = client.get("absences", args)
|
11
|
+
Response.new(response, "absences")
|
18
12
|
end
|
19
13
|
end
|
20
14
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Breathe
|
2
|
+
class Response
|
3
|
+
extend Forwardable
|
4
|
+
attr_reader :data, :type, :response
|
5
|
+
|
6
|
+
delegate [:each, :find, :select, :count, :[]] => :body
|
7
|
+
|
8
|
+
def initialize(response, type)
|
9
|
+
@response = response
|
10
|
+
@data = JSON.parse(response.body)
|
11
|
+
@type = type
|
12
|
+
end
|
13
|
+
|
14
|
+
def total
|
15
|
+
response.headers["total"].to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def per_page
|
19
|
+
response.headers.per_page
|
20
|
+
end
|
21
|
+
|
22
|
+
def next_page
|
23
|
+
link_headers["next"].to_i unless link_headers.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def last_page
|
27
|
+
link_headers["last"].to_i unless link_headers.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def body
|
33
|
+
data[type]
|
34
|
+
end
|
35
|
+
|
36
|
+
def link_headers
|
37
|
+
@link_headers ||= begin
|
38
|
+
return nil if response.headers["link"].nil?
|
39
|
+
|
40
|
+
parse_link_headers(response.headers["link"])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_link_headers(header)
|
45
|
+
header.split(",").map { |header|
|
46
|
+
v, k = header.split(";")
|
47
|
+
k = k.match("rel=\"(.+)\"")[1]
|
48
|
+
v = v.match("page=([0-9]+)")[1]
|
49
|
+
[k, v]
|
50
|
+
}.to_h
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/breathe/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breathe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Harrison
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/breathe.rb
|
161
161
|
- lib/breathe/absences.rb
|
162
162
|
- lib/breathe/client.rb
|
163
|
+
- lib/breathe/response.rb
|
163
164
|
- lib/breathe/version.rb
|
164
165
|
homepage: http://github.com/dxw/breathe_ruby
|
165
166
|
licenses:
|